1 #ifndef KMP_STATS_TIMING_H 2 #define KMP_STATS_TIMING_H 23 #if KMP_HAVE_X86INTRIN_H 24 #include <x86intrin.h> 27 class tsc_tick_count {
32 class tsc_interval_t {
34 explicit tsc_interval_t(int64_t _value) : value(_value) {}
37 tsc_interval_t() : value(0){};
38 #if KMP_HAVE_TICK_TIME 39 double seconds()
const;
41 double ticks()
const {
return double(value); }
42 int64_t getValue()
const {
return value; }
43 tsc_interval_t &operator=(int64_t nvalue) {
48 friend class tsc_tick_count;
50 friend tsc_interval_t operator-(
const tsc_tick_count &t1,
51 const tsc_tick_count &t0);
52 friend tsc_interval_t operator-(
const tsc_tick_count::tsc_interval_t &i1,
53 const tsc_tick_count::tsc_interval_t &i0);
54 friend tsc_interval_t &operator+=(tsc_tick_count::tsc_interval_t &i1,
55 const tsc_tick_count::tsc_interval_t &i0);
58 #if KMP_HAVE___BUILTIN_READCYCLECOUNTER 60 : my_count(static_cast<int64_t>(__builtin_readcyclecounter())) {}
61 #elif KMP_HAVE___RDTSC 62 tsc_tick_count() : my_count(static_cast<int64_t>(__rdtsc())){};
64 #error Must have high resolution timer defined 66 tsc_tick_count(int64_t value) : my_count(value){};
67 int64_t getValue()
const {
return my_count; }
68 tsc_tick_count later(tsc_tick_count
const other)
const {
69 return my_count > other.my_count ? (*this) : other;
71 tsc_tick_count earlier(tsc_tick_count
const other)
const {
72 return my_count < other.my_count ? (*this) : other;
74 #if KMP_HAVE_TICK_TIME 75 static double tick_time();
77 static tsc_tick_count now() {
78 return tsc_tick_count();
80 friend tsc_tick_count::tsc_interval_t operator-(
const tsc_tick_count &t1,
81 const tsc_tick_count &t0);
84 inline tsc_tick_count::tsc_interval_t operator-(
const tsc_tick_count &t1,
85 const tsc_tick_count &t0) {
86 return tsc_tick_count::tsc_interval_t(t1.my_count - t0.my_count);
89 inline tsc_tick_count::tsc_interval_t
90 operator-(
const tsc_tick_count::tsc_interval_t &i1,
91 const tsc_tick_count::tsc_interval_t &i0) {
92 return tsc_tick_count::tsc_interval_t(i1.value - i0.value);
95 inline tsc_tick_count::tsc_interval_t &
96 operator+=(tsc_tick_count::tsc_interval_t &i1,
97 const tsc_tick_count::tsc_interval_t &i0) {
102 #if KMP_HAVE_TICK_TIME 103 inline double tsc_tick_count::tsc_interval_t::seconds()
const {
104 return value * tick_time();
108 extern std::string formatSI(
double interval,
int width,
char unit);
110 inline std::string formatSeconds(
double interval,
int width) {
111 return formatSI(interval, width,
'S');
114 inline std::string formatTicks(
double interval,
int width) {
115 return formatSI(interval, width,
'T');
118 #endif // KMP_STATS_TIMING_H