Skip to content

Commit 0829a25

Browse files
author
Thomas Brady
committed
Add params to configure logging semantics of LogSlowExecution, add LogSlowExecution for bucket merges longer than 2 minutes
1 parent 55ec348 commit 0829a25

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/bucket/FutureBucket.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,10 @@ FutureBucket::startMerge(Application& app, uint32_t maxProtocolVersion,
353353
std::shared_ptr<task_t> task = std::make_shared<task_t>(
354354
[curr, snap, &bm, shadows, maxProtocolVersion, countMergeEvents, level,
355355
&timer, &ctx, doFsync, availableTime]() mutable {
356-
auto timeScope = timer.TimeScope();
356+
auto timeScope = LogSlowExecution(
357+
"Bucket merge", LogSlowExecution::Mode::AUTOMATIC_RAII, "took",
358+
std::chrono::seconds(120), /*warnOnThreshold=*/true,
359+
/*logEveryExecution=*/true);
357360
CLOG_TRACE(Bucket, "Worker merging curr={} with snap={}",
358361
hexAbbrev(curr->getHash()), hexAbbrev(snap->getHash()));
359362

@@ -372,14 +375,6 @@ FutureBucket::startMerge(Application& app, uint32_t maxProtocolVersion,
372375
CLOG_TRACE(
373376
Bucket, "Worker finished merging curr={} with snap={}",
374377
hexAbbrev(curr->getHash()), hexAbbrev(snap->getHash()));
375-
376-
std::chrono::duration<double> time(timeScope.Stop());
377-
double timePct = time.count() / availableTime.count() * 100;
378-
CLOG_DEBUG(
379-
Perf,
380-
"Bucket merge on level {} finished in {} seconds "
381-
"({}% of available time)",
382-
level, time.count(), timePct);
383378
}
384379

385380
return res;

src/util/LogSlowExecution.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ namespace stellar
2222
{
2323
LogSlowExecution::LogSlowExecution(std::string eventName, Mode mode,
2424
std::string message,
25-
std::chrono::milliseconds threshold)
25+
std::chrono::milliseconds threshold,
26+
bool warnOnThreshold, bool logEveryExecution)
2627
: mStart(std::chrono::system_clock::now())
2728
, mName(std::move(eventName))
2829
, mMode(mode)
2930
, mMessage(std::move(message))
30-
, mThreshold(threshold){};
31+
, mThreshold(threshold)
32+
, mWarnOnThreshold(warnOnThreshold)
33+
, mLogEveryExecution(logEveryExecution){};
3134

3235
LogSlowExecution::~LogSlowExecution()
3336
{
@@ -44,13 +47,15 @@ LogSlowExecution::checkElapsedTime() const
4447
auto elapsed =
4548
std::chrono::duration_cast<std::chrono::milliseconds>(finish - mStart);
4649

47-
if (!mThreshold.count() || elapsed > mThreshold)
50+
if (!mThreshold.count() || elapsed > mThreshold || mLogEveryExecution)
4851
{
4952
std::lock_guard<std::mutex> guard(gLogSlowExecMutex);
5053

5154
// Check whether we're 10 times over the threshold to decide the log
52-
// level.
53-
LogLevel ll = (elapsed > mThreshold * 10 || !mThreshold.count())
55+
// level. If warnOnThreshold is set, log as warning if we're over the
56+
// threshold.
57+
LogLevel ll = (elapsed > mThreshold * 10 || !mThreshold.count() ||
58+
(elapsed > mThreshold && mWarnOnThreshold))
5459
? LogLevel::LVL_WARNING
5560
: LogLevel::LVL_DEBUG;
5661

src/util/LogSlowExecution.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class LogSlowExecution
2222
LogSlowExecution(
2323
std::string eventName, Mode mode = Mode::AUTOMATIC_RAII,
2424
std::string message = "took",
25-
std::chrono::milliseconds threshold = std::chrono::seconds(1));
25+
std::chrono::milliseconds threshold = std::chrono::seconds(1),
26+
bool warnOnThreshold = false, bool logEveryExecution = false);
2627
~LogSlowExecution();
2728
std::chrono::milliseconds checkElapsedTime() const;
2829

@@ -32,6 +33,8 @@ class LogSlowExecution
3233
Mode mMode;
3334
std::string mMessage;
3435
std::chrono::milliseconds mThreshold;
36+
bool mWarnOnThreshold;
37+
bool mLogEveryExecution;
3538
};
3639

3740
// Helper class to emit rate-limited log messages without any threshold

0 commit comments

Comments
 (0)