Skip to content

Commit 9b08006

Browse files
jonatackhebastopracticalswift
committed
log, sync: improve lock contention logging and add time duration
in microseconds. Change the function name in order to print "LockContention" instead of "PrintLockContention" to the log. Add Doxygen documentation. With this change, the lock contention log prints: 2021-09-01T11:29:03Z LockContention: pnode->cs_vSend, net.cpp:1373 started 2021-09-01T11:29:03Z LockContention: pnode->cs_vSend, net.cpp:1373 completed (31μs) 2021-09-01T11:29:03Z LockContention: cs_vNodes, net.cpp:2277 started 2021-09-01T11:29:03Z LockContention: cs_vNodes, net.cpp:2277 completed (6μs) 2021-09-01T11:29:04Z LockContention: cs_vNodes, net.cpp:2242 started 2021-09-01T11:29:04Z LockContention: cs_vNodes, net.cpp:2242 completed (3μs) Co-authored-by: Hennadii Stepanov <[email protected]> Co-authored-by: practicalswift <[email protected]>
1 parent 3f4c6b8 commit 9b08006

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/sync.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <sync.h>
1010

1111
#include <logging.h>
12+
#include <logging/timer.h>
1213
#include <tinyformat.h>
1314
#include <util/strencodings.h>
1415
#include <util/threadnames.h>
@@ -27,10 +28,9 @@
2728
#if !defined(HAVE_THREAD_LOCAL)
2829
static_assert(false, "thread_local is not supported");
2930
#endif
30-
void PrintLockContention(const char* pszName, const char* pszFile, int nLine)
31+
void LockContention(const char* pszName, const char* pszFile, int nLine)
3132
{
32-
LogPrint(BCLog::LOCK, "LOCKCONTENTION: %s\n", pszName);
33-
LogPrint(BCLog::LOCK, "Locker: %s:%d\n", pszFile, nLine);
33+
LOG_TIME_MICROS_WITH_CATEGORY(strprintf("%s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
3434
}
3535
#endif /* DEBUG_LOCKCONTENTION */
3636

src/sync.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
127127
typedef AnnotatedMixin<std::mutex> Mutex;
128128

129129
#ifdef DEBUG_LOCKCONTENTION
130-
void PrintLockContention(const char* pszName, const char* pszFile, int nLine);
130+
/** Prints a lock contention to the log */
131+
void LockContention(const char* pszName, const char* pszFile, int nLine);
131132
#endif
132133

133134
/** Wrapper around std::unique_lock style lock for Mutex. */
@@ -140,7 +141,7 @@ class SCOPED_LOCKABLE UniqueLock : public Base
140141
EnterCritical(pszName, pszFile, nLine, Base::mutex());
141142
#ifdef DEBUG_LOCKCONTENTION
142143
if (!Base::try_lock()) {
143-
PrintLockContention(pszName, pszFile, nLine);
144+
LockContention(pszName, pszFile, nLine); // log the contention
144145
#endif
145146
Base::lock();
146147
#ifdef DEBUG_LOCKCONTENTION

0 commit comments

Comments
 (0)