-
Notifications
You must be signed in to change notification settings - Fork 979
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1766 from marta-lokhova/extra_logging
Log time it takes to resolve a bucket Reviewed-by: MonsieurNicolas
- Loading branch information
Showing
5 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2018 Stellar Development Foundation and contributors. Licensed | ||
// under the Apache License, Version 2.0. See the COPYING file at the root | ||
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
#pragma once | ||
|
||
#include "util/Logging.h" | ||
#include <chrono> | ||
|
||
class LogSlowExecution | ||
{ | ||
|
||
std::chrono::system_clock::time_point mStart; | ||
std::string mName; | ||
int mThresholdInMs; | ||
|
||
public: | ||
LogSlowExecution(std::string eventName, int ms = 1000) | ||
: mStart(std::chrono::system_clock::now()) | ||
, mName(std::move(eventName)) | ||
, mThresholdInMs(ms){}; | ||
|
||
~LogSlowExecution() | ||
{ | ||
auto finish = std::chrono::system_clock::now(); | ||
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>( | ||
finish - mStart); | ||
auto tooSlow = elapsed.count() > mThresholdInMs; | ||
|
||
LOG_IF(tooSlow, INFO) | ||
<< mName << " hung for " | ||
<< static_cast<float>(elapsed.count()) / 1000 << " s"; | ||
} | ||
}; |