To enable lock contention logging, DEBUG_LOCKCONTENTION
has to be defined at compilation. Once built, the logging is not limited to a category and is high frequency, verbose and in all-caps. With these factors combined, it seems likely to be rarely used.
This patch:
- adds a
lock
logging category - adds a timing macro in microseconds,
LOG_TIME_MICROS_WITH_CATEGORY
- updates
BCLog::LogMsg()
to omit irrelevant decimals for microseconds and skip unneeded code and math - improves the lock contention logging, drops the all-caps, and displays the duration in microseconds
- removes the conditional compilation directives
- allows lock contentions to be logged on startup with
-debug=lock
or at run time withbitcoin-cli logging '["lock"]'
0$ bitcoind -signet -debug=lock
12021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1920 started
22021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1920 completed (4μs)
32021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1302 started
42021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1302 completed (4μs)
52021-09-01T12:40:02Z LockContention: cs_vNodes, net.cpp:2242 started
62021-09-01T12:40:02Z LockContention: cs_vNodes, net.cpp:2242 completed (20μs)
72021-09-01T12:43:04Z LockContention: ::cs_main, validation.cpp:4980 started
82021-09-01T12:43:04Z LockContention: ::cs_main, validation.cpp:4980 completed (3μs)
9
10$ bitcoin-cli -signet logging
11 "lock": true,
12
13$ bitcoin-cli -signet logging [] '["lock"]'
14 "lock": false,
15
16$ bitcoin-cli -signet logging '["lock"]'
17 "lock": true,
I’ve tested this with Clang 13 and GCC 10.2.1, on Debian, with and without --enable-debug
.