2016-06-05 16:08:55 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <map>
|
2016-07-01 23:20:41 +02:00
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <HyperionConfig.h>
|
2016-06-05 16:08:55 +02:00
|
|
|
|
2020-06-17 20:59:26 +02:00
|
|
|
/*
|
|
|
|
The performance (real time) of any function can be tested with the help of profiler.
|
|
|
|
The determined times are determined using clock cycles.
|
|
|
|
|
|
|
|
To do this, compile with the cmake option: -DENABLE_PROFILER=ON
|
|
|
|
This header file (utils/Profiler.h) must be included in the respective file that contains the function to be measured
|
|
|
|
|
|
|
|
The start time is set in a function with the following instructions:
|
|
|
|
PROFILER_TIMER_START("test_performance")
|
|
|
|
The end point is set as follows:
|
|
|
|
PROFILER_TIMER_GET("test_performance")
|
|
|
|
|
|
|
|
For more profiler function see the macros listed below
|
|
|
|
*/
|
|
|
|
|
2016-06-05 16:08:55 +02:00
|
|
|
#ifndef ENABLE_PROFILER
|
2020-07-12 09:19:59 +02:00
|
|
|
#error "Profiler is not for production code, enable it via cmake or remove header include"
|
2016-06-05 16:08:55 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// profiler
|
2020-06-17 20:59:26 +02:00
|
|
|
#define PROFILER_BLOCK_EXECUTION_TIME Profiler DEBUG_PROFILE__BLOCK__EXECUTION__TIME_messure_object(__FILE__, __FUNCTION__, __LINE__ );
|
|
|
|
#define PROFILER_TIMER_START(stopWatchName) Profiler::TimerStart(stopWatchName, __FILE__, __FUNCTION__, __LINE__);
|
|
|
|
#define PROFILER_TIMER_GET(stopWatchName) Profiler::TimerGetTime(stopWatchName, __FILE__, __FUNCTION__, __LINE__);
|
|
|
|
#define PROFILER_TIMER_GET_IF(condition, stopWatchName) { if (condition) {Profiler::TimerGetTime(stopWatchName, __FILE__, __FUNCTION__, __LINE__);} }
|
2016-06-05 16:08:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Profiler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Profiler(const char* sourceFile, const char* func, unsigned int line);
|
|
|
|
~Profiler();
|
|
|
|
|
2017-03-04 22:17:42 +01:00
|
|
|
static void TimerStart(const QString stopWatchName, const char* sourceFile, const char* func, unsigned int line);
|
|
|
|
static void TimerGetTime(const QString stopWatchName, const char* sourceFile, const char* func, unsigned int line);
|
2016-06-05 16:08:55 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
static void initLogger();
|
2020-06-17 20:59:26 +02:00
|
|
|
|
2016-06-05 16:08:55 +02:00
|
|
|
static Logger* _logger;
|
2017-03-04 22:17:42 +01:00
|
|
|
const char* _file;
|
|
|
|
const char* _func;
|
|
|
|
unsigned int _line;
|
|
|
|
unsigned int _blockId;
|
|
|
|
clock_t _startTime;
|
2016-06-05 16:08:55 +02:00
|
|
|
};
|