(This post supersedes GitHub Issue #349.)
Here is a recipe for enabling all available debugging tools. You might want to pick and choose depending on the nature of the specific bug you are hunting.
- Catch stack traces.
- Set the environment variable
RUST_BACKTRACE, either runexport RUST_BACKTRACE=1before invokingneptune-coreor prepend theneptune-corewithRUST_BACKTRACE=1.
- Choose informative log level.
- In principle there are four log levels,
ERROR,WARN,INFO, andDEBUG, and by default everything up to and includingINFOis enabled. Phrased differently,DEBUGmessages are disabled by default. - To enable
DEBUGmessages, runexport RUST_LOG="debug"or prepend theneptune-corecommand withRUST_LOG="debug".
- Trace locks.
- Lock tracing is another (non-standard) set of log messages. It requires nightly.
- Enable nightly:
rustup default nightly, or alternatively add+nightlyimmediately aftercargoin commands that usecargo. - Set log level to
"debug,neptune_cash=trace"with anexportcommand or by prepending. - Build and run with
--features log-slow-write-lock,log-slow-read-lock,log-lock_events(immediately before the double dash (--) indicating the start of the command line arguments).
- Use
tokio-console.
tokio-consoleis anhtop-like tool to monitor which threads are doing what.- Install
tokio-console:cargo install --locked tokio-console - To instruct
neptune-coreto supporttokio-console, add--tokio-consoleas an extra CLI argument. - Note that
tokio-consoleuses port 6669 for communication, so that port had better not be in use by other processes.
- Pipe output into a log file.
teecan be used to put the console output into a file while preserving the console output.sedcan be used to strip colors, making the file more reader-friendly.- Use both: pipe the
neptune-coreoutput through| tee >(sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]//g" > neptune-core.log) - This suffix will overwrite the log file
neptune-core.log, so be sure to back it up if one exists already and you might need it.
- All together.
- (Don’t forget to cherry pick!)
- (Don’t forget to
cargo installdependencies.) - (Don’t forget to replace
[other CLI arguments]with the CLI arguments you would otherwise runneptune-corewith, such as--max-num-peers 5or--guess.) RUST_BACKTRACE=1 RUST_LOG="debug,neptune_cash=trace" cargo +nightly run neptune-core --features log-slow-write-lock,log-slow-read-lock,log-lock_events -- --tokio-console [other CLI arguments] | tee >(sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]//g" > neptune-core.log)