1 #ifndef KMP_STATS_TIMING_H
2 #define KMP_STATS_TIMING_H
44 class tsc_tick_count {
49 class tsc_interval_t {
51 explicit tsc_interval_t(int64_t _value) : value(_value) {}
53 tsc_interval_t() : value(0) {};
54 double seconds()
const;
55 double ticks()
const {
return double(value); }
56 int64_t getValue()
const {
return value; }
58 friend class tsc_tick_count;
60 friend tsc_interval_t operator-(
61 const tsc_tick_count t1,
const tsc_tick_count t0);
64 tsc_tick_count() : my_count(static_cast<int64_t>(__rdtsc())) {};
65 tsc_tick_count(int64_t value) : my_count(value) {};
66 int64_t getValue()
const {
return my_count; }
67 tsc_tick_count later (tsc_tick_count
const other)
const {
68 return my_count > other.my_count ? (*this) : other;
70 tsc_tick_count earlier(tsc_tick_count
const other)
const {
71 return my_count < other.my_count ? (*this) : other;
73 static double tick_time();
74 static tsc_tick_count now() {
return tsc_tick_count(); }
75 friend tsc_tick_count::tsc_interval_t operator-(
const tsc_tick_count t1,
const tsc_tick_count t0);
78 inline tsc_tick_count::tsc_interval_t operator-(
const tsc_tick_count t1,
const tsc_tick_count t0)
80 return tsc_tick_count::tsc_interval_t( t1.my_count-t0.my_count );
83 inline double tsc_tick_count::tsc_interval_t::seconds()
const
85 return value*tick_time();
88 extern std::string formatSI(
double interval,
int width,
char unit);
90 inline std::string formatSeconds(
double interval,
int width)
92 return formatSI(interval, width,
'S');
95 inline std::string formatTicks(
double interval,
int width)
97 return formatSI(interval, width,
'T');
102 tsc_tick_count KMP_ALIGN_CACHE start;
106 timePair() : start(-std::numeric_limits<int64_t>::max()), end(-std::numeric_limits<int64_t>::max()) {}
107 tsc_tick_count get_start()
const {
return start; }
108 tsc_tick_count get_end()
const {
return end; }
109 tsc_tick_count * get_startp() {
return &start; }
110 tsc_tick_count * get_endp() {
return &end; }
112 void markStart() { start = tsc_tick_count::now(); }
113 void markEnd() { end = tsc_tick_count::now(); }
114 void set_start(tsc_tick_count s) { start = s; }
115 void set_end (tsc_tick_count e) { end = e; }
117 tsc_tick_count::tsc_interval_t duration()
const {
return end-start; }
118 std::string format()
const;
122 extern tsc_tick_count::tsc_interval_t computeLastInLastOutInterval(timePair * times,
int nTimes);
123 #endif // KMP_STATS_TIMING_H