diff --git a/include/MGIS/Profiling.hxx b/include/MGIS/Profiling.hxx index a3af5ea3e..da4882c5c 100644 --- a/include/MGIS/Profiling.hxx +++ b/include/MGIS/Profiling.hxx @@ -23,20 +23,36 @@ #define MGIS_CONCAT_INNER(a, b) a##b #define MGIS_VARNAME() MGIS_CONCAT(mgis_timer_, __COUNTER__) +/*Temporary macro to allow compiling (careful, the old CatchTimeSection(NAME) will not work)*/ +#define MGIS_CATCH_TIME_SECTION_1(NAME) \ + mgis::ProfilingSection MGIS_VARNAME()(NAME) + +#define MGIS_GET_CATCH_MACRO(_1, _2, MACRO_NAME, ...) MACRO_NAME +#define MGIS_EXPAND(x) x + +#define CatchTimeSection(...) \ + MGIS_EXPAND(MGIS_GET_CATCH_MACRO(__VA_ARGS__, MGIS_CATCH_TIME_SECTION_2, MGIS_CATCH_TIME_SECTION_1)(__VA_ARGS__)) + #define CatchTimeSection(CTX, NAME) \ mgis::ProfilingSection MGIS_VARNAME()(CTX, NAME, (CTX).isProfilingEnabled()) #define CatchLocalTimeSection(CTX, NAME, IS_ENABLED) \ mgis::ProfilingSection MGIS_VARNAME()(CTX, NAME, IS_ENABLED) + + namespace mgis { struct Context; struct MGIS_EXPORT ProfilingSection { - //! \brief Standard constructor (active or inactive depending on the - //! 'enabled' flag) - ProfilingSection(Context& ctx, std::string, bool) noexcept; - + //! \brief Standard constructor (active or inactive depending on the 'enabled' flag) + ProfilingSection(Context& ctx, + std::string name, + bool enabled) noexcept; + + //! \brief dummy constructor for 1-argument CatchTimeSection + ProfilingSection(std::string name) noexcept; + //! \brief Default constructor (fallback, always inactive) ProfilingSection() noexcept : ctx_ptr(nullptr), active(false) {} diff --git a/src/Profiling.cxx b/src/Profiling.cxx index e78bafb0c..ee8ddeb40 100644 --- a/src/Profiling.cxx +++ b/src/Profiling.cxx @@ -18,6 +18,11 @@ namespace mgis { } } // end of ProfilingSection + ProfilingSection::ProfilingSection(std::string /* name */) noexcept + : ctx_ptr(nullptr), + active(false) { + } // end of legacy ProfilingSection + ProfilingSection::~ProfilingSection() noexcept { if (this->active && this->ctx_ptr != nullptr) { const auto end = std::chrono::high_resolution_clock::now();