log, sync: add LOCK logging category, apply it to lock contention
Summary:
This diff:
- adds a LOCK logging category if DEBUG_LOCKCONTENTION is defined at compilation.
- 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
- makes unexpected time type in BCLog::LogMsg() a compile-time error
- add a paragraph of documentation to developer-notes.md
Lock contention logging in checkqueue_tests is disabled, as some of these tests are designed to be heavily contested to trigger race conditions or other issues. This created very large log files when run with DEBUG_LOCKCONTENTION defined.
This is a backport of core#22736, core#22904, core#23223 and core#24770
The first pull request implements the lock category, the other pull requests are important follow-ups (mixed with minor refactorings) fixing various regressions (bugs and suspected performance issues).
Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
Co-authored-by: practicalswift <practicalswift@users.noreply.github.com>
Co-authored-by: Martin Ankerl <martin.ankerl@gmail.com>
Test Plan:
ninja all check-all
Follow the instructions in the new documentation and check that the logging works:
cmake .. -GNinja -DCMAKE_CXX_FLAGS="-DDEBUG_LOCKCONTENTION" ninja src/bitcoind -h | grep -A8 "debug=<category>" src/bitcoind -debug=lock
Reviewers: #bitcoin_abc, sdulfari
Reviewed By: #bitcoin_abc, sdulfari
Subscribers: sdulfari
Differential Revision: https://reviews.bitcoinabc.org/D12049