Compute Library
 21.05
PMUCounter Class Reference

Implementation of an instrument to count CPU cycles. More...

#include <PMUCounter.h>

Collaboration diagram for PMUCounter:
[legend]

Public Member Functions

 PMUCounter (ScaleFactor scale_factor)
 Construct a PMU counter. 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

Implementation of an instrument to count CPU cycles.

Definition at line 37 of file PMUCounter.h.

Constructor & Destructor Documentation

◆ PMUCounter()

PMUCounter ( ScaleFactor  scale_factor)
inline

Construct a PMU counter.

Parameters
[in]scale_factorMeasurement scale factor.

Definition at line 44 of file PMUCounter.h.

45  {
46  switch(scale_factor)
47  {
48  case ScaleFactor::NONE:
49  _scale_factor = 1;
50  _unit = "";
51  break;
53  _scale_factor = 1000;
54  _unit = "K ";
55  break;
57  _scale_factor = 1000000;
58  _unit = "M ";
59  break;
60  default:
61  ARM_COMPUTE_ERROR("Invalid scale");
62  }
63  };
#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::SCALE_1K, and arm_compute::test::framework::SCALE_1M.

Member Function Documentation

◆ id()

std::string id ( ) const
overridevirtual

Identifier for the instrument.

Implements Instrument.

Definition at line 32 of file PMUCounter.cpp.

33 {
34  return "PMU Counter";
35 }

◆ measurements()

Instrument::MeasurementsMap measurements ( ) const
overridevirtual

Return the latest measurements.

Returns
the latest measurements.

Reimplemented from Instrument.

Definition at line 64 of file PMUCounter.cpp.

65 {
66  return MeasurementsMap
67  {
68  { "CPU cycles", Measurement(_cycles / _scale_factor, _unit + "cycles") },
69  { "CPU instructions", Measurement(_instructions / _scale_factor, _unit + "instructions") },
70  };
71 }
std::map< std::string, Measurement > MeasurementsMap
Map of measurements.
Definition: Instrument.h:109

◆ start()

void start ( )
overridevirtual

Start measuring.

Called just before the run of the test starts

Reimplemented from Instrument.

Definition at line 37 of file PMUCounter.cpp.

38 {
39  _pmu_cycles.reset();
40  _pmu_instructions.reset();
41 }
void reset()
Reset counter.
Definition: PMU.cpp:92

References PMU::reset().

◆ stop()

void stop ( )
overridevirtual

Stop measuring.

Called just after the run of the test ends

Reimplemented from Instrument.

Definition at line 43 of file PMUCounter.cpp.

44 {
45  try
46  {
47  _cycles = _pmu_cycles.get_value<long long>();
48  }
49  catch(const std::runtime_error &)
50  {
51  _cycles = 0;
52  }
53 
54  try
55  {
56  _instructions = _pmu_instructions.get_value<long long>();
57  }
58  catch(const std::runtime_error &)
59  {
60  _instructions = 0;
61  }
62 }
T get_value() const
Get the counter value.
Definition: PMU.h:91

References PMU::get_value().


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