summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-09-12 11:29:30 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-09-12 11:29:30 +0200
commit1dddf8c03e8b7781f549636be6d23e6ca245512b (patch)
tree256d99c0390aac33f9c64b3468f9565e30051ba4
parent2f864ac5289e8426f1d0c91c264a6a274047245b (diff)
util/cmake: enable ScopeTracing through cmake variable option
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
-rw-r--r--CMakeLists.txt8
-rw-r--r--src/util.cpp6
-rw-r--r--src/util.hpp14
3 files changed, 20 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a7382f0..e0e8f92 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -50,6 +50,14 @@ else()
remove_definitions(-DDEBUG_OUTPUT)
endif()
+# Should modernize the following somehow...
+set(ENABLE_SCOPE_TRACING OFF CACHE BOOL "Enable scope enter/leave messages for certain parts of the code.")
+if(ENABLE_SCOPE_TRACING)
+ add_definitions(-DSCOPE_TRACING)
+else()
+ remove_definitions(-DSCOPE_TRACING)
+endif()
+
set(SANITIZER_MODE "none" CACHE STRING "Build using a specific sanitizer (e.g. 'address', 'thread', 'leak', 'undefined'), depends on compiler; default none")
set(LINK_LIBCXX OFF CACHE BOOL "Link against LLVMs libc++")
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