From e186eb757ccdddad5ff612b2a9204422c9c5f1f6 Mon Sep 17 00:00:00 2001 From: dario Date: Fri, 24 May 2024 15:37:55 +0200 Subject: [PATCH] Added profiler implementation based on RAII. --- include/sta/debug/profile.hpp | 36 +++++++++++++++++++++++++++++++++++ src/debug/profile.cpp | 29 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 include/sta/debug/profile.hpp create mode 100644 src/debug/profile.cpp diff --git a/include/sta/debug/profile.hpp b/include/sta/debug/profile.hpp new file mode 100644 index 0000000..051f7ef --- /dev/null +++ b/include/sta/debug/profile.hpp @@ -0,0 +1,36 @@ +/* + * profile.hpp + * + * Created on: May 22, 2024 + * Author: Dario + */ + +#ifndef STA_DEBUGGING_PROFILING_HPP +#define STA_DEBUGGING_PROFILING_HPP + +#include +#ifdef STA_DEBUGGING_ENABLED + +namespace sta +{ + class Profiler { + public: + Profiler(const char* name); + + ~Profiler(); + private: + const char* name_; + uint32_t start_; + }; +} // namespace sta + +/** + * + */ +#define STA_TIME_IT(name) sta::Profiler profiler(name); + +#endif // STA_DEBUGGING_ENABLED + +#define STA_TIME_IT(name) ((void)0) + +#endif // STA_DEBUGGING_PROFILING_HPP diff --git a/src/debug/profile.cpp b/src/debug/profile.cpp new file mode 100644 index 0000000..6e0c8de --- /dev/null +++ b/src/debug/profile.cpp @@ -0,0 +1,29 @@ +/* + * profiler.cpp + * + * Created on: May 22, 2024 + * Author: Dario + */ + +#include + +#ifdef STA_DEBUGGING_ENABLED + +#include + +namespace sta +{ + Profiler::Profiler(const char* name) + : name_{name}, + start_{timeUs()} + { + + } + + Profiler::~Profiler() + { + STA_DEBUG_PRINTF("[PROFILER] %s took %d us", name_, timeUs() - start_); + } +} // namespace sta + +#endif // STA_DEBUGGING_ENABLED