Skip to content
Snippets Groups Projects
Commit c07ddf86 authored by Radovan Červený's avatar Radovan Červený
Browse files

added Type enum, copied old test for comparison

parent 122b33c7
No related branches found
No related tags found
1 merge request!14BP_cervera3 - new measurements
......@@ -5,11 +5,13 @@
#ifndef MEASUREMENT_ENGINE_HPP_
#define MEASUREMENT_ENGINE_HPP_
 
#include "MeasurementTypes.hpp"
namespace measurements {
 
class MeasurementEngine {
public:
virtual void push_measurement_frame ( std::string, unsigned ) = 0;
virtual void push_measurement_frame ( std::string, measurements::Type ) = 0;
virtual void pop_measurement_frame ( ) = 0;
virtual void get_results ( ) = 0;
virtual ~MeasurementEngine ( ) = default;
......
/*
* Author: Radovan Cerveny
*/
#ifndef MEASUREMENT_TYPES_HPP_
#define MEASUREMENT_TYPES_HPP_
namespace measurements {
enum Type {
OVERALL = 1, INIT = 2, FINALIZE = 4, MAIN = 8, AUXILIARY = 16
};
}
#endif /* MEASUREMENT_TYPES_HPP_ */
......@@ -2,6 +2,7 @@
* Author: Radovan Cerveny
*/
 
#include "MeasurementTypes.hpp"
#include "Measurements.hpp"
#include "TimeMeasurementEngine.hpp"
 
......@@ -26,7 +27,7 @@ Measurements::~Measurements ( ) {
* creates new block on top of the measurements stack
* @param block_name
*/
void Measurements::start ( std::string block_name, unsigned type ) {
void Measurements::start ( std::string block_name, measurements::Type type ) {
for ( auto me : INSTANCE.measurement_engines )
me->push_measurement_frame ( block_name, type );
}
......
......@@ -7,8 +7,10 @@
 
#include <string>
#include <vector>
#include "MeasurementTypes.hpp"
#include "MeasurementEngine.hpp"
 
namespace measurements {
 
class Measurements {
......@@ -22,7 +24,7 @@ private:
static Measurements INSTANCE;
 
public:
static void start ( std::string, unsigned );
static void start ( std::string, measurements::Type );
static void end ( );
static void print ( );
};
......
......@@ -9,8 +9,8 @@ using namespace std::chrono;
 
namespace measurements {
 
void TimeMeasurementEngine::push_measurement_frame ( std::string frame_name, unsigned frame_type ) {
TimeMeasurementFrame tmf = { std::move ( frame_name ), frame_type, std::vector < unsigned > ( ), system_clock::now ( ), microseconds ( 0 ), microseconds ( 0 ) };
void TimeMeasurementEngine::push_measurement_frame ( std::string frame_name, measurements::Type frame_type ) {
TimeMeasurementFrame tmf = { std::move ( frame_name ), frame_type, std::vector < unsigned > ( ), high_resolution_clock::now ( ), microseconds ( 0 ), microseconds ( 0 ) };
 
frames.emplace_back ( std::move ( tmf ) );
}
......@@ -20,7 +20,7 @@ void TimeMeasurementEngine::pop_measurement_frame ( ) {
 
frames.pop_back ( );
 
current_frame.duration = duration_cast < microseconds > ( system_clock::now ( ) - current_frame.start );
current_frame.duration = duration_cast < microseconds > ( high_resolution_clock::now ( ) - current_frame.start );
current_frame.real_duration += current_frame.duration;
 
unsigned idx = results.size ( );
......@@ -38,6 +38,7 @@ void TimeMeasurementEngine::get_results ( ) {
for ( auto frame : results ) {
std::cout << frame.frame_name << std::endl;
std::cout << frame.duration << ' ' << frame.real_duration << std::endl;
for ( unsigned idx : frame.sub_frames )
std::cout << idx << ' ';
 
......
......@@ -14,12 +14,12 @@ namespace measurements {
 
struct TimeMeasurementFrame {
std::string frame_name;
unsigned frame_type;
measurements::Type frame_type;
std::vector < unsigned > sub_frames;
 
std::chrono::time_point < std::chrono::system_clock > start;
std::chrono::microseconds duration;
std::chrono::microseconds real_duration;
std::chrono::time_point < std::chrono::high_resolution_clock > start;
std::chrono::microseconds duration;
std::chrono::microseconds real_duration;
};
 
class TimeMeasurementEngine : public MeasurementEngine {
......@@ -28,7 +28,7 @@ private:
std::vector < TimeMeasurementFrame > results;
 
public:
void push_measurement_frame ( std::string, unsigned );
void push_measurement_frame ( std::string, measurements::Type );
void pop_measurement_frame ( );
void get_results ( );
};
......
......@@ -13,16 +13,28 @@ void MeasurementsTest::tearDown ( ) {
}
 
void MeasurementsTest::testMeasurements ( ) {
measurements::Measurements::start ( "test", 0 );
std::this_thread::sleep_for ( std::chrono::milliseconds ( 100 ) );
measurements::Measurements::start ( "test2", 0 );
measurements::Measurements::start ( "global", measurements::Type::OVERALL );
measurements::Measurements::start ( "init", measurements::Type::INIT );
std::this_thread::sleep_for ( std::chrono::milliseconds ( 100 ) );
measurements::Measurements::end ( );
std::this_thread::sleep_for ( std::chrono::milliseconds ( 50 ) );
measurements::Measurements::start ( "main", measurements::Type::MAIN );
std::this_thread::sleep_for ( std::chrono::milliseconds ( 20 ) );
measurements::Measurements::start ( "aux", measurements::Type::AUXILIARY );
std::this_thread::sleep_for ( std::chrono::milliseconds ( 40 ) );
measurements::Measurements::end ( );
std::this_thread::sleep_for ( std::chrono::milliseconds ( 80 ) );
measurements::Measurements::start ( "aux", measurements::Type::AUXILIARY );
std::this_thread::sleep_for ( std::chrono::milliseconds ( 40 ) );
measurements::Measurements::end ( );
std::this_thread::sleep_for ( std::chrono::milliseconds ( 80 ) );
measurements::Measurements::end ( );
measurements::Measurements::start ( "fin", measurements::Type::FINALIZE );
std::this_thread::sleep_for ( std::chrono::milliseconds ( 30 ) );
measurements::Measurements::start ( "aux", measurements::Type::AUXILIARY );
std::this_thread::sleep_for ( std::chrono::milliseconds ( 40 ) );
measurements::Measurements::end ( );
std::this_thread::sleep_for ( std::chrono::milliseconds ( 80 ) );
measurements::Measurements::end ( );
measurements::Measurements::end ( );
measurements::Measurements::print ( );
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment