1 #ifndef KMP_STATS_TIMING_H 2 #define KMP_STATS_TIMING_H 24 #if KMP_HAVE_X86INTRIN_H 25 # include <x86intrin.h> 28 class tsc_tick_count {
33 class tsc_interval_t {
35 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; }
44 friend class tsc_tick_count;
46 friend tsc_interval_t operator-(
47 const tsc_tick_count t1,
const tsc_tick_count t0);
50 #if KMP_HAVE___BUILTIN_READCYCLECOUNTER 51 tsc_tick_count() : my_count(static_cast<int64_t>(__builtin_readcyclecounter())) {}
52 #elif KMP_HAVE___RDTSC 53 tsc_tick_count() : my_count(static_cast<int64_t>(__rdtsc())) {};
55 # error Must have high resolution timer defined 57 tsc_tick_count(int64_t value) : my_count(value) {};
58 int64_t getValue()
const {
return my_count; }
59 tsc_tick_count later (tsc_tick_count
const other)
const {
60 return my_count > other.my_count ? (*this) : other;
62 tsc_tick_count earlier(tsc_tick_count
const other)
const {
63 return my_count < other.my_count ? (*this) : other;
65 #if KMP_HAVE_TICK_TIME 66 static double tick_time();
68 static tsc_tick_count now() {
return tsc_tick_count(); }
69 friend tsc_tick_count::tsc_interval_t operator-(
const tsc_tick_count t1,
const tsc_tick_count t0);
72 inline tsc_tick_count::tsc_interval_t operator-(
const tsc_tick_count t1,
const tsc_tick_count t0)
74 return tsc_tick_count::tsc_interval_t( t1.my_count-t0.my_count );
77 #if KMP_HAVE_TICK_TIME 78 inline double tsc_tick_count::tsc_interval_t::seconds()
const 80 return value*tick_time();
84 extern std::string formatSI(
double interval,
int width,
char unit);
86 inline std::string formatSeconds(
double interval,
int width)
88 return formatSI(interval, width,
'S');
91 inline std::string formatTicks(
double interval,
int width)
93 return formatSI(interval, width,
'T');
98 tsc_tick_count KMP_ALIGN_CACHE start;
102 timePair() : start(-
std::numeric_limits<int64_t>::max()), end(-
std::numeric_limits<int64_t>::max()) {}
103 tsc_tick_count get_start()
const {
return start; }
104 tsc_tick_count get_end()
const {
return end; }
105 tsc_tick_count * get_startp() {
return &start; }
106 tsc_tick_count * get_endp() {
return &end; }
108 void markStart() { start = tsc_tick_count::now(); }
109 void markEnd() { end = tsc_tick_count::now(); }
110 void set_start(tsc_tick_count s) { start = s; }
111 void set_end (tsc_tick_count e) { end = e; }
113 tsc_tick_count::tsc_interval_t duration()
const {
return end-start; }
114 std::string format()
const;
118 extern tsc_tick_count::tsc_interval_t computeLastInLastOutInterval(timePair * times,
int nTimes);
119 #endif // KMP_STATS_TIMING_H