42 #include "kmp_stats_timing.h"
48 double tsc_tick_count::tick_time()
51 return 1/((double)1000*1.e6);
56 double tsc_tick_count::tick_time()
58 static double result = 0.0;
65 __cpuid(cpuinfo, 0x80000000);
66 memset(brand, 0,
sizeof(brand));
69 for (
unsigned int i=2; i<(ids^0x80000000)+2; i++)
70 __cpuid(brand+(i-2)*
sizeof(cpuinfo), i | 0x80000000);
72 char * start = &brand[0];
73 for (;*start ==
' '; start++)
76 char * end = brand + strlen(brand) - 3;
79 if (*end ==
'M') multiplier = 1000LL*1000LL;
80 else if (*end ==
'G') multiplier = 1000LL*1000LL*1000LL;
81 else if (*end ==
'T') multiplier = 1000LL*1000LL*1000LL*1000LL;
84 cout <<
"Error determining multiplier '" << *end <<
"'\n";
88 while (*end !=
' ') end--;
91 double freq = strtod(end, &start);
94 cout <<
"Error calculating frequency " << end <<
"\n";
98 result = ((double)1.0)/(freq * multiplier);
105 static bool useSI =
true;
109 std::string formatSI(
double interval,
int width,
char unit)
111 std::stringstream os;
117 static struct {
double scale;
char prefix; } ranges[] = {
136 os << std::setw(width-3) << std::right <<
"0.00" << std::setw(3) << unit;
140 bool negative =
false;
144 interval = -interval;
147 for (
int i=0; i<(int)(
sizeof(ranges)/
sizeof(ranges[0])); i++)
149 if (interval*ranges[i].scale < 1.e0)
151 interval = interval * 1000.e0 * ranges[i].scale;
152 os << std::fixed << std::setprecision(2) << std::setw(width-3) << std::right <<
153 (negative ? -interval : interval) << std::setw(2) << ranges[i].prefix << std::setw(1) << unit;
159 os << std::setprecision(2) << std::fixed << std::right << std::setw(width-3) << interval << std::setw(3) << unit;
164 tsc_tick_count::tsc_interval_t computeLastInLastOutInterval(timePair * times,
int nTimes)
166 timePair lastTimes = times[0];
167 tsc_tick_count * startp = lastTimes.get_startp();
168 tsc_tick_count * endp = lastTimes.get_endp();
170 for (
int i=1; i<nTimes; i++)
172 (*startp) = startp->later(times[i].get_start());
173 (*endp) = endp->later (times[i].get_end());
176 return lastTimes.duration();
179 std::string timePair::format()
const
181 std::ostringstream oss;
183 oss << start.getValue() <<
":" << end.getValue() <<
" = " << (end-start).getValue();