1 #ifndef DASH__UTIL__TIMER_H_ 2 #define DASH__UTIL__TIMER_H_ 4 #include <dash/internal/Config.h> 7 #include <dash/util/Timestamp.h> 8 #include <dash/util/TimeMeasure.h> 13 #if defined(DASH__UTIL__TIMER_PAPI) 14 # include <dash/util/internal/TimestampPAPI.h> 16 # include <dash/util/internal/TimestampCounterPosix.h> 17 # include <dash/util/internal/TimestampClockPosix.h> 20 #include <dash/internal/Logging.h> 25 template<TimeMeasure::MeasureMode TimerType>
34 typedef Timestamp::counter_t timestamp_t;
40 timestamp_t timestampStart;
43 #if defined(DASH__UTIL__TIMER_PAPI) 45 typedef dash::util::internal::TimestampPAPI<TimeMeasure::Clock>
47 #elif defined(DASH__UTIL__TIMER_POSIX) 49 typedef dash::util::internal::TimestampClockPosix
53 #error "dash::util::Timer requires POSIX platform or PAPI" 57 typedef Timestamp_t timestamp_type;
58 typedef timestamp_t timestamp;
62 : timestampStart(Timer::Now())
66 inline Timer(
const self_t& other) =
default;
68 inline Timer & operator=(
const self_t & other)
71 timestampStart = other.timestampStart;
82 Timestamp_t timestamp;
83 now = timestamp.Value();
84 return (static_cast<double>(now - timestampStart) *
85 static_cast<double>(Timestamp_t::FrequencyPrescale())) /
86 static_cast<double>(Timestamp_t::FrequencyScaling());
92 inline const timestamp_t &
Start()
const 94 return timestampStart;
103 return (static_cast<double>(now.Value() - timestamp) *
104 static_cast<double>(Timestamp_t::FrequencyPrescale())) /
105 static_cast<double>(Timestamp_t::FrequencyScaling());
111 inline static timestamp_t
Now()
113 Timestamp_t timestamp;
114 return timestamp.Value();
121 const timestamp_t & start,
122 const timestamp_t &
end)
124 return (static_cast<double>(end - start) *
125 static_cast<double>(Timestamp_t::FrequencyPrescale())) /
126 static_cast<double>(Timestamp_t::FrequencyScaling());
133 const double & start,
136 return ((end - start) *
137 Timestamp_t::FrequencyPrescale() /
138 Timestamp_t::FrequencyScaling());
141 inline static void Calibrate(
142 unsigned int freq = 0)
144 DASH_LOG_DEBUG(
"Timer<Clock>::Calibrate(freq)", freq);
145 Timestamp_t::Calibrate(freq);
148 inline static const char * TimerName()
150 return Timestamp_t::TimerName();
153 inline static Timestamp::counter_t TimestampInfinity()
155 return Timestamp_t::TimestampInfinity();
158 inline static Timestamp::counter_t TimestampNegInfinity() {
159 return Timestamp_t::TimestampNegInfinity();
162 inline static double FrequencyScaling()
164 return Timestamp_t::FrequencyScaling();
174 typedef Timestamp::counter_t timestamp_t;
180 timestamp_t timestampStart;
183 #if defined(DASH__UTIL__TIMER_PAPI) 185 typedef dash::util::internal::TimestampPAPI<TimeMeasure::Counter>
187 #elif defined(DASH__UTIL__TIMER_POSIX) 189 typedef dash::util::internal::TimestampCounterPosix
193 #error "dash::util::Timer requires POSIX platform or PAPI" 197 typedef Timestamp_t timestamp_type;
198 typedef timestamp_t timestamp;
202 : timestampStart(Timer::Now())
205 inline Timer(
const self_t& other) =
default;
207 inline Timer & operator=(
const self_t & other)
209 if (
this != &other) {
210 timestampStart = other.timestampStart;
221 Timestamp_t timestamp;
222 now = timestamp.Value();
223 return (static_cast<double>(now - timestampStart) *
224 static_cast<double>(Timestamp_t::FrequencyPrescale())) /
225 static_cast<double>(Timestamp_t::FrequencyScaling());
231 inline const timestamp_t &
Start()
const 233 return timestampStart;
242 return (static_cast<double>(now.Value() - timestamp) *
243 static_cast<double>(Timestamp_t::FrequencyPrescale())) /
244 static_cast<double>(Timestamp_t::FrequencyScaling());
250 inline static timestamp_t
Now()
252 Timestamp_t timestamp;
253 return timestamp.Value();
260 const timestamp_t & start,
261 const timestamp_t &
end)
263 return (static_cast<double>(end - start) *
264 static_cast<double>(Timestamp_t::FrequencyPrescale())) /
265 static_cast<double>(Timestamp_t::FrequencyScaling());
272 const double & start,
275 return ((end - start) *
276 Timestamp_t::FrequencyPrescale() /
277 Timestamp_t::FrequencyScaling());
280 inline static void Calibrate(
281 unsigned int freq = 0)
283 DASH_LOG_DEBUG(
"Timer<Counter>::Calibrate(freq)", freq);
284 Timestamp_t::Calibrate(freq);
287 inline static const char * TimerName()
289 return Timestamp_t::TimerName();
292 inline static Timestamp::counter_t TimestampInfinity()
294 return Timestamp_t::TimestampInfinity();
297 inline static Timestamp::counter_t TimestampNegInfinity()
299 return Timestamp_t::TimestampNegInfinity();
302 inline static double FrequencyScaling()
304 return Timestamp_t::FrequencyScaling();
311 #endif // DASH__UTIL__TIMER_H_ constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
This class is a simple memory pool which holds allocates elements of size ValueType.
const timestamp_t & Start() const
Returns timestamp from instantiation of this Timer.
static double ElapsedSince(timestamp_t timestamp)
Microseconds elapsed since given timestamp.
static double FromInterval(const timestamp_t &start, const timestamp_t &end)
Convert interval of two timestamp values to mircoseconds.
static timestamp_t Now()
Produces current timestamp.
static double ElapsedSince(timestamp_t timestamp)
Microseconds elapsed since given timestamp.
const timestamp_t & Start() const
Returns timestamp from instantiation of this Timer.
static double FromInterval(const timestamp_t &start, const timestamp_t &end)
Convert interval of two timestamp values to microseconds.
double Elapsed() const
Microseconds elapsed since instantiation of this Timer object.
static double FromInterval(const double &start, const double &end)
Convert interval of two timestamp values to mircoseconds.
double Elapsed() const
Microseconds elapsed since instantiation of this Timer object.
static timestamp_t Now()
Produces current timestamp.
static double FromInterval(const double &start, const double &end)
Convert interval of two timestamp values to mircoseconds.