diff --git a/src/prof.hpp b/src/prof.hpp new file mode 100644 index 0000000..9a40d38 --- /dev/null +++ b/src/prof.hpp @@ -0,0 +1,15 @@ +struct Prof_Scope_Print { + Prof_Scope_Print(const char *name) : scope_name { name }, scope_start_t { std::chrono::high_resolution_clock::now() } {} + ~Prof_Scope_Print() { + using namespace std::chrono; + time_point scope_end_t = high_resolution_clock::now(); + duration scope_duration = duration_cast(scope_end_t - scope_start_t); + fprintf(stderr, "[profile] %s took %.4f ms\n", scope_name, scope_duration.count() * 0.001f); + } + + const char *scope_name; + std::chrono::time_point scope_start_t; +}; + +#define TIMED_SCOPE() const Prof_Scope_Print CONCAT_STR(_prof, __LINE__) { __func__ } +#define TIMED_SCOPE_NAME(name) const Prof_Scope_Print CONCAT_STR(_prof, __LINE__) { name } diff --git a/src/rntviewer.cpp b/src/rntviewer.cpp index fafb385..37aae02 100644 --- a/src/rntviewer.cpp +++ b/src/rntviewer.cpp @@ -33,6 +33,7 @@ #include "types.h" #include "defer.hpp" +#include "prof.hpp" #include "mem.h" #include "str.h" #include "rntuple.h"