Skip to content

Commit acafed7

Browse files
committed
Performance test
Signed-off-by: JCW <[email protected]>
1 parent 4feaa7b commit acafed7

File tree

13 files changed

+300
-334
lines changed

13 files changed

+300
-334
lines changed

include/xrpl/basics/Log.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <boost/beast/core/string.hpp>
2727
#include <boost/filesystem.hpp>
2828

29+
#include <boost/lockfree/queue.hpp>
30+
2931
#include <array>
3032
#include <atomic>
3133
#include <chrono>
@@ -74,10 +76,10 @@ class Logs
7476
operator=(Sink const&) = delete;
7577

7678
void
77-
write(beast::severities::Severity level, std::string_view text, beast::Journal::MessagePoolNode owner = nullptr) override;
79+
write(beast::severities::Severity level, beast::Journal::StringBuffer text) override;
7880

7981
void
80-
writeAlways(beast::severities::Severity level, std::string_view text, beast::Journal::MessagePoolNode owner = nullptr)
82+
writeAlways(beast::severities::Severity level, beast::Journal::StringBuffer text)
8183
override;
8284
};
8385

@@ -135,7 +137,7 @@ class Logs
135137
Does nothing if there is no associated system file.
136138
*/
137139
void
138-
write(std::string&& str);
140+
write(std::string const& str);
139141

140142
/** @} */
141143

@@ -156,7 +158,7 @@ class Logs
156158

157159
// Batching members
158160
mutable std::mutex batchMutex_;
159-
beast::lockfree::queue<std::string> messages_;
161+
boost::lockfree::queue<beast::Journal::StringBuffer, boost::lockfree::capacity<100>> messages_;
160162
static constexpr size_t BATCH_BUFFER_SIZE = 64 * 1024; // 64KB buffer
161163
std::array<char, BATCH_BUFFER_SIZE> batchBuffer_{};
162164
std::span<char> writeBuffer_; // Points to available write space
@@ -217,8 +219,7 @@ class Logs
217219
write(
218220
beast::severities::Severity level,
219221
std::string const& partition,
220-
std::string_view text,
221-
beast::Journal::MessagePoolNode owner,
222+
beast::Journal::StringBuffer text,
222223
bool console);
223224

224225
std::string
@@ -280,12 +281,16 @@ class Logs
280281
// Wraps a Journal::Stream to skip evaluation of
281282
// expensive argument lists if the stream is not active.
282283
#ifndef JLOG
284+
#define JLOG_JOIN_(a,b) a##b
285+
#define JLOG_JOIN(a,b) JLOG_JOIN_(a,b)
286+
#define JLOG_UNIQUE(base) JLOG_JOIN(base, __LINE__) // line-based unique name
287+
283288
#define JLOG(x) \
284-
if (!x) \
285-
{ \
286-
} \
287-
else \
288-
x
289+
if (auto JLOG_UNIQUE(stream) = (x); !JLOG_UNIQUE(stream)) \
290+
{ \
291+
} \
292+
else \
293+
JLOG_UNIQUE(stream)
289294
#endif
290295

291296
#ifndef CLOG

0 commit comments

Comments
 (0)