1 #ifndef KMP_STATS_TIMING_H
2 #define KMP_STATS_TIMING_H
25 class tsc_tick_count {
30 class tsc_interval_t {
32 explicit tsc_interval_t(int64_t _value) : value(_value) {}
34 tsc_interval_t() : value(0) {};
35 double seconds()
const;
36 double ticks()
const {
return double(value); }
37 int64_t getValue()
const {
return value; }
39 friend class tsc_tick_count;
41 friend tsc_interval_t operator-(
42 const tsc_tick_count t1,
const tsc_tick_count t0);
45 tsc_tick_count() : my_count(static_cast<int64_t>(__rdtsc())) {};
46 tsc_tick_count(int64_t value) : my_count(value) {};
47 int64_t getValue()
const {
return my_count; }
48 tsc_tick_count later (tsc_tick_count
const other)
const {
49 return my_count > other.my_count ? (*this) : other;
51 tsc_tick_count earlier(tsc_tick_count
const other)
const {
52 return my_count < other.my_count ? (*this) : other;
54 static double tick_time();
55 static tsc_tick_count now() {
return tsc_tick_count(); }
56 friend tsc_tick_count::tsc_interval_t operator-(
const tsc_tick_count t1,
const tsc_tick_count t0);
59 inline tsc_tick_count::tsc_interval_t operator-(
const tsc_tick_count t1,
const tsc_tick_count t0)
61 return tsc_tick_count::tsc_interval_t( t1.my_count-t0.my_count );
64 inline double tsc_tick_count::tsc_interval_t::seconds()
const
66 return value*tick_time();
69 extern std::string formatSI(
double interval,
int width,
char unit);
71 inline std::string formatSeconds(
double interval,
int width)
73 return formatSI(interval, width,
'S');
76 inline std::string formatTicks(
double interval,
int width)
78 return formatSI(interval, width,
'T');
83 tsc_tick_count KMP_ALIGN_CACHE start;
87 timePair() : start(-
std::numeric_limits<int64_t>::max()), end(-
std::numeric_limits<int64_t>::max()) {}
88 tsc_tick_count get_start()
const {
return start; }
89 tsc_tick_count get_end()
const {
return end; }
90 tsc_tick_count * get_startp() {
return &start; }
91 tsc_tick_count * get_endp() {
return &end; }
93 void markStart() { start = tsc_tick_count::now(); }
94 void markEnd() { end = tsc_tick_count::now(); }
95 void set_start(tsc_tick_count s) { start = s; }
96 void set_end (tsc_tick_count e) { end = e; }
98 tsc_tick_count::tsc_interval_t duration()
const {
return end-start; }
99 std::string format()
const;
103 extern tsc_tick_count::tsc_interval_t computeLastInLastOutInterval(timePair * times,
int nTimes);
104 #endif // KMP_STATS_TIMING_H