Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions include/MGIS/Profiling.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down
5 changes: 5 additions & 0 deletions src/Profiling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading