Revert unrelated changes & performance optimisation

Signed-off-by: JCW <a1q123456@users.noreply.github.com>
This commit is contained in:
JCW
2025-09-08 16:40:34 +01:00
parent de6ff088a7
commit 7c2832161c
13 changed files with 93 additions and 101 deletions

View File

@@ -71,10 +71,10 @@ private:
operator=(Sink const&) = delete;
void
write(beast::severities::Severity level, std::string&& text) override;
write(beast::severities::Severity level, std::string_view text) override;
void
writeAlways(beast::severities::Severity level, std::string&& text)
writeAlways(beast::severities::Severity level, std::string_view text)
override;
};
@@ -205,7 +205,7 @@ public:
write(
beast::severities::Severity level,
std::string const& partition,
std::string const& text,
std::string_view text,
bool console);
std::string
@@ -246,7 +246,7 @@ public:
static void
format(
std::string& output,
std::string const& message,
std::string_view message,
beast::severities::Severity severity,
std::string const& partition);

View File

@@ -366,7 +366,7 @@ private:
severities::Severity severity) const;
static std::string_view
formatLog(std::string&& message);
formatLog(std::string const& message);
public:
//--------------------------------------------------------------------------
@@ -420,7 +420,7 @@ public:
level is below the current threshold().
*/
virtual void
write(Severity level, std::string&& text) = 0;
write(Severity level, std::string_view text) = 0;
/** Bypass filter and write text to the sink at the specified severity.
* Always write the message, but maintain the same formatting as if
@@ -430,7 +430,7 @@ public:
* @param text Text to write to sink.
*/
virtual void
writeAlways(Severity level, std::string&& text) = 0;
writeAlways(Severity level, std::string_view text) = 0;
private:
Severity thresh_;

View File

@@ -88,17 +88,17 @@ public:
}
void
write(beast::severities::Severity level, std::string&& text) override
write(beast::severities::Severity level, std::string_view text) override
{
using beast::Journal;
sink_.write(level, prefix_ + text);
sink_.write(level, prefix_ + std::string{text});
}
void
writeAlways(severities::Severity level, std::string&& text) override
writeAlways(severities::Severity level, std::string_view text) override
{
using beast::Journal;
sink_.writeAlways(level, prefix_ + text);
sink_.writeAlways(level, prefix_ + std::string{text});
}
};

View File

