Skip to content

Commit 39a34b6

Browse files
committed
Put lock logging behind DEBUG_LOCKCONTENTION preprocessor directive
1 parent 7ab9fc3 commit 39a34b6

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-6
lines changed

src/logging.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ const CLogCategoryDesc LogCategories[] =
160160
{BCLog::VALIDATION, "validation"},
161161
{BCLog::I2P, "i2p"},
162162
{BCLog::IPC, "ipc"},
163+
#ifdef DEBUG_LOCKCONTENTION
163164
{BCLog::LOCK, "lock"},
165+
#endif
164166
{BCLog::UTIL, "util"},
165167
{BCLog::BLOCKSTORE, "blockstorage"},
166168
{BCLog::ALL, "1"},

src/logging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ namespace BCLog {
6060
VALIDATION = (1 << 21),
6161
I2P = (1 << 22),
6262
IPC = (1 << 23),
63+
#ifdef DEBUG_LOCKCONTENTION
6364
LOCK = (1 << 24),
65+
#endif
6466
UTIL = (1 << 25),
6567
BLOCKSTORE = (1 << 26),
6668
ALL = ~(uint32_t)0,

src/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <crypto/siphash.h>
1414
#include <hash.h>
1515
#include <i2p.h>
16+
#include <logging.h>
1617
#include <net_permissions.h>
1718
#include <netaddress.h>
1819
#include <netbase.h>
@@ -32,6 +33,7 @@
3233
#include <cstdint>
3334
#include <deque>
3435
#include <functional>
36+
#include <list>
3537
#include <map>
3638
#include <memory>
3739
#include <optional>

src/sync.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
#ifndef BITCOIN_SYNC_H
77
#define BITCOIN_SYNC_H
88

9+
#ifdef DEBUG_LOCKCONTENTION
910
#include <logging.h>
1011
#include <logging/timer.h>
12+
#endif
13+
1114
#include <threadsafety.h>
1215
#include <util/macros.h>
1316

@@ -136,8 +139,10 @@ class SCOPED_LOCKABLE UniqueLock : public Base
136139
void Enter(const char* pszName, const char* pszFile, int nLine)
137140
{
138141
EnterCritical(pszName, pszFile, nLine, Base::mutex());
142+
#ifdef DEBUG_LOCKCONTENTION
139143
if (Base::try_lock()) return;
140144
LOG_TIME_MICROS_WITH_CATEGORY(strprintf("lock contention %s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
145+
#endif
141146
Base::lock();
142147
}
143148

src/test/checkqueue_tests.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919
#include <vector>
2020

2121
/**
22-
* Identical to TestingSetup but excludes lock contention logging, as some of
23-
* these tests are designed to be heavily contested to trigger race conditions
24-
* or other issues.
22+
* Identical to TestingSetup but excludes lock contention logging if
23+
* `DEBUG_LOCKCONTENTION` is defined, as some of these tests are designed to be
24+
* heavily contested to trigger race conditions or other issues.
2525
*/
2626
struct NoLockLoggingTestingSetup : public TestingSetup {
2727
NoLockLoggingTestingSetup()
28+
#ifdef DEBUG_LOCKCONTENTION
2829
: TestingSetup{CBaseChainParams::MAIN, /*extra_args=*/{"-debugexclude=lock"}} {}
30+
#else
31+
: TestingSetup{CBaseChainParams::MAIN} {}
32+
#endif
2933
};
3034

3135
BOOST_FIXTURE_TEST_SUITE(checkqueue_tests, NoLockLoggingTestingSetup)

test/functional/rpc_misc.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ def run_test(self):
5656

5757
self.log.info("test logging rpc and help")
5858

59-
# Test logging RPC returns the expected number of logging categories.
60-
assert_equal(len(node.logging()), 27)
61-
6259
# Test toggling a logging category on/off/on with the logging RPC.
6360
assert_equal(node.logging()['qt'], True)
6461
node.logging(exclude=['qt'])

0 commit comments

Comments
 (0)