-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc.cpp
134 lines (119 loc) · 3.37 KB
/
misc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Misc Stuff (profiling) for MPEG2Dec3
*
* Copyright (C) 2002-2003 Marc Fauconneau <[email protected]>
*
* This file is part of MPEG2Dec3, a free MPEG-2 decoder
*
* MPEG2Dec3 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* MPEG2Dec3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include "global.h"
static ui64 local;
static char buffer[256];
unsigned __int64 read_counter(void)
{
unsigned __int64 ts;
unsigned __int32 ts1, ts2;
__asm {
rdtsc
mov ts1, eax
mov ts2, edx
}
ts = ((unsigned __int64) ts2 << 32) | ((unsigned __int64) ts1);
return ts;
}
// get CPU frequency in Hz (1MHz precision)
ui64 get_freq(void)
{
unsigned __int64 x = 0;
time_t i;
i = time(NULL);
while (i == time(NULL));
x -= read_counter();
i++;
while (i == time(NULL));
x += read_counter();
return x;
}
void init_first(ts* timers) {
memset(timers,0,sizeof(ts));
timers->div = 0; timers->sum = 0;
timers->freq = get_freq()/1000;
// timers->freq = 1412*1000000; // shortcut for my athlon xp 1600+ (1.4 Gz)
}
void init_timers(ts* timers) {
timers->idct = 0;
timers->conv = 0;
timers->mcpy = 0;
timers->post = 0;
timers->dec = 0;
timers->bit = 0;
timers->decMB = 0;
timers->mcmp = 0;
timers->addb = 0;
timers->overall = 0;
if (timers->div > 25) { timers->div = 0; timers->sum = 0; }
}
void start_timer() {
local = read_counter();
}
ui64 read_timer()
{
ui64 tmp;
tmp = local;
local = read_counter();
return (local - tmp);
}
void start_timer2(ui64* timer) {
*timer -= read_counter();
}
void stop_timer(ui64*timer) {
*timer += (read_counter() - local);
}
void stop_timer2(ui64* timer) {
*timer += read_counter();
}
void timer_debug(ts* timers) {
ts tim = *timers;
//tim.freq = ;
// sprintf(buffer,"conv = %I64d ",tim.conv);
// sprintf(buffer,"idct = %I64d overall=%I64d idct% = %f",tim.idct,tim.overall,(double)tim.idct*100/tim.overall);
sprintf(buffer,"| dec%% = %f > mcmp%% = %f addb%% = %f idct%% = %f decMB%% = %f bit%% = %f | conv%% = %f | post%% = %f | mcpy%% = %f | msec = %f fps = %f mean = %f",
(double)tim.dec*100/tim.overall,
(double)tim.idct*100/tim.overall,
(double)tim.addb*100/tim.overall,
(double)tim.mcmp*100/tim.overall,
(double)tim.decMB*100/tim.overall,
(double)tim.bit*100/tim.overall,
(double)tim.conv*100/tim.overall,
(double)tim.post*100/tim.overall,
(double)tim.mcpy*100/tim.overall,
(double)tim.overall*1000/tim.freq,
tim.freq/(double)tim.overall,
(tim.freq)/((double)tim.sum/tim.div)
);
OutputDebugString(buffer);
}
int dprintf(char* fmt, ...)
{
char printString[1000];
va_list argp;
va_start(argp, fmt);
vsprintf(printString, fmt, argp);
va_end(argp);
OutputDebugString(printString);
return strlen(printString);
}