Track length of time mutexes are held for #2267
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replaced all
std::lock_guard
andstd::unique_lock
with newnano::
equivalents (apart from ones incrypto_lib
as they don't have any nano dependencies). If-DNANO_TIMED_LOCKS=100
is set for instance, it will use the new classes which will output the stacktrace of any mutexes held for longer than this (100ms). It also reports which ones were waiting on other mutexes as well as the pointer address so that they can be later connected.I'm only tracking the containers using a
std::mutex
, as things likerecursive_mutex
,shared_mutex
are quite a bit more difficult and not nearly as useful. Speaking of which this will be useful for checking whether we have a lot of readers (and few writers) blocking each other, where usingstd::shared_mutex
&std::shared_timed_mutex
may be more appropriate.Annoyingly
std::condition_variable
methods are not based on a template, it only expectsstd::unique_lock
, so it makes it difficult to use the newnano::unique_lock
, for this reason I also had to addnano::condition_variable
, which is quite a bit more difficult to wrap as it uses spin-locks etc... So I'm using boost'scondition_variable_any
, which is based on a template! and wrapped my class around that. But this does mean we need thecontext
&fiber
boost libraries. But I made sure that they are only required ifDNANO_TIMED_LOCKS
is set to greater than 0 to maintain backwards compatibility because this is very much a Diagnostics only options only really useful for debugging purposes. I started to add a test, but again, this could only be tested if using DNANO_TIMED_LOCKS, which would then affect all other tests so this didn't seem worth the hassle it for a diagnostics only option.