From cc8bc663df9fc55e7024787175e759aac9f50358 Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Tue, 12 May 2020 17:17:27 +0000 Subject: [PATCH] update(userspace/profiler): introduce profiler namespace Co-authored-by: Lorenzo Fontana Signed-off-by: Leonardo Di Donato --- userspace/profiler/profile.fbs | 2 +- userspace/profiler/profiler.h | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/userspace/profiler/profile.fbs b/userspace/profiler/profile.fbs index e91654e4..a5f1d35b 100644 --- a/userspace/profiler/profile.fbs +++ b/userspace/profiler/profile.fbs @@ -1,4 +1,4 @@ -namespace profiler_structures; +namespace profiler; file_identifier "FPRO"; file_extension "fpro"; diff --git a/userspace/profiler/profiler.h b/userspace/profiler/profiler.h index 2b2b5181..7f55c0b8 100644 --- a/userspace/profiler/profiler.h +++ b/userspace/profiler/profiler.h @@ -22,9 +22,12 @@ limitations under the License. #include #include +namespace profiler +{ + #define CHUNK_ELEMENTS 7 #define CHUNK_SIZE ((1 << 20) * CHUNK_ELEMENTS) // 20 MiB = 5242880 * sizeof(uint32_t) -#define LABEL_MASK 0x80000000 // Largest positive int32 + 1 +#define LABEL_MASK 0x80000000 // Largest positive int32 + 1 struct cursor { @@ -78,13 +81,13 @@ HEDLEY_NEVER_INLINE uint32_t create_label(char const* file, int line, char const return l.label; } -struct profiler +struct profile { uint32_t* data; int n; int epochs; // (max) depth at the moment of execution - explicit profiler(uint32_t label) + explicit profile(uint32_t label) { data = c.current; auto next = data + CHUNK_ELEMENTS; @@ -107,7 +110,7 @@ struct profiler data[2] = lo; } - ~profiler() + ~profile() { unsigned int lo, hi; __asm__ __volatile__("rdtsc" @@ -115,7 +118,6 @@ struct profiler data[3] = hi; data[4] = lo; - if(HEDLEY_LIKELY(epochs > 1)) { for(int i = 0; i < epochs - 1; i++) @@ -163,6 +165,8 @@ struct profiler #define PROFILE_VARIABLE_IMPL(arg1, arg2) arg1##arg2 #define PROFILE_VARIABLE(arg1, arg2) PROFILE_VARIABLE_IMPL(arg1, arg2) -#define PROFILEME() \ - static uint32_t PROFILE_VARIABLE(_label, __LINE__) = create_label(__FILE__, __LINE__, __FUNCTION__); \ - profiler PROFILE_VARIABLE(_profile_, __LINE__)(PROFILE_VARIABLE(_label, __LINE__)); +#define PROFILEME() \ + static uint32_t PROFILE_VARIABLE(_label, __LINE__) = profiler::create_label(__FILE__, __LINE__, __FUNCTION__); \ + profiler::profile PROFILE_VARIABLE(_profile_, __LINE__)(PROFILE_VARIABLE(_label, __LINE__)); + +}; // namespace profiler \ No newline at end of file