/** * @file include/di/Tracer.h * @brief Tracer for logging code duration * @copyright 2018 Dual Inventive Technology Centre B.V. * * Class for logging code duration */ #ifndef INCLUDE_DI_TRACER_H_ #define INCLUDE_DI_TRACER_H_ #include #include #include #include #include #include #include #include namespace Di { /** * @class Tracer * * Class for logging code duration */ class Tracer { public: /** * Constructor * @param path the path to write the csv to */ explicit Tracer(const std::string &path); /** * Start the trace * * @param name the name of the trace */ void start(const std::string name); /** * Stop the trace * * @param name the name of the trace */ void stop(const std::string &name); void trigger(const std::string &name); private: struct __trace { __trace(const std::string &initName, bool initTick) : name(initName), minDuration(std::chrono::nanoseconds::max()), maxDuration(std::chrono::nanoseconds::min()), start(std::chrono::high_resolution_clock::now()), numberOfTicks(0) { if (initTick) { numberOfTicks = 1; } } std::string name; std::chrono::nanoseconds minDuration; std::chrono::nanoseconds maxDuration; std::chrono::time_point start; uint64_t numberOfTicks; }; void __write(); std::shared_ptr> __traces; Di::Timer __timer; std::mutex __mut; std::ofstream __fout; }; } // namespace Di #endif // INCLUDE_DI_TRACER_H_