diff options
author | Marcus Fritzsch <marcus_fritzsch@mentor.com> | 2017-09-12 11:29:30 +0200 |
---|---|---|
committer | Marcus Fritzsch <marcus_fritzsch@mentor.com> | 2017-09-12 11:29:30 +0200 |
commit | 1dddf8c03e8b7781f549636be6d23e6ca245512b (patch) | |
tree | 256d99c0390aac33f9c64b3468f9565e30051ba4 /src | |
parent | 2f864ac5289e8426f1d0c91c264a6a274047245b (diff) |
util/cmake: enable ScopeTracing through cmake variable option
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/util.cpp | 6 | ||||
-rw-r--r-- | src/util.hpp | 14 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/util.cpp b/src/util.cpp index db61bc2..44c377c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -24,7 +24,13 @@ #include <unistd.h> +#ifdef SCOPE_TRACING thread_local int ScopeTrace::indent = 0; +explicit ScopeTrace::ScopeTrace(char const *func) : f(func) { + fprintf(stderr, "%lu %*s%s -->\n", pthread_self(), 2 * indent++, "", this->f); +} +ScopeTrace::~ScopeTrace() { fprintf(stderr, "%lu %*s%s <--\n", pthread_self(), 2 * --indent, "", this->f); } +#endif unique_fd::~unique_fd() { if (this->fd != -1) { diff --git a/src/util.hpp b/src/util.hpp index ff173c8..5d602ed 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -27,6 +27,9 @@ extern "C" { #include <afb/afb-binding.h> }; +#define CONCAT_(X, Y) X##Y +#define CONCAT(X, Y) CONCAT_(X, Y) + #ifdef __GNUC__ #define ATTR_FORMAT(stringindex, firsttocheck) \ __attribute__((format(printf, stringindex, firsttocheck))) @@ -50,13 +53,10 @@ extern "C" { #define logdebug(...) #endif -#ifdef NDEBUG +#ifndef SCOPE_TRACING #define ST() #define STN(N) #else -#define CONCAT_(X, Y) X##Y -#define CONCAT(X, Y) CONCAT_(X, Y) - #define ST() \ ScopeTrace __attribute__((unused)) CONCAT(trace_scope_, __LINE__)(__func__) #define STN(N) \ @@ -65,10 +65,8 @@ extern "C" { struct ScopeTrace { thread_local static int indent; char const *f{}; - explicit ScopeTrace(char const *func) : f(func) { - fprintf(stderr, "%lu %*s%s -->\n", pthread_self(), 2 * indent++, "", this->f); - } - ~ScopeTrace() { fprintf(stderr, "%lu %*s%s <--\n", pthread_self(), 2 * --indent, "", this->f); } + explicit ScopeTrace(char const *func); + ~ScopeTrace(); }; #endif |