Skip to content

Commit 916ae34

Browse files
committed
Revert "Remove disabled option"
This reverts commit 9ec37aa.
1 parent 9ec37aa commit 916ae34

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

include/glaze/trace/trace.hpp

+21
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,37 @@ namespace glz
6262

6363
std::optional<std::chrono::time_point<std::chrono::steady_clock>> t0{}; // the time of the first event
6464

65+
std::atomic<bool> disabled = false;
6566
std::mutex mtx{};
6667

6768
template <class... Args>
6869
requires(sizeof...(Args) <= 1)
6970
void begin(const std::string_view name, Args&&... args) noexcept
7071
{
72+
if (disabled) {
73+
return;
74+
}
7175
duration(name, 'B', std::forward<Args>(args)...);
7276
}
7377

7478
template <class... Args>
7579
requires(sizeof...(Args) <= 1)
7680
void end(const std::string_view name, Args&&... args) noexcept
7781
{
82+
if (disabled) {
83+
return;
84+
}
7885
duration(name, 'E', std::forward<Args>(args)...);
7986
}
8087

8188
template <class... Args>
8289
requires(sizeof...(Args) <= 1)
8390
void duration(const std::string_view name, const char phase, Args&&... args) noexcept
8491
{
92+
if (disabled) {
93+
return;
94+
}
95+
8596
const auto tnow = std::chrono::steady_clock::now();
8697
trace_event* event{};
8798
{
@@ -104,20 +115,30 @@ namespace glz
104115
requires(sizeof...(Args) <= 1)
105116
void async_begin(const std::string_view name, Args&&... args) noexcept
106117
{
118+
if (disabled) {
119+
return;
120+
}
107121
async(name, 'b', std::forward<Args>(args)...);
108122
}
109123

110124
template <class... Args>
111125
requires(sizeof...(Args) <= 1)
112126
void async_end(const std::string_view name, Args&&... args) noexcept
113127
{
128+
if (disabled) {
129+
return;
130+
}
114131
async(name, 'e', std::forward<Args>(args)...);
115132
}
116133

117134
template <class... Args>
118135
requires(sizeof...(Args) <= 1)
119136
void async(const std::string_view name, const char phase, Args&&... args) noexcept
120137
{
138+
if (disabled) {
139+
return;
140+
}
141+
121142
const auto tnow = std::chrono::steady_clock::now();
122143
trace_event* event{};
123144
{

0 commit comments

Comments
 (0)