24 #include "kmp_stats_timing.h" 28 #if KMP_HAVE_TICK_TIME 30 double tsc_tick_count::tick_time() {
32 return 1 / ((double)1000 * 1.e6);
34 #elif KMP_ARCH_X86 || KMP_ARCH_X86_64 37 double tsc_tick_count::tick_time() {
38 static double result = 0.0;
44 __kmp_x86_cpuid(0x80000000, 0, &cpuinfo);
45 memset(brand, 0,
sizeof(brand));
46 int ids = cpuinfo.eax;
48 for (
unsigned int i = 2; i < (ids ^ 0x80000000) + 2; i++)
49 __kmp_x86_cpuid(i | 0x80000000, 0,
50 (kmp_cpuid_t *)(brand + (i - 2) *
sizeof(kmp_cpuid_t)));
52 char *start = &brand[0];
53 for (; *start ==
' '; start++)
56 char *end = brand + KMP_STRLEN(brand) - 3;
60 multiplier = 1000LL * 1000LL;
62 multiplier = 1000LL * 1000LL * 1000LL;
64 multiplier = 1000LL * 1000LL * 1000LL * 1000LL;
66 cout <<
"Error determining multiplier '" << *end <<
"'\n";
74 double freq = strtod(end, &start);
76 cout <<
"Error calculating frequency " << end <<
"\n";
80 result = ((double)1.0) / (freq * multiplier);
87 static bool useSI =
true;
91 std::string formatSI(
double interval,
int width,
char unit) {
100 } ranges[] = {{1.e12,
'f'}, {1.e9,
'p'}, {1.e6,
'n'}, {1.e3,
'u'},
101 {1.0,
'm'}, {1.e-3,
' '}, {1.e-6,
'k'}, {1.e-9,
'M'},
102 {1.e-12,
'G'}, {1.e-15,
'T'}, {1.e-18,
'P'}, {1.e-21,
'E'},
103 {1.e-24,
'Z'}, {1.e-27,
'Y'}};
105 if (interval == 0.0) {
106 os << std::setw(width - 3) << std::right <<
"0.00" << std::setw(3)
111 bool negative =
false;
112 if (interval < 0.0) {
114 interval = -interval;
117 for (
int i = 0; i < (int)(
sizeof(ranges) /
sizeof(ranges[0])); i++) {
118 if (interval * ranges[i].scale < 1.e0) {
119 interval = interval * 1000.e0 * ranges[i].scale;
120 os << std::fixed << std::setprecision(2) << std::setw(width - 3)
121 << std::right << (negative ? -interval : interval) << std::setw(2)
122 << ranges[i].prefix << std::setw(1) << unit;
128 os << std::setprecision(2) << std::fixed << std::right << std::setw(width - 3)
129 << interval << std::setw(3) << unit;