-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLog.cpp
More file actions
132 lines (109 loc) · 2.44 KB
/
Log.cpp
File metadata and controls
132 lines (109 loc) · 2.44 KB
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
#include "Log.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
// Add "num" variable based on original version
void Sample::setMsg(const char *fmt, const char *msg, int num)
{
_isMsg = true;
_fmt = new char[strlen(fmt)+1];
strcpy(_fmt, fmt);
_msg = new char[strlen(msg)+1];
strcpy(_msg, msg);
_num = num;
}
void Sample::setTimer(const char *fmt, const char *msg, double timer, unsigned int nbytes, int loops)
{
_isMsg = false;
_timer = timer;
if(loops != 0) _loops = loops;
if(nbytes > 0) _nbytes = nbytes;
if (strlen(msg ) > 0)
{
_fmt = new char[strlen( fmt ) + 1];
strcpy(_fmt, fmt);
}
if (strlen(msg) > 0)
{
_msg = new char[strlen( msg ) + 1];
strcpy(_msg, msg);
}
}
void Sample::printSample(void)
{
if(_isMsg == true)
printf(_fmt, _msg, _num);
else
{
double bwd = (((double) _nbytes * _loops )/ _timer) / 1e9;
printf(_fmt, _msg, _timer, bwd) ;
}
}
TestLog::TestLog(int nSamples) : _logIdx(0),
_logLoops(0),
_logLoopEntries(0),
_logLoopTimers(0)
{
_samples = new Sample[nSamples];
}
void TestLog::loopMarker()
{
_logLoopTimers = 0;
_logLoops++;
}
void TestLog::Msg(const char *format, const char *msg, const int num)
{
_samples[_logIdx++].setMsg(format, msg, num);
_logLoopEntries++;
}
void TestLog::Error(const char *format, const char *msg)
{
_samples[_logIdx].setMsg(format, msg, 0);
_samples[_logIdx++].setErr();
_logLoopEntries++;
}
void TestLog::Timer(const char *format, const char *msg, double timer, unsigned int nbytes, int loops)
{
_samples[_logIdx++].setTimer(format, msg, timer, nbytes, loops);
_logLoopEntries++;
_logLoopTimers++;
}
void TestLog::printLog(void)
{
int idx = 0;
for(unsigned int i = 0; i < _logLoopEntries; i++)
_samples[idx++].printSample();
}
void TestLog::printSummary(int skip)
{
for(unsigned int i = 0; i < _logLoopEntries; i++)
{
if(_samples[i].isMsg())
{
bool foundError = false;
for(unsigned int nl = 0; nl < _logLoops; nl++)
{
unsigned int current = i + nl * _logLoopEntries;
if(_samples[current].isErr())
{
_samples[current].printSample();
foundError = true;
break;
}
}
if(!foundError)
_samples[i].printSample();
}
else
{
double sum = 0;
for(unsigned int nl = skip; nl < _logLoops; nl++)
{
sum += _samples[i + nl * _logLoopEntries].getTimer();
}
_samples[i].setTimer("", "", sum / (_logLoops-skip), 0, 0);
_samples[i].printSample();
}
}
}