23 #include "kmp_stats_timing.h"
29 double tsc_tick_count::tick_time()
32 return 1/((double)1000*1.e6);
37 double tsc_tick_count::tick_time()
39 static double result = 0.0;
46 __cpuid(cpuinfo, 0x80000000);
47 memset(brand, 0,
sizeof(brand));
50 for (
unsigned int i=2; i<(ids^0x80000000)+2; i++)
51 __cpuid(brand+(i-2)*
sizeof(cpuinfo), i | 0x80000000);
53 char * start = &brand[0];
54 for (;*start ==
' '; start++)
57 char * end = brand + KMP_STRLEN(brand) - 3;
60 if (*end ==
'M') multiplier = 1000LL*1000LL;
61 else if (*end ==
'G') multiplier = 1000LL*1000LL*1000LL;
62 else if (*end ==
'T') multiplier = 1000LL*1000LL*1000LL*1000LL;
65 cout <<
"Error determining multiplier '" << *end <<
"'\n";
69 while (*end !=
' ') end--;
72 double freq = strtod(end, &start);
75 cout <<
"Error calculating frequency " << end <<
"\n";
79 result = ((double)1.0)/(freq * multiplier);
86 static bool useSI =
true;
90 std::string formatSI(
double interval,
int width,
char unit)
98 static struct {
double scale;
char prefix; } ranges[] = {
117 os << std::setw(width-3) << std::right <<
"0.00" << std::setw(3) << unit;
121 bool negative =
false;
125 interval = -interval;
128 for (
int i=0; i<(int)(
sizeof(ranges)/
sizeof(ranges[0])); i++)
130 if (interval*ranges[i].scale < 1.e0)
132 interval = interval * 1000.e0 * ranges[i].scale;
133 os << std::fixed << std::setprecision(2) << std::setw(width-3) << std::right <<
134 (negative ? -interval : interval) << std::setw(2) << ranges[i].prefix << std::setw(1) << unit;
140 os << std::setprecision(2) << std::fixed << std::right << std::setw(width-3) << interval << std::setw(3) << unit;
145 tsc_tick_count::tsc_interval_t computeLastInLastOutInterval(timePair * times,
int nTimes)
147 timePair lastTimes = times[0];
148 tsc_tick_count * startp = lastTimes.get_startp();
149 tsc_tick_count * endp = lastTimes.get_endp();
151 for (
int i=1; i<nTimes; i++)
153 (*startp) = startp->later(times[i].get_start());
154 (*endp) = endp->later (times[i].get_end());
157 return lastTimes.duration();
160 std::string timePair::format()
const
162 std::ostringstream oss;
164 oss << start.getValue() <<
":" << end.getValue() <<
" = " << (end-start).getValue();