Skip to content
Open
Show file tree
Hide file tree
Changes from 161 commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
f8d06b2
Add dynamic programming to CLP.
SharafMohamed Sep 17, 2025
add11a2
Format.
SharafMohamed Sep 19, 2025
c82dbab
Merge branch 'main' into dfa-search-using-ls-port
SharafMohamed Sep 22, 2025
70f357b
Add unit-tests.
SharafMohamed Sep 26, 2025
9d3e152
Format.
SharafMohamed Sep 26, 2025
b587085
Add missing header; Flip cast for comparison to SymbolID over unit32_t.
SharafMohamed Sep 26, 2025
9d5dd94
Fix typos.
SharafMohamed Sep 26, 2025
c5bd43b
Remove magic number.
SharafMohamed Sep 26, 2025
d7cfb0d
Add missing header; Fix typo; Fix if statement.
SharafMohamed Sep 26, 2025
27ebc0f
Remove thread-unsafe statics.
SharafMohamed Sep 26, 2025
7a2f74e
Use uint64_t with bit shift operator.
SharafMohamed Sep 26, 2025
9848096
Switch to default initialization for all false map.
SharafMohamed Sep 26, 2025
3b4572b
Fix bug in string_utils and add to test-string_utils; Refactor unit-t…
SharafMohamed Oct 1, 2025
b633980
Format.
SharafMohamed Oct 1, 2025
62f23b0
Add flags to hide test helper in production.
SharafMohamed Oct 1, 2025
8b093a0
Cast to SymbolId instead of uint32_t.
SharafMohamed Oct 1, 2025
49dc925
Add missing include.
SharafMohamed Oct 1, 2025
7b73754
Avoid multiple get_logtype() calls; Reserve size.
SharafMohamed Oct 1, 2025
c8f9046
Remove more get_logtype() calls and make tokens be references into th…
SharafMohamed Oct 1, 2025
9eba2d5
Switch from contains to find to avoid double lookup.
SharafMohamed Oct 1, 2025
4115786
Fix typos.
SharafMohamed Oct 1, 2025
8aa356a
Reduce mask size to 16 bits; Update documentation to match.
SharafMohamed Oct 1, 2025
e5afe04
Use propery type for bit mask.
SharafMohamed Oct 1, 2025
7352fd2
Define cross-test constants in a single place; Make sure constants ar…
SharafMohamed Oct 1, 2025
80354f3
Reserve var dict size.
SharafMohamed Oct 1, 2025
1680f33
Cache logtype and use references into it.
SharafMohamed Oct 1, 2025
5bc40ff
Replace contain with find to avoid double lookup.
SharafMohamed Oct 1, 2025
decca7e
Reserve possible_logtype_ids.
SharafMohamed Oct 1, 2025
26c8e49
Use correct types for bit mask.
SharafMohamed Oct 1, 2025
0908106
Use constants in place of magic numbers.
SharafMohamed Oct 1, 2025
42d7a1c
Add paranthesis for bit operation clarity.
SharafMohamed Oct 1, 2025
fae5913
Add docstrings for unit-test helpers.
SharafMohamed Oct 1, 2025
2bdf381
Fix some unit-tests.
SharafMohamed Oct 1, 2025
764973c
Merge branch 'main' into dfa-search-using-ls-port
SharafMohamed Oct 1, 2025
8996cfb
Format.
SharafMohamed Oct 1, 2025
7608cab
Remove consecutive wildcards from interpretation tokens; Undo changes…
SharafMohamed Oct 3, 2025
a130b96
Format.
SharafMohamed Oct 3, 2025
ae93a4e
Merge branch 'main' into dfa-search-using-ls-port
SharafMohamed Oct 3, 2025
f2f01d6
Add missing headers.
SharafMohamed Oct 3, 2025
0eed0db
Improve docstring.
SharafMohamed Oct 3, 2025
e2c55a7
Use find over contains to avoid double lookup.
SharafMohamed Oct 3, 2025
1cbbefd
Fix type in test to use variable_dictionary_id_t.
SharafMohamed Oct 3, 2025
f3ab0a5
Update docstring for consistency.
SharafMohamed Oct 3, 2025
ddf3e23
Fix macos ULL error.
SharafMohamed Oct 3, 2025
d629ae9
Replace map with bool vector.
SharafMohamed Oct 3, 2025
9e3e9d9
Fix type mismatch.
SharafMohamed Oct 3, 2025
06ab6a6
Add missing header; Remove unused header.
SharafMohamed Oct 3, 2025
ad951ae
Add missing header.
SharafMohamed Oct 3, 2025
f3d27b7
Format.
SharafMohamed Oct 3, 2025
76ecb1d
Merge branch 'main' into dfa-search-using-ls-port
SharafMohamed Oct 3, 2025
9920bc9
Remove duplicate sub queries.
SharafMohamed Oct 4, 2025
e7dcc43
Format.
SharafMohamed Oct 4, 2025
ed13886
Rename to rhs.
SharafMohamed Oct 4, 2025
e0ecdd0
Refactor schema search classes and methods into new files; Do the sam…
SharafMohamed Dec 9, 2025
134c2a4
Remove comments.
SharafMohamed Dec 9, 2025
763f8be
Fix test names.
SharafMohamed Dec 9, 2025
c9d1da2
Fix guard format; Remove duplicate VarInfo.
SharafMohamed Dec 9, 2025
39c3f18
Remove using form logtype header.
SharafMohamed Dec 9, 2025
88dca33
Remove using from variable header.
SharafMohamed Dec 9, 2025
7479840
Fix comment indentation.
SharafMohamed Dec 9, 2025
c318db4
Fix formatting.
SharafMohamed Dec 9, 2025
d08ce9e
Fix naming.
SharafMohamed Dec 9, 2025
7caa3e7
Fix indentation.
SharafMohamed Dec 9, 2025
90c2a7f
Format.
SharafMohamed Dec 9, 2025
fc2891e
Remove using from header.
SharafMohamed Dec 9, 2025
7320c0f
Simplify ranges::find call.
SharafMohamed Dec 9, 2025
fd1eecd
Fix typo in docstring.
SharafMohamed Dec 9, 2025
43b5b3a
Check oob.
SharafMohamed Dec 9, 2025
754b4f0
Lint.
SharafMohamed Dec 10, 2025
1ebb3bf
Check lexer map contains symbol.
SharafMohamed Dec 10, 2025
f5e1f9a
Replace magic numbers.
SharafMohamed Dec 10, 2025
31fe021
Simplify ranges call.
SharafMohamed Dec 10, 2025
e2330cc
Remove explicit keyword; Add docstring for VarInfo.
SharafMohamed Dec 10, 2025
732b452
Flip check order.
SharafMohamed Dec 10, 2025
8fdd28d
Fix typo.
SharafMohamed Dec 10, 2025
322390c
Improve constexpr.
SharafMohamed Dec 10, 2025
b33a072
Merge branch 'main' into dfa-search-using-ls-port
SharafMohamed Dec 10, 2025
3dc36b2
Merge branch 'main' into dfa-search-using-ls-port
SharafMohamed Dec 10, 2025
eed8b0b
Improve make_var_dict.
SharafMohamed Dec 11, 2025
dff3df0
Add REQUIRE(false).
SharafMohamed Jan 11, 2026
e4f39a2
Update includes to use angled braces.
SharafMohamed Jan 11, 2026
426966c
Reverse order to have shorter branch first.
SharafMohamed Jan 11, 2026
510c176
Update cmake.
SharafMohamed Jan 11, 2026
db92c0d
Move todo to issue.
SharafMohamed Jan 11, 2026
934889a
Reword comments.
SharafMohamed Jan 11, 2026
21046b0
Remove std.
SharafMohamed Jan 11, 2026
b27b92b
Update includes.
SharafMohamed Jan 11, 2026
65e683d
Remove unused var.
SharafMohamed Jan 11, 2026
07fff20
Add missing header.
SharafMohamed Jan 11, 2026
6cc8df9
Remove unused headers.
SharafMohamed Jan 11, 2026
b6312f0
Fix headers.
SharafMohamed Jan 12, 2026
34bdf28
Group clp headers seperately.
SharafMohamed Jan 12, 2026
caf160f
Fix clp compile error by reverting to old include style for Query.hpp.
SharafMohamed Jan 14, 2026
45294c4
Fix clp, clo, clg, to use new include style.
SharafMohamed Jan 14, 2026
43b5bd1
Make const.
SharafMohamed Jan 14, 2026
3ce21e8
Replace static string.
SharafMohamed Jan 14, 2026
dc414a0
Switch to deque.
SharafMohamed Jan 14, 2026
71a4a8f
Use traceable exception.
SharafMohamed Jan 14, 2026
74e4688
Add consts.
SharafMohamed Jan 14, 2026
6b56c6c
Merge branch 'main' into dfa-search-using-ls-port
SharafMohamed Jan 14, 2026
2ddc90a
Fix build.
SharafMohamed Jan 14, 2026
dc542fe
Format.
SharafMohamed Jan 14, 2026
aee311c
Fix build errors.
SharafMohamed Jan 14, 2026
18499c2
Use braced initialization.
SharafMohamed Jan 16, 2026
12c926d
Use braced initialization, again.
SharafMohamed Jan 16, 2026
68660b5
Remove obvious comment.
SharafMohamed Jan 16, 2026
9425afc
Use braced initialization, again x2.
SharafMohamed Jan 16, 2026
fa8e353
Add full stop.
SharafMohamed Jan 16, 2026
3fde49f
Remove obvious comment, again.
SharafMohamed Jan 16, 2026
435a008
Move using into namespace.
SharafMohamed Jan 16, 2026
fc47f23
Use pre-increment over post-increment.
SharafMohamed Jan 16, 2026
b81360d
Switch tuple to struct.
SharafMohamed Jan 16, 2026
5922cb1
Move SchemaSearcherTest class into its own file.
SharafMohamed Jan 18, 2026
235fa74
Add doc string.
SharafMohamed Jan 18, 2026
06704c7
Move constexpr to method param.
SharafMohamed Jan 18, 2026
82251ab
Add class level docstring.
SharafMohamed Jan 18, 2026
66bd892
Update docstring.
SharafMohamed Jan 18, 2026
8133207
Remove unused header.
SharafMohamed Jan 18, 2026
73f1890
Make test vector empty.
SharafMohamed Jan 18, 2026
62600b9
Merge branch 'main' into dfa-search-using-ls-port
SharafMohamed Jan 19, 2026
d2f4e44
Add header.
SharafMohamed Jan 19, 2026
49aac57
Update using in test header.
SharafMohamed Jan 19, 2026
b0bea5f
Add missing namespace.
SharafMohamed Jan 19, 2026
ea477fb
Add missing namespace again.
SharafMohamed Jan 19, 2026
be6f629
Ensure mask shift doesn't exceed uint64_t size.
SharafMohamed Jan 19, 2026
9e0bf19
Fix using.
SharafMohamed Jan 19, 2026
2e517fb
Format.
SharafMohamed Jan 19, 2026
aaa69e4
Make it clear the c++ macro and cmake variable are seperate things by…
SharafMohamed Feb 5, 2026
0e6f078
Merge branch 'main' into dfa-search-using-ls-port
SharafMohamed Feb 5, 2026
afeda55
Merge branch 'main' into dfa-search-using-ls-port
SharafMohamed Feb 9, 2026
8c3950a
Allow timestamped headers; Remove delimiter checking code in load_lexer.
SharafMohamed Feb 11, 2026
c79077c
Allow for 0 capture header to be added to search lexer.
SharafMohamed Feb 11, 2026
0ca3ab2
Merge branch 'allow-headers-with-timestamp' into dfa-search-using-ls-…
SharafMohamed Feb 11, 2026
2039f72
Remove unused headers and unused declarations.
SharafMohamed Feb 11, 2026
a8eb0c1
Remove unused headers and unused declarations.
SharafMohamed Feb 11, 2026
b0b1d06
Remove unneeded move operation.
SharafMohamed Feb 11, 2026
065ebb9
Safety check for empty captures set.
SharafMohamed Feb 11, 2026
84fb5ee
Avoid temporary object.
SharafMohamed Feb 11, 2026
53e6c1b
Merge branch 'allow-headers-with-timestamp' into dfa-search-using-ls-…
SharafMohamed Feb 11, 2026
a1bcdb5
Add new unit-tests; Cleanup config schema.txt.
SharafMohamed Feb 11, 2026
27d6d12
Revert change to schema.
SharafMohamed Feb 18, 2026
176e828
Add drop_all comment.
SharafMohamed Feb 18, 2026
6d4c1b9
Merge branch 'allow-headers-with-timestamp' into dfa-search-using-ls-…
SharafMohamed Feb 18, 2026
8d4a3a2
Fix decompression bug.
SharafMohamed Feb 19, 2026
4ecd399
Rename macro.
SharafMohamed Feb 19, 2026
47705f7
Merge branch 'main' into dfa-search-using-ls-port
SharafMohamed Feb 19, 2026
861bc37
Fix unit-tests based on previous change.
SharafMohamed Feb 19, 2026
49e3b4d
Add scoped profiler.
SharafMohamed Mar 4, 2026
810bd8f
Switch to fragmented measurements for scope profiler; Add unit-tests…
SharafMohamed Mar 5, 2026
7bd1740
Use new profiling code.
SharafMohamed Mar 5, 2026
74778c1
Combine continuous and fragmented measurements; Seperate runtime and …
SharafMohamed Mar 5, 2026
ab0da8a
Add checks for init and timer existance.
SharafMohamed Mar 5, 2026
f5b80b0
Add ProfilerReported documentation.
SharafMohamed Mar 5, 2026
4cddd71
Add unit tests; Make reset reset all runtime measurments.
SharafMohamed Mar 5, 2026
76955b6
Make sure profiler reporter is called first.
SharafMohamed Mar 5, 2026
71e780a
Remove init from runtime measurements.
SharafMohamed Mar 5, 2026
0ffb467
Finish unit-test for ProfilerReporter.
SharafMohamed Mar 6, 2026
85e92fa
Add stats to profiling.
SharafMohamed Mar 6, 2026
12554b7
Update unit-test with stats.
SharafMohamed Mar 6, 2026
5017b94
Merge branch 'main' into profiler
SharafMohamed Mar 6, 2026
96fbe97
Format.
SharafMohamed Mar 7, 2026
e5b37e0
Remove unused using.
SharafMohamed Mar 7, 2026
0131b76
Remove more unused usings.
SharafMohamed Mar 7, 2026
e970893
Format.
SharafMohamed Mar 7, 2026
027838e
Fix typo.
SharafMohamed Mar 7, 2026
f91b94b
Fix header guard.
SharafMohamed Mar 7, 2026
c2c2f41
Fix typo.
SharafMohamed Mar 7, 2026
a64478b
make stopwatch reset call count.
SharafMohamed Mar 7, 2026
d3abf6b
Typo fix.
SharafMohamed Mar 7, 2026
08f7675
Document unfreed vector.
SharafMohamed Mar 7, 2026
a8074dc
Remove unused variable.
SharafMohamed Mar 7, 2026
c7afef7
Remove ScopedProfiling if profiler disabled.
SharafMohamed Mar 7, 2026
22cf1cc
Update doc to specify init is only need for compile-time measurements.
SharafMohamed Mar 7, 2026
449d3c0
Prevent error message spam.
SharafMohamed Mar 7, 2026
5ea5af1
Indent.
SharafMohamed Mar 7, 2026
25bff02
Reword error.
SharafMohamed Mar 7, 2026
ca945de
Update unit-test tags to fix CI.
SharafMohamed Mar 7, 2026
5765cfa
Allow for disabling scopes in reporting.
SharafMohamed Mar 11, 2026
2b700ad
Update unit-test.
SharafMohamed Mar 11, 2026
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
8 changes: 7 additions & 1 deletion components/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ set(SOURCE_FILES_unitTest
src/clp/Platform.hpp
src/clp/Profiler.cpp
src/clp/Profiler.hpp
src/clp/ProfilerReporter.hpp
src/clp/Query.cpp
src/clp/Query.hpp
src/clp/QueryToken.cpp
Expand All @@ -629,6 +630,7 @@ set(SOURCE_FILES_unitTest
src/clp/ReaderInterface.hpp
src/clp/ReadOnlyMemoryMappedFile.cpp
src/clp/ReadOnlyMemoryMappedFile.hpp
src/clp/ScopedProfiler.hpp
src/clp/spdlog_with_specializations.hpp
src/clp/SQLiteDB.cpp
src/clp/SQLiteDB.hpp
Expand Down Expand Up @@ -734,9 +736,11 @@ set(SOURCE_FILES_unitTest
tests/test-MemoryMappedFile.cpp
tests/test-NetworkReader.cpp
tests/test-ParserWithUserSchema.cpp
tests/test-ProfilerReporter.cpp
tests/test-query_methods.cpp
tests/test-regex_utils.cpp
tests/test-SchemaSearcher.cpp
tests/test-ScopedProfiler.cpp
tests/test-Segment.cpp
tests/test-SQLiteDB.cpp
tests/test-Stopwatch.cpp
Expand Down Expand Up @@ -797,6 +801,8 @@ if(CLP_ENABLE_TESTS)
PRIVATE cxx_std_20
)
target_compile_definitions(unitTest
PRIVATE CLP_ENABLE_TESTS
PRIVATE
CLP_ENABLE_TESTS
PROF_TEST_ENABLED=1
)
endif()
8 changes: 3 additions & 5 deletions components/core/src/clp/Profiler.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include "Profiler.hpp"

#include <memory>

using std::unique_ptr;
using std::vector;

namespace clp {
vector<Stopwatch>* Profiler::m_fragmented_measurements = nullptr;
vector<Stopwatch>* Profiler::m_continuous_measurements = nullptr;
std::unordered_map<std::string, Stopwatch> Profiler::m_runtime_measurements;
vector<Stopwatch>* Profiler::m_compile_time_measurements = nullptr;
bool Profiler::m_initialized = false;
} // namespace clp
230 changes: 122 additions & 108 deletions components/core/src/clp/Profiler.hpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,56 @@
#ifndef CLP_PROFILER_HPP
#define CLP_PROFILER_HPP

#if defined(PROF_ENABLED) || defined(PROF_TEST_ENABLED)
#define PROF_ACTIVE 1
#else
#define PROF_ACTIVE 0
#endif

#include <array>
#include <unordered_map>
#include <vector>

#include <spdlog/spdlog.h>

#include "Stopwatch.hpp"
#include "type_utils.hpp"

namespace clp {
/**
* Class to time code.
*
* There are two types of measurements:
* - Continuous measurements where a user needs to time a single, continuous operation.
* - Fragmented measurements where a user needs to time multiple, separated instances of an
* operation. For example if we want to get the total run time taken for inserting entries into a
* dictionary, we could wrap the insertion with a fragmented measurement.
* A Measurement can be taken over a single continuous operation, or called multiple times to
* accumulate fragemented measurements into a single total run time.
*
* To add a measurement, add it to the ContinuousMeasurementIndex or FragmentedMeasurementIndex
* enums and add a corresponding enable flag to cContinuousMeasurementEnabled or
* cFragmentedMeasurementEnabled. The flags allow enabling/disabling specific measurements such that
* a disabled measurement will not affect the performance of the program (except for extra heap
* storage).
*
* To log a measurement, use LOG_CONTINUOUS_MEASUREMENT or LOG_FRAGMENTED_MEASUREMENT, passing in
* the relevant measurement index enum.
* There are two ways to add a measurement:
* 1. For measurements that are taken a small number of times use a runtime measurement.
* 2. For measurements that are in hot loops, use a compile-time measurement, such that when it is
* disabled it has zero-overhead. In this case to add a measurement, add it to the
* MeasurementIndex enum and add a corresponding enable flag to cMeasurementEnabled. The flags
* allow enabling/disabling specific measurements such that a disabled measurement will not
* affect the performance of the program (except for extra heap storage).
*
* Two implementation details allow this class to avoid inducing overhead when profiling is
* disabled:
* - All methods bodies are defined in the header, guarded by `if constexpr (PROF_ENABLED)`. When
* - All methods bodies are defined in the header, guarded by `if constexpr (PROF_ACTIVE)`. When
* profiling is disabled, the compiler will detect the empty body and won't add any code to the
* binary; if the methods were instead defined in the .cpp file, the compiler would still generate
* an empty method.
* - The methods use the measurement enum as a template parameter to indicate which measurement the
* method call is for. So at compile-time, for each measurement, the compiler can use the enable
* flag to determine whether to generate code to do the measurement or whether to do nothing.
* - The compile-time methods use the measurement enum as a template parameter to indicate which
* measurement the method call is for. So at compile-time, for each measurement, the compiler can
* use the enable flag to determine whether to generate code to do the measurement or whether to
* do nothing.
*/
class Profiler {
public:
// Types
enum class ContinuousMeasurementIndex : size_t {
Compression = 0,
ParseLogFile,
Search,
Length
};
enum class FragmentedMeasurementIndex : size_t {
enum class CompileTimeMeasurementIndex : uint8_t {
Length
};

// Constants
// NOTE: We use lambdas so that we can programmatically initialize the constexpr array
static constexpr auto cContinuousMeasurementEnabled = []() {
std::array<bool, enum_to_underlying_type(ContinuousMeasurementIndex::Length)> enabled{};
enabled[enum_to_underlying_type(ContinuousMeasurementIndex::Compression)] = true;
enabled[enum_to_underlying_type(ContinuousMeasurementIndex::ParseLogFile)] = true;
enabled[enum_to_underlying_type(ContinuousMeasurementIndex::Search)] = true;
return enabled;
}();
static constexpr auto cFragmentedMeasurementEnabled = []() {
std::array<bool, enum_to_underlying_type(FragmentedMeasurementIndex::Length)> enabled{};
static constexpr auto cMeasurementEnabled = []() {
std::array<bool, enum_to_underlying_type(CompileTimeMeasurementIndex::Length)> enabled{};
return enabled;
}();

Expand All @@ -68,110 +59,133 @@ class Profiler {
* Static initializer for class. This must be called before using the class.
*/
static void init() {
if constexpr (PROF_ENABLED) {
m_continuous_measurements = new std::vector<Stopwatch>(
enum_to_underlying_type(ContinuousMeasurementIndex::Length)
);
m_fragmented_measurements = new std::vector<Stopwatch>(
enum_to_underlying_type(FragmentedMeasurementIndex::Length)
if constexpr (PROF_ACTIVE) {
if (m_initialized) {
return;
}
m_initialized = true;
m_compile_time_measurements = new std::vector<Stopwatch>(
enum_to_underlying_type(CompileTimeMeasurementIndex::Length)
);
}
}

template <ContinuousMeasurementIndex index>
static void start_continuous_measurement() {
if constexpr (PROF_ENABLED && cContinuousMeasurementEnabled[enum_to_underlying_type(index)])
{
auto& stopwatch = (*m_continuous_measurements)[enum_to_underlying_type(index)];
stopwatch.reset();
stopwatch.start();
static auto check_init() -> bool {
if constexpr (PROF_ACTIVE) {
if (false == m_initialized) {
SPDLOG_ERROR("Profiler used without calling Profiler::init()");
}
return m_initialized;
}
return false;
}

template <ContinuousMeasurementIndex index>
static void stop_continuous_measurement() {
if constexpr (PROF_ENABLED && cContinuousMeasurementEnabled[enum_to_underlying_type(index)])
{
(*m_continuous_measurements)[enum_to_underlying_type(index)].stop();
static auto check_runtime_timer_exists(std::string const& name) -> bool {
if constexpr (PROF_ACTIVE) {
if (false == m_runtime_measurements.contains(name)) {
SPDLOG_ERROR("Attempt to get runtime measurment of non existent timer {}", name);
return false;
}
return true;
}
return false;
}

template <ContinuousMeasurementIndex index>
static double get_continuous_measurement_in_seconds() {
if constexpr (PROF_ENABLED) {
return (*m_continuous_measurements)[enum_to_underlying_type(index)]
.get_time_taken_in_seconds();
static auto start_runtime_measurement(std::string const& name) -> void {
if constexpr (PROF_ACTIVE) {
// implicitly creates the timer if it doesn't exist yet
m_runtime_measurements[name].start();
}
}

static auto stop_runtime_measurement(std::string const& name) -> void {
if constexpr (PROF_ACTIVE) {
if (false == check_runtime_timer_exists(name)) {
return;
}
m_runtime_measurements[name].stop();
}
}

static auto reset_runtime_measurements() -> void {
if constexpr (PROF_ACTIVE) {
m_runtime_measurements.clear();
}
}

static auto get_runtime_measurement_in_seconds(std::string const& name) -> double {
if constexpr (PROF_ACTIVE) {
if (false == check_runtime_timer_exists(name)) {
return 0;
}
return m_runtime_measurements[name].get_time_taken_in_seconds();
} else {
return 0;
}
}

template <FragmentedMeasurementIndex index>
static void start_fragmented_measurement() {
if constexpr (PROF_ENABLED && cFragmentedMeasurementEnabled[enum_to_underlying_type(index)])
{
(*m_fragmented_measurements)[enum_to_underlying_type(index)].start();
static auto get_runtime_call_count(std::string const& name) -> uint32_t {
if constexpr (PROF_ACTIVE) {
if (false == check_runtime_timer_exists(name)) {
return 0;
}
return m_runtime_measurements[name].get_call_count();
} else {
return 0;
}
}

template <FragmentedMeasurementIndex index>
static void stop_fragmented_measurement() {
if constexpr (PROF_ENABLED && cFragmentedMeasurementEnabled[enum_to_underlying_type(index)])
{
(*m_fragmented_measurements)[enum_to_underlying_type(index)].stop();
static auto get_runtime_measurements() -> std::unordered_map<std::string, Stopwatch> const& {
return m_runtime_measurements;
}

template <CompileTimeMeasurementIndex index>
static auto start_compile_time_measurement() -> void {
if constexpr (PROF_ACTIVE && cMeasurementEnabled[enum_to_underlying_type(index)]) {
if (false == check_init()) {
return;
}
(*m_compile_time_measurements)[enum_to_underlying_type(index)].start();
}
}

template <FragmentedMeasurementIndex index>
static void reset_fragmented_measurement() {
if constexpr (PROF_ENABLED && cFragmentedMeasurementEnabled[enum_to_underlying_type(index)])
{
(*m_fragmented_measurements)[enum_to_underlying_type(index)].reset();
template <CompileTimeMeasurementIndex index>
static auto stop_compile_time_measurement() -> void {
if constexpr (PROF_ACTIVE && cMeasurementEnabled[enum_to_underlying_type(index)]) {
if (false == check_init()) {
return;
}
(*m_compile_time_measurements)[enum_to_underlying_type(index)].stop();
}
}

template <FragmentedMeasurementIndex index>
static double get_fragmented_measurement_in_seconds() {
if constexpr (PROF_ENABLED) {
return (*m_fragmented_measurements)[enum_to_underlying_type(index)]
template <CompileTimeMeasurementIndex index>
static auto reset_compile_time_measurement() -> void {
if constexpr (PROF_ACTIVE && cMeasurementEnabled[enum_to_underlying_type(index)]) {
if (false == check_init()) {
return;
}
(*m_compile_time_measurements)[enum_to_underlying_type(index)].reset();
}
}

template <CompileTimeMeasurementIndex index>
static auto get_compile_time_measurement_in_seconds() -> double {
if constexpr (PROF_ACTIVE && cMeasurementEnabled[enum_to_underlying_type(index)]) {
if (false == check_init()) {
return 0;
}
return (*m_compile_time_measurements)[enum_to_underlying_type(index)]
.get_time_taken_in_seconds();
} else {
return 0;
}
}

private:
static std::vector<Stopwatch>* m_fragmented_measurements;
static std::vector<Stopwatch>* m_continuous_measurements;
static std::unordered_map<std::string, Stopwatch> m_runtime_measurements;
static std::vector<Stopwatch>* m_compile_time_measurements;
static bool m_initialized;
};
} // namespace clp

// Macros to log the measurements
// NOTE: We use macros so that we can add the measurement index to the log (not easy to do with
// templates).
#define LOG_CONTINUOUS_MEASUREMENT(x) \
if (PROF_ENABLED \
&& ::clp::Profiler::cContinuousMeasurementEnabled[enum_to_underlying_type(x)]) \
{ \
SPDLOG_INFO( \
"{} took {} s", \
#x, \
::clp::Profiler::get_continuous_measurement_in_seconds<x>() \
); \
}
#define LOG_FRAGMENTED_MEASUREMENT(x) \
if (PROF_ENABLED \
&& ::clp::Profiler::cFragmentedMeasurementEnabled[enum_to_underlying_type(x)]) \
{ \
SPDLOG_INFO( \
"{} took {} s", \
#x, \
::clp::Profiler::get_fragmented_measurement_in_seconds<x>() \
); \
}
#define PROFILER_SPDLOG_INFO(...) \
if (PROF_ENABLED) { \
SPDLOG_INFO(__VA_ARGS__); \
}

#endif // CLP_PROFILER_HPP
Loading
Loading