@@ -132,8 +132,7 @@ public:
}
}
JLOG(m_journal.debug())
<< "New inbound endpoint " << log::param("Entry", *entry);
JLOG(m_journal.debug()) << "New inbound endpoint " << *entry;
return Consumer(*this, *entry);
}
@@ -161,8 +160,7 @@ public:
}
}
JLOG(m_journal.debug())
<< "New outbound endpoint " << log::param("Entry", *entry);
JLOG(m_journal.debug()) << "New outbound endpoint " << *entry;
return Consumer(*this, *entry);
}
@@ -195,8 +193,7 @@ public:
}
}
JLOG(m_journal.debug())
<< "New unlimited endpoint " << log::param("Entry", *entry);
JLOG(m_journal.debug()) << "New unlimited endpoint " << *entry;
return Consumer(*this, *entry);
}
@@ -353,8 +350,7 @@ public:
{
if (iter->whenExpires <= elapsed)
{
JLOG(m_journal.debug())
<< "Expired " << log::param("Entry", *iter);
JLOG(m_journal.debug()) << "Expired " << *iter;
auto table_iter = table_.find(*iter->key);
++iter;
erase(table_iter);
@@ -426,9 +422,7 @@ public:
std::lock_guard _(lock_);
if (--entry.refcount == 0)
{
JLOG(m_journal.debug())
<< "Inactive " << log::param("Entry", entry);
;
JLOG(m_journal.debug()) << "Inactive " << entry;
switch (entry.key->kind)
{
@@ -480,8 +474,7 @@ public:
clock_type::time_point const now(m_clock.now());
int const balance(entry.add(fee.cost(), now));
JLOG(getStream(fee.cost(), m_journal))
<< "Charging " << log::param("Entry", entry) << " for "
<< log::param("Fee", fee) << context;
<< "Charging " << entry << " for " << fee << context;
return disposition(balance);
}
@@ -503,9 +496,7 @@ public:
}
if (notify)
{
JLOG(m_journal.info())
<< "Load warning: " << log::param("Entry", entry);
;
JLOG(m_journal.info()) << "Load warning: " << entry;
++m_stats.warn;
}
return notify;
@@ -524,10 +515,8 @@ public:
if (balance >= dropThreshold)
{
JLOG(m_journal.warn())
<< "Consumer entry " << log::param("Entry", entry)
<< " dropped with balance " << log::param("Entry", balance)
<< " at or above drop threshold "
<< log::param("Entry", dropThreshold);
<< "Consumer entry " << entry << " dropped with balance "
<< balance << " at or above drop threshold " << dropThreshold;
// Adding feeDrop at this point keeps the dropped connection
// from re-connecting for at least a little while after it is

View File

@@ -52,18 +52,18 @@ Logs::Sink::Sink(
}
void
Logs::Sink::write(beast::severities::Severity level, std::string&& text)
Logs::Sink::write(beast::severities::Severity level, std::string_view text)
{
if (level < threshold())
return;
logs_.write(level, partition_, std::move(text), console());
logs_.write(level, partition_, text, console());
}
void
Logs::Sink::writeAlways(beast::severities::Severity level, std::string&& text)
Logs::Sink::writeAlways(beast::severities::Severity level, std::string_view text)
{
logs_.write(level, partition_, std::move(text), console());
logs_.write(level, partition_, text, console());
}
//------------------------------------------------------------------------------
@@ -190,21 +190,26 @@ void
Logs::write(
beast::severities::Severity level,
std::string const& partition,
std::string const& text,
std::string_view text,
bool console)
{
std::string s;
format(s, text, level, partition);
std::string_view result = text;
if (!beast::Journal::isStructuredJournalEnabled())
{
format(s, text, level, partition);
result = s;
}
// Console output still immediate for responsiveness
if (!silent_)
std::cerr << s << '\n';
std::cerr << result << '\n';
// Add to batch buffer for file output
{
std::lock_guard lock(batchMutex_);
size_t logSize = s.size() + 1; // +1 for newline
size_t logSize = result.size() + 1; // +1 for newline
// If log won't fit in current write buffer, flush first
if (logSize > writeBuffer_.size())
@@ -213,8 +218,8 @@ Logs::write(
}
// Copy log into write buffer
std::copy(s.begin(), s.end(), writeBuffer_.begin());
writeBuffer_[s.size()] = '\n';
std::copy(result.begin(), result.end(), writeBuffer_.begin());
writeBuffer_[result.size()] = '\n';
// Update spans: expand read buffer, shrink write buffer
size_t totalUsed = readBuffer_.size() + logSize;
@@ -378,47 +383,45 @@ Logs::fromString(std::string const& s)
void
Logs::format(
std::string& output,
std::string const& message,
std::string_view message,
beast::severities::Severity severity,
std::string const& partition)
{
output = message;
if (!beast::Journal::isStructuredJournalEnabled())
output.reserve(output.size() + partition.size() + 100);
output += to_string(std::chrono::system_clock::now());
output += " ";
if (!partition.empty())
output += partition + ":";
using namespace beast::severities;
switch (severity)
{
output.reserve(output.size() + partition.size() + 100);
output += to_string(std::chrono::system_clock::now());
output += " ";
if (!partition.empty())
output += partition + ":";
using namespace beast::severities;
switch (severity)
{
case kTrace:
output += "TRC ";
break;
case kDebug:
output += "DBG ";
break;
case kInfo:
output += "NFO ";
break;
case kWarning:
output += "WRN ";
break;
case kError:
output += "ERR ";
break;
default:
UNREACHABLE("ripple::Logs::format : invalid severity");
[[fallthrough]];
case kFatal:
output += "FTL ";
break;
}
case kTrace:
output += "TRC ";
break;
case kDebug:
output += "DBG ";
break;
case kInfo:
output += "NFO ";
break;
case kWarning:
output += "WRN ";
break;
case kError:
output += "ERR ";
break;
default:
UNREACHABLE("ripple::Logs::format : invalid severity");
[[fallthrough]];
case kFatal:
output += "FTL ";
break;
}
// Limit the maximum length of the output
if (output.size() > maximumMessageCharacters)
{

View File

@@ -156,12 +156,12 @@ public:
}
void
write(severities::Severity, std::string&&) override
write(severities::Severity, std::string_view) override
{
}
void
writeAlways(severities::Severity, std::string&&) override
writeAlways(severities::Severity, std::string_view) override
{
}
};
@@ -293,7 +293,7 @@ Journal::initMessageContext(
}
std::string_view
Journal::formatLog(std::string&& message)
Journal::formatLog(std::string const& message)
{
if (!m_jsonLogsEnabled)
{
@@ -391,9 +391,9 @@ Journal::ScopedStream::~ScopedStream()
if (!s.empty())
{
if (s == "\n")
m_sink.write(m_level, std::string{formatLog("")});
m_sink.write(m_level, formatLog(""));
else
m_sink.write(m_level, std::string{formatLog(std::move(s))});
m_sink.write(m_level, formatLog(s));
}
}

View File

@@ -48,14 +48,14 @@ public:
}
void
write(severities::Severity level, std::string&&) override
write(severities::Severity level, std::string_view) override
{
if (level >= threshold())
++m_count;
}
void
writeAlways(severities::Severity level, std::string&&) override
writeAlways(severities::Severity level, std::string_view) override
{
++m_count;
}

View File

@@ -49,7 +49,7 @@ public:
}
void
write(beast::severities::Severity level, std::string&& text) override
write(beast::severities::Severity level, std::string_view text) override
{
if (level < threshold())
return;
@@ -59,7 +59,7 @@ public:
}
void
writeAlways(beast::severities::Severity level, std::string&& text) override
writeAlways(beast::severities::Severity level, std::string_view text) override
{
std::cout << clock_.now().time_since_epoch().count() << " " << text
<< std::endl;

View File

@@ -57,14 +57,14 @@ class CaptureLogs : public Logs
}
void
write(beast::severities::Severity level, std::string&& text) override
write(beast::severities::Severity level, std::string_view text) override
{
std::lock_guard lock(strmMutex_);
strm_ << text;
}
void
writeAlways(beast::severities::Severity level, std::string&& text)
writeAlways(beast::severities::Severity level, std::string_view text)
override
{
std::lock_guard lock(strmMutex_);

View File

@@ -45,14 +45,14 @@ class CheckMessageLogs : public Logs
}
void
write(beast::severities::Severity level, std::string&& text) override
write(beast::severities::Severity level, std::string_view text) override
{
if (text.find(owner_.msg_) != std::string::npos)
*owner_.pFound_ = true;
}
void
writeAlways(beast::severities::Severity level, std::string&& text)
writeAlways(beast::severities::Severity level, std::string_view text)
override
{
write(level, std::move(text));

View File

@@ -89,7 +89,7 @@ public:
}
void
write(beast::severities::Severity level, std::string&& text) override
write(beast::severities::Severity level, std::string_view text) override
{
if (level < threshold())
return;
@@ -98,7 +98,7 @@ public:
}
void
writeAlways(beast::severities::Severity level, std::string&& text)
writeAlways(beast::severities::Severity level, std::string_view text)
override
{
suite_.log << text << std::endl;

View File

@@ -49,14 +49,14 @@ public:
}
void
write(beast::severities::Severity level, std::string&& text) override;
write(beast::severities::Severity level, std::string_view text) override;
void
writeAlways(beast::severities::Severity level, std::string&& text) override;
writeAlways(beast::severities::Severity level, std::string_view text) override;
};
inline void
SuiteJournalSink::write(beast::severities::Severity level, std::string&& text)
SuiteJournalSink::write(beast::severities::Severity level, std::string_view text)
{
// Only write the string if the level at least equals the threshold.
if (level >= threshold())
@@ -66,7 +66,7 @@ SuiteJournalSink::write(beast::severities::Severity level, std::string&& text)
inline void
SuiteJournalSink::writeAlways(
beast::severities::Severity level,
std::string&& text)
std::string_view text)
{
using namespace beast::severities;
@@ -134,7 +134,7 @@ public:
}
void
write(beast::severities::Severity level, std::string&& text) override
write(beast::severities::Severity level, std::string_view text) override
{
if (level < threshold())
return;
@@ -142,7 +142,7 @@ public:
}
inline void
writeAlways(beast::severities::Severity level, std::string&& text) override
writeAlways(beast::severities::Severity level, std::string_view text) override
{
strm_ << text << std::endl;
}

View File

@@ -53,13 +53,13 @@ private:
operator=(Sink const&) = delete;
void
write(beast::severities::Severity level, std::string&& text) override
write(beast::severities::Severity level, std::string_view text) override
{
logs_.write(level, partition_, text, false);
}
void
writeAlways(beast::severities::Severity level, std::string&& text)
writeAlways(beast::severities::Severity level, std::string_view text)
override
{
logs_.write(level, partition_, text, false);
@@ -86,7 +86,7 @@ public:
write(
beast::severities::Severity level,
std::string const& partition,
std::string const& text,
std::string_view text,
bool console)
{
std::string s;
@@ -365,13 +365,13 @@ public:
}
void
write(beast::severities::Severity level, std::string&& text) override
write(beast::severities::Severity level, std::string_view text) override
{
strm_ << text;
}
void
writeAlways(beast::severities::Severity level, std::string&& text) override
writeAlways(beast::severities::Severity level, std::string_view text) override
{
strm_ << text;
}