Utilities to easily count events for debuging puposes
This can be useful to gather statistics about how often different code paths are run.
Overhead
The implementation is very simple and not particularly fast. Using counters will affect perfomance measurements.
Optimizing out
If the feature flag noop
is enabled, the counters compile into an empty struct
with empty methods. This way the code for counting events can be kept while opting
out of its overhead in shipping and profiling build configurations.
Example
In the example below we have a function do_the_thing
which we determined to
be expensive (using a profiler). We would like to get some insight into how
often the function is run and how often we take the slow and fast paths.
use Counters;
use *;