In short, PyCounters is built to allow adding event reporting with piratically no performance impact. Counters add some minimal overhead. Only on output does PyCounters do some calculation (every 5 minutes, depending on configuration).
PyCounters defines two types of events:
There is no special way in PyCounters to create new event it is enough, to create a counter listening to that event.
All the “smartness” of PyCounters is bundled withing a set of Counters. Counters are in charge of intercepting and interpreting events reported by different parts of the program. As mentioned before, you can register a Counter when you want to analyze specific events (by default events of identical name, if you need more control, use events parameter). You do so by using the register_counter() function:
counter = AverageWindowCounter("some_name") register_counter(counter)
You can also unregister the counter once you don’t need it anymore:
or by name:
After unregistering the counter all events named “some_name” will be ignored (unless some other counter listens to them).
You can only register a single counter for any given name.
Reporters are used to collect a report from the currently registered Counters. Reporters are not supposed to run often as that will have a performance impact.
At the moment PyCounters can only output to python logs and JSON files. For example, to output to logs, create an instance of LogReporter . You can then manually output reports (using output_report) or turn on auto reporting (using start_auto_reporting .)
reporter=pycounters.reporters.LogReporter(logging.getLogger("counters")) pycounters.register_reporter(reporter) #... some where later pycounters.output_report()