mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
adding profiler
This commit is contained in:
parent
e07e437fb9
commit
691c8409a5
2
dependencies/iroha-ed25519
vendored
2
dependencies/iroha-ed25519
vendored
@ -1 +1 @@
|
|||||||
Subproject commit eb4c0fce900e2468b94bb9e9498af626bb66c039
|
Subproject commit 7307ffb8a89d2459f0c07ea5cab27c0d3496df00
|
||||||
64
src/cpp/model/Profiler.cpp
Normal file
64
src/cpp/model/Profiler.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include "Profiler.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
Profiler::Profiler()
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
Profiler::~Profiler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double Profiler::millis() const
|
||||||
|
{
|
||||||
|
auto current = std::chrono::high_resolution_clock::now();
|
||||||
|
std::chrono::duration<double, std::milli> fp_ms = current - mStartTick;
|
||||||
|
return fp_ms.count();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double Profiler::micros() const
|
||||||
|
{
|
||||||
|
auto current = std::chrono::high_resolution_clock::now();
|
||||||
|
std::chrono::duration<double, std::micro> fp_micros = current - mStartTick;
|
||||||
|
return fp_micros.count();
|
||||||
|
//auto diff = current - mStartTick;
|
||||||
|
//return diff.count() / 1000.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Profiler::nanos() const
|
||||||
|
{
|
||||||
|
auto current = std::chrono::high_resolution_clock::now();
|
||||||
|
return static_cast<double>((current - mStartTick).count());
|
||||||
|
}
|
||||||
|
|
||||||
|
double Profiler::seconds() const
|
||||||
|
{
|
||||||
|
auto current = std::chrono::high_resolution_clock::now();
|
||||||
|
std::chrono::duration<double, std::milli> fp_ms = current - mStartTick;
|
||||||
|
return fp_ms.count() / 1000.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Profiler::string() const
|
||||||
|
{
|
||||||
|
auto current = std::chrono::high_resolution_clock::now();
|
||||||
|
auto diff = current - mStartTick;
|
||||||
|
std::stringstream ss;
|
||||||
|
ss.precision(3);
|
||||||
|
|
||||||
|
if (diff < std::chrono::microseconds{1}) {
|
||||||
|
ss << diff.count() << " nano s";
|
||||||
|
} else if (diff < std::chrono::milliseconds{ 1 }) {
|
||||||
|
ss << (double)diff.count() / 1000.0 << " micro s";
|
||||||
|
} else if (diff < std::chrono::seconds{ 1 }) {
|
||||||
|
ss << (double)std::chrono::duration_cast<std::chrono::microseconds>(diff).count() / 1000.0 << " ms";
|
||||||
|
} else {
|
||||||
|
ss << (double)std::chrono::duration_cast<std::chrono::milliseconds>(diff).count() / 1000.0 << " s";
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
|
||||||
|
}
|
||||||
33
src/cpp/model/Profiler.h
Normal file
33
src/cpp/model/Profiler.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*!
|
||||||
|
*
|
||||||
|
* \author: einhornimmond
|
||||||
|
*
|
||||||
|
* \date: 08.03.19
|
||||||
|
*
|
||||||
|
* \brief: easy to use time profiler
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DR_LUA_WEB_MODULE_CORE_LIB_PROFILER_H
|
||||||
|
#define DR_LUA_WEB_MODULE_CORE_LIB_PROFILER_H
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Profiler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Profiler();
|
||||||
|
~Profiler();
|
||||||
|
|
||||||
|
inline void reset() { mStartTick = std::chrono::high_resolution_clock::now(); }
|
||||||
|
double millis() const;
|
||||||
|
double micros() const;
|
||||||
|
double nanos() const;
|
||||||
|
double seconds() const;
|
||||||
|
std::string string() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::chrono::time_point<std::chrono::high_resolution_clock> mStartTick;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //DR_LUA_WEB_MODULE_CORE_LIB_PROFILER_H
|
||||||
Loading…
x
Reference in New Issue
Block a user