-
Notifications
You must be signed in to change notification settings - Fork 0
/
Watch.c
147 lines (128 loc) · 3.82 KB
/
Watch.c
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
135
136
137
138
139
140
141
142
143
144
145
146
147
////////////////////////////////////////////////////////////////////////////////
//
// General including files
//
// Including the files for the system.
//
// These including files are generally used in different operation system.
//
////////////////////////////////////////////////////////////////////////////////
#include "Global.h"
////////////////////////////////////////////////////////////////////////////////
//
// Internal definitions.
//
// These definitions are generally used internally.
//
////////////////////////////////////////////////////////////////////////////////
#define MAX_VALUE 0xFFFFFFFF
////////////////////////////////////////////////////////////////////////////////
//
// Initialize watch.
//
////////////////////////////////////////////////////////////////////////////////
void InitializeWatch(SimpleWatch* pWatch)
{
#ifdef _DEBUG
assert(pWatch != NULL);
#endif
//CLear watch.
memset(pWatch,0,sizeof(SimpleWatch));
//Initialize start time.
assert(InitializeTime(&pWatch->timeStart));
//Initialize stop time.
assert(InitializeTime(&pWatch->timeStop));
//Set count.
pWatch->nCount = 0;
//Set performance counters.
//Minimum
pWatch->nPerformanceCounters[0] = MAX_VALUE;
//Current
pWatch->nPerformanceCounters[1] = MAX_VALUE;
//Maximum
pWatch->nPerformanceCounters[2] = 0;
}
////////////////////////////////////////////////////////////////////////////////
//
// Start watch.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL StartWatch(SimpleWatch* pWatch)
{
#ifdef _DEBUG
assert(pWatch != NULL);
#endif
//Initialize start time.
if(!InitializeTime(&pWatch->timeStart))
{
#ifdef _DEBUG
PrintLine(stderr,"Watch::StartWatch : fail to initialize time !");
#endif
return _FALSE;
}
//Return true.
return _TRUE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Stop watch.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL StopWatch(SimpleWatch* pWatch)
{
#ifdef _DEBUG
assert(pWatch != NULL);
#endif
//Get current performance counter.
pWatch->nPerformanceCounters[1] = pWatch->timeStop.nPerformanceCounters[1] -
pWatch->timeStart.nPerformanceCounters[1];
//Set minimum consumed.
if(pWatch->nPerformanceCounters[1] < pWatch->nPerformanceCounters[0])
{
pWatch->nPerformanceCounters[0] = pWatch->nPerformanceCounters[1];
}
//Set maximum consumed.
if(pWatch->nPerformanceCounters[1] > pWatch->nPerformanceCounters[2])
{
pWatch->nPerformanceCounters[2] = pWatch->nPerformanceCounters[1];
}
//Add count.
pWatch->nCount ++;
//Initialize stop time.
if(!InitializeTime(&pWatch->timeStop))
{
#ifdef _DEBUG
PrintLine(stderr,"Watch::StopWatch : fail to initialize time !");
#endif
return _FALSE;
}
//Return true.
return _TRUE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Dump watch.
//
////////////////////////////////////////////////////////////////////////////////
_STRING DumpWatch(_STRING lpstrFormat,SimpleWatch* pWatch)
{
#ifdef _DEBUG
assert(lpstrFormat != NULL && pWatch != NULL);
#endif
//Beging format.
lpstrFormat = FormatLine(lpstrFormat,"Watch::DumpWatch : show data !");
//Dump start time.
lpstrFormat = FormatLine(lpstrFormat,"\ttimeStart = %u [%s]",
pWatch->timeStart.nMilliseconds,GetStandardFormat(&pWatch->timeStart));
//Dump stop time.
lpstrFormat = FormatLine(lpstrFormat,"\ttimeStop = %u [%s]",
pWatch->timeStart.nMilliseconds,GetStandardFormat(&pWatch->timeStop));
//Dump count.
lpstrFormat = FormatLine(lpstrFormat,"\tnCount = %u",
pWatch->nCount);
//Dump performance counter.
lpstrFormat = FormatLine(lpstrFormat,"\tnPerformanceCounters[minimum,current,maximum] = %u,%u,%u",
pWatch->nPerformanceCounters[0],pWatch->nPerformanceCounters[1],pWatch->nPerformanceCounters[2]);
//Return format.
return lpstrFormat;
}