Compute Library
 22.11
Profiler Class Reference

Profiler class to collect benchmark numbers. More...

#include <Profiler.h>

Public Types

using MeasurementsMap = std::map< std::string, std::vector< Measurement > >
 Mapping from instrument ids to their measurements. More...
 

Public Member Functions

void add (std::unique_ptr< Instrument > instrument)
 Add instrument to the performance monitor. More...
 
void test_start ()
 Call test_start() on all the added instruments. More...
 
void start ()
 Call start() on all the added instruments. More...
 
void stop ()
 Call stop() on all the added instruments. More...
 
void test_stop ()
 Call test_stop() on all the added instruments. More...
 
const MeasurementsMapmeasurements () const
 Return measurements for all instruments. More...
 
const std::string & header () const
 Return JSON formatted header data. More...
 

Detailed Description

Profiler class to collect benchmark numbers.

A profiler manages multiple instruments that can collect different types of benchmarking numbers.

Definition at line 45 of file Profiler.h.

Member Typedef Documentation

◆ MeasurementsMap

using MeasurementsMap = std::map<std::string, std::vector<Measurement> >

Mapping from instrument ids to their measurements.

Definition at line 49 of file Profiler.h.

Member Function Documentation

◆ add()

void add ( std::unique_ptr< Instrument instrument)

Add instrument to the performance monitor.

All added instruments will be used when start or stop are called to make measurements.

Parameters
[in]instrumentInstrument to be used to measure performance.

Definition at line 35 of file Profiler.cpp.

Referenced by Framework::get_profiler().

36 {
37  _instruments.emplace_back(std::move(instrument));
38 }

◆ header()

const std::string & header ( ) const

Return JSON formatted header data.

Returns
JSON formmated string

Definition at line 94 of file Profiler.cpp.

Referenced by Framework::error_on_missing_assets().

95 {
96  return _header_data;
97 }

◆ measurements()

const Profiler::MeasurementsMap & measurements ( ) const

Return measurements for all instruments.

Returns
measurements for all instruments.

Definition at line 89 of file Profiler.cpp.

Referenced by Framework::error_on_missing_assets(), and main().

90 {
91  return _measurements;
92 }

◆ start()

void start ( )

Call start() on all the added instruments.

Called just before the run of the test starts

Definition at line 48 of file Profiler.cpp.

Referenced by Framework::error_on_missing_assets(), and main().

49 {
50  for(auto &instrument : _instruments)
51  {
52  instrument->start();
53  }
54 }

◆ stop()

void stop ( )

Call stop() on all the added instruments.

Called just after the run of the test ends

Definition at line 56 of file Profiler.cpp.

Referenced by Framework::error_on_missing_assets(), and main().

57 {
58  for(auto instrument = _instruments.rbegin(); instrument != _instruments.rend(); instrument++)
59  {
60  (*instrument)->stop();
61  }
62  for(const auto &instrument : _instruments)
63  {
64  for(const auto &measurement : instrument->measurements())
65  {
66  _measurements[instrument->id() + "/" + measurement.first].push_back(measurement.second);
67  }
68  }
69 }

◆ test_start()

void test_start ( )

Call test_start() on all the added instruments.

Called before the test set up starts

Definition at line 40 of file Profiler.cpp.

Referenced by Framework::error_on_missing_assets().

41 {
42  for(auto &instrument : _instruments)
43  {
44  instrument->test_start();
45  }
46 }

◆ test_stop()

void test_stop ( )

Call test_stop() on all the added instruments.

Called after the test teardown ended

Definition at line 71 of file Profiler.cpp.

Referenced by Framework::error_on_missing_assets().

72 {
73  for(auto instrument = _instruments.rbegin(); instrument != _instruments.rend(); instrument++)
74  {
75  (*instrument)->test_stop();
76  }
77 
78  for(const auto &instrument : _instruments)
79  {
80  for(const auto &measurement : instrument->test_measurements())
81  {
82  _measurements[instrument->id() + "/" + measurement.first].push_back(measurement.second);
83  }
84 
85  _header_data = instrument->instrument_header();
86  }
87 }

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