LLVM OpenMP 19.0.0git
kmp_stats_timing.h
Go to the documentation of this file.
1#ifndef KMP_STATS_TIMING_H
2#define KMP_STATS_TIMING_H
3
4/** @file kmp_stats_timing.h
5 * Access to real time clock and timers.
6 */
7
8//===----------------------------------------------------------------------===//
9//
10// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
11// See https://llvm.org/LICENSE.txt for license information.
12// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13//
14//===----------------------------------------------------------------------===//
15
16#include "kmp_os.h"
17#include <limits>
18#include <stdint.h>
19#include <string>
20#if KMP_HAVE_X86INTRIN_H
21#include <x86intrin.h>
22#endif
23
25private:
26 int64_t my_count;
27
28public:
30 int64_t value;
31 explicit tsc_interval_t(int64_t _value) : value(_value) {}
32
33 public:
34 tsc_interval_t() : value(0) {} // Construct 0 time duration
35#if KMP_HAVE_TICK_TIME
36 double seconds() const; // Return the length of a time interval in seconds
37#endif
38 double ticks() const { return double(value); }
39 int64_t getValue() const { return value; }
40 tsc_interval_t &operator=(int64_t nvalue) {
41 value = nvalue;
42 return *this;
43 }
44
45 friend class tsc_tick_count;
46
48 const tsc_tick_count &t0);
53 };
54
55#if KMP_HAVE___BUILTIN_READCYCLECOUNTER
57 : my_count(static_cast<int64_t>(__builtin_readcyclecounter())) {}
58#elif KMP_HAVE___RDTSC
59 tsc_tick_count() : my_count(static_cast<int64_t>(__rdtsc())) {}
60#else
61#error Must have high resolution timer defined
62#endif
63 tsc_tick_count(int64_t value) : my_count(value) {}
64 int64_t getValue() const { return my_count; }
65 tsc_tick_count later(tsc_tick_count const other) const {
66 return my_count > other.my_count ? (*this) : other;
67 }
69 return my_count < other.my_count ? (*this) : other;
70 }
71#if KMP_HAVE_TICK_TIME
72 static double tick_time(); // returns seconds per cycle (period) of clock
73#endif
75 return tsc_tick_count();
76 } // returns the rdtsc register value
78 const tsc_tick_count &t0);
79};
80
82 const tsc_tick_count &t0) {
83 return tsc_tick_count::tsc_interval_t(t1.my_count - t0.my_count);
84}
85
89 return tsc_tick_count::tsc_interval_t(i1.value - i0.value);
90}
91
95 i1.value += i0.value;
96 return i1;
97}
98
99#if KMP_HAVE_TICK_TIME
100inline double tsc_tick_count::tsc_interval_t::seconds() const {
101 return value * tick_time();
102}
103#endif
104
105extern std::string formatSI(double interval, int width, char unit);
106
107inline std::string formatSeconds(double interval, int width) {
108 return formatSI(interval, width, 'S');
109}
110
111inline std::string formatTicks(double interval, int width) {
112 return formatSI(interval, width, 'T');
113}
114
115#endif // KMP_STATS_TIMING_H
tsc_interval_t & operator=(int64_t nvalue)
friend tsc_interval_t & operator+=(tsc_tick_count::tsc_interval_t &i1, const tsc_tick_count::tsc_interval_t &i0)
friend tsc_interval_t operator-(const tsc_tick_count &t1, const tsc_tick_count &t0)
static tsc_tick_count now()
tsc_tick_count later(tsc_tick_count const other) const
friend tsc_tick_count::tsc_interval_t operator-(const tsc_tick_count &t1, const tsc_tick_count &t0)
int64_t getValue() const
tsc_tick_count(int64_t value)
tsc_tick_count earlier(tsc_tick_count const other) const
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
KMP_ARCH_X86 KMP_ARCH_X86 long double
std::string formatTicks(double interval, int width)
tsc_tick_count::tsc_interval_t operator-(const tsc_tick_count &t1, const tsc_tick_count &t0)
std::string formatSeconds(double interval, int width)
tsc_tick_count::tsc_interval_t & operator+=(tsc_tick_count::tsc_interval_t &i1, const tsc_tick_count::tsc_interval_t &i0)
std::string formatSI(double interval, int width, char unit)