kranewl

A wlroots-based dynamic Wayland compositor, written in C++, configurable with Lua
git clone git://git.deurzen.net/kranewl
Log | Files | Refs | LICENSE

trace.hh (1230B)


      1 #pragma once
      2 
      3 #include <spdlog/spdlog.h>
      4 
      5 #include <string>
      6 
      7 #ifndef NDEBUG
      8 #ifndef TRACING_DISABLED
      9 #define TRACING_ENABLED 1
     10 #endif
     11 #endif
     12 
     13 #ifdef TRACING_ENABLED
     14 namespace tracing
     15 {
     16     class Tracer {
     17     public:
     18         Tracer() = delete;
     19         Tracer(Tracer const&) = delete;
     20         Tracer(Tracer&&) = delete;
     21 
     22         Tracer& operator=(Tracer const&) = delete;
     23         Tracer& operator=(Tracer&&) = delete;
     24 
     25         Tracer(std::string const& fun, std::string const& file, int const line)
     26             : m_function_name{fun},
     27               m_file_name{file},
     28               m_line_number{line}
     29         {
     30             spdlog::trace("Entering function: "
     31                 + m_function_name
     32                 + " ("
     33                 + m_file_name
     34                 + ":"
     35                 + std::to_string(m_line_number)
     36                 + ")");
     37         }
     38 
     39         ~Tracer()
     40         {
     41             spdlog::trace("Leaving function: " + m_function_name);
     42         }
     43 
     44     private:
     45         std::string m_function_name;
     46         std::string m_file_name;
     47         int m_line_number;
     48     };
     49 }
     50 #endif
     51 
     52 #ifdef TRACING_ENABLED
     53 #define TRACE() tracing::Tracer _tracer_object__ ## __COUNTER__ {__func__, __FILE__, __LINE__}
     54 #else
     55 #define TRACE()
     56 #endif