mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-07-04 13:17:08 -04:00
39 lines
963 B
C++
39 lines
963 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: %" PRIu32, text.c_str(), cpp_freertos::Ticks::GetTicks() - timestamp);
|
|
#endif
|
|
}
|
|
};
|
|
|
|
}; // namespace time
|
|
}; // namespace utils
|