Files
MuditaOS/module-utils/time/ScopedTime.hpp
Radoslaw Wicik a8573a404c Apply new style
2020-03-17 10:03:16 +01:00

39 lines
958 B
C++

#pragma once
#include <FreeRTOS.h>
#include <log/log.hpp>
#include <string>
#include <ticks.hpp>
namespace utils
{
namespace time
{
class Scoped
{
TickType_t timestamp;
std::string text;
public:
/// scoped timer usage:
/// auto time = Scoped("lol");
/// will log how much time elapsed in form 'lol time: 123'
/// auto time is important - othervise item will be created and removed instantly
Scoped(const std::string &text)
{
#if DEBUG_SCOPED_TIMINGS == 1
this->text = text;
timestamp = cpp_freertos::Ticks::GetTicks();
#endif
}
~Scoped()
{
#if DEBUG_SCOPED_TIMINGS == 1
LOG_DEBUG("%s time: %lu", text.c_str(), cpp_freertos::Ticks::GetTicks() - timestamp);
#endif
}
};
}; // namespace time
}; // namespace utils