Compute Library
 21.05
WallClock< output_timestamps > Class Template Reference

Implementation of an instrument to measure elapsed wall-clock time in milliseconds. More...

#include <WallClockTimer.h>

Collaboration diagram for WallClock< output_timestamps >:
[legend]

Public Member Functions

 WallClock (ScaleFactor scale_factor)
 Construct a Wall clock timer. More...
 
std::string id () const override
 Identifier for the instrument. More...
 
void start () override
 Start measuring. More...
 
void stop () override
 Stop measuring. More...
 
MeasurementsMap measurements () const override
 Return the latest measurements. More...
 
- Public Member Functions inherited from Instrument
 Instrument ()=default
 Default constructor. More...
 
 Instrument (const Instrument &)=default
 Allow instances of this class to be copy constructed. More...
 
 Instrument (Instrument &&)=default
 Allow instances of this class to be move constructed. More...
 
Instrumentoperator= (const Instrument &)=default
 Allow instances of this class to be copied. More...
 
Instrumentoperator= (Instrument &&)=default
 Allow instances of this class to be moved. More...
 
virtual ~Instrument ()=default
 Default destructor. More...
 
virtual void test_start ()
 Start of the test. More...
 
virtual void test_stop ()
 End of the test. More...
 
virtual MeasurementsMap test_measurements () const
 Return the latest test measurements. More...
 

Additional Inherited Members

- Public Types inherited from Instrument
using MeasurementsMap = std::map< std::string, Measurement >
 Map of measurements. More...
 
- Static Public Member Functions inherited from Instrument
template<typename T , ScaleFactor scale>
static std::unique_ptr< Instrumentmake_instrument ()
 Helper function to create an instrument of the given type. More...
 

Detailed Description

template<bool output_timestamps>
class arm_compute::test::framework::WallClock< output_timestamps >

Implementation of an instrument to measure elapsed wall-clock time in milliseconds.

Definition at line 39 of file WallClockTimer.h.

Constructor & Destructor Documentation

◆ WallClock()

WallClock ( ScaleFactor  scale_factor)
inline

Construct a Wall clock timer.

Parameters
[in]scale_factorMeasurement scale factor.

Definition at line 46 of file WallClockTimer.h.

47  {
48  switch(scale_factor)
49  {
50  case ScaleFactor::NONE:
51  _scale_factor = 1.f;
52  _unit = "us";
53  break;
55  _scale_factor = 1000.f;
56  _unit = "ms";
57  break;
59  _scale_factor = 1000000.f;
60  _unit = "s";
61  break;
62  default:
63  ARM_COMPUTE_ERROR("Invalid scale");
64  }
65  };
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352

References ARM_COMPUTE_ERROR, arm_compute::test::framework::NONE, arm_compute::test::framework::TIME_MS, and arm_compute::test::framework::TIME_S.

Member Function Documentation

◆ id()

std::string id ( ) const
overridevirtual

Identifier for the instrument.

Implements Instrument.

Definition at line 36 of file WallClockTimer.cpp.

37 {
38  if(output_timestamps)
39  {
40  return "Wall clock timestamps";
41  }
42  else
43  {
44  return "Wall clock";
45  }
46 }

◆ measurements()

Instrument::MeasurementsMap measurements ( ) const
overridevirtual

Return the latest measurements.

Returns
the latest measurements.

Reimplemented from Instrument.

Definition at line 92 of file WallClockTimer.cpp.

93 {
95  if(output_timestamps)
96  {
97 #if defined(BARE_METAL)
98  measurements.emplace("[start]Wall clock time", Measurement(_start / static_cast<uint64_t>(_scale_factor), _unit));
99  measurements.emplace("[end]Wall clock time", Measurement(_stop / static_cast<uint64_t>(_scale_factor), _unit));
100 #else // !defined(BARE_METAL)
101  measurements.emplace("[start]Wall clock time", Measurement(_start.time_since_epoch().count() / static_cast<uint64_t>(1000 * _scale_factor), _unit));
102  measurements.emplace("[end]Wall clock time", Measurement(_stop.time_since_epoch().count() / static_cast<uint64_t>(1000 * _scale_factor), _unit));
103 #endif // defined(BARE_METAL)
104  }
105  else
106  {
107 #if defined(BARE_METAL)
108  const double delta = _stop - _start;
109  measurements.emplace("Wall clock time", Measurement(delta / static_cast<double>(1000 * _scale_factor), _unit));
110 #else // !defined(BARE_METAL)
111  const auto delta = std::chrono::duration_cast<std::chrono::microseconds>(_stop - _start);
112  measurements.emplace("Wall clock time", Measurement(delta.count() / _scale_factor, _unit));
113 #endif // defined(BARE_METAL)
114  }
115  return measurements;
116 }
std::map< std::string, Measurement > MeasurementsMap
Map of measurements.
Definition: Instrument.h:109
MeasurementsMap measurements() const override
Return the latest measurements.

◆ start()

void start ( )
overridevirtual

Start measuring.

Called just before the run of the test starts

Reimplemented from Instrument.

Definition at line 49 of file WallClockTimer.cpp.

50 {
51 #if defined(BARE_METAL)
52  uint64_t tmp;
53  uint64_t retval;
54 
55  __asm __volatile(
56  "mrs %[tmp], pmcr_el0\n"
57  "orr %[tmp], %[tmp], #1\n"
58  "msr pmcr_el0, %[tmp]\n"
59  "mrs %[tmp], pmcntenset_el0\n"
60  "orr %[tmp], %[tmp], #1<<31\n"
61  "msr pmcntenset_el0, %[tmp]\n"
62  "mrs %[retval], pmccntr_el0\n"
63  : [tmp] "=r"(tmp), [retval] "=r"(retval));
64 
65  _start = retval;
66 #else // !defined(BARE_METAL)
67  _start = std::chrono::system_clock::now();
68 #endif // defined(BARE_METAL)
69 }

◆ stop()

void stop ( )
overridevirtual

Stop measuring.

Called just after the run of the test ends

Reimplemented from Instrument.

Definition at line 72 of file WallClockTimer.cpp.

73 {
74 #if defined(BARE_METAL)
75  uint64_t tmp;
76  uint64_t retval;
77 
78  __asm __volatile(
79  "mrs %[retval], pmccntr_el0\n"
80  "mov %[tmp], #0x3f\n"
81  "orr %[tmp], %[tmp], #1<<31\n"
82  "msr pmcntenclr_el0, %[tmp]\n"
83  : [tmp] "=r"(tmp), [retval] "=r"(retval));
84 
85  _stop = retval;
86 #else // !defined(BARE_METAL)
87  _stop = std::chrono::system_clock::now();
88 #endif // defined(BARE_METAL)
89 }

The documentation for this class was generated from the following files: