Skip to content

Commit

Permalink
Add OSC_RUNTIME_PERF_MEASUREMENTS_ENABLED compiler flag
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Jul 3, 2024
1 parent cfcf212 commit 774163a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/oscar/Utils/Perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ namespace osc
}
}

#ifdef OSC_RUNTIME_PERF_MEASUREMENTS_ENABLED
#define OSC_PERF_TOKENPASTE(x, y) x##y
#define OSC_PERF_TOKENPASTE2(x, y) OSC_PERF_TOKENPASTE(x, y)
#define OSC_PERF(label) \
static const size_t OSC_PERF_TOKENPASTE2(s_TimerID, __LINE__) = osc::detail::allocate_perf_mesurement_id(label, osc::extract_filename(__FILE__), __LINE__); \
const osc::detail::PerfTimer OSC_PERF_TOKENPASTE2(timer, __LINE__) (OSC_PERF_TOKENPASTE2(s_TimerID, __LINE__));
#else
#define OSC_PERF(label)
#endif
12 changes: 8 additions & 4 deletions src/oscar_compiler_configuration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ set(
CACHE BOOL
"force-enable/disable NDEBUG - even if building a release build. Note: unlike OSC_FORCE_ASSERTS_ENABLED, this also tends to enable runtime assertions from library headers"
)
set(OSC_RUNTIME_PERF_MEASUREMENTS_ENABLED ON
CACHE BOOL
"enable/disable whether performance counters are collected at runtime wherever the `OSC_PERF` macro is used in the source code"
)

# -------------- set globally-applicable policies ---------------- #

Expand Down Expand Up @@ -196,7 +200,7 @@ target_link_options(oscar_compiler_configuration INTERFACE
)
target_compile_features(oscar_compiler_configuration INTERFACE cxx_std_20)

# handle OSC_FORCE_ASSERTS_ENABLED
if(OSC_FORCE_ASSERTS_ENABLED)
target_compile_definitions(oscar_compiler_configuration INTERFACE -DOSC_FORCE_ASSERTS_ENABLED=1)
endif()
target_compile_definitions(oscar_compiler_configuration INTERFACE
$<$<BOOL:${OSC_FORCE_ASSERTS_ENABLED}>:-DOSC_FORCE_ASSERTS_ENABLED=1>
$<$<BOOL:${OSC_RUNTIME_PERF_MEASUREMENTS_ENABLED}>:-DOSC_RUNTIME_PERF_MEASUREMENTS_ENABLED=1>
)

0 comments on commit 774163a

Please sign in to comment.