Classes for instrumenting code to collect various metrics. Instrumentation consists of creating the metric and then updating it. Creation can be performed at the module level or as a class attribute. Since the metric namespace is global, metrics should not be created by instances unless that instance is certain to be a singleton. Sample code: _my_counter = metrics.Counter("my-counter") def foo(): _my_counter.inc() # calls to foo() count as 1 unit. def bar(n): _my_counter.inc(n) # calls to bar() count as n units.
Class |
|
A monotonically increasing metric. |
Class |
|
A metric to track simple statistics from a distribution of values. |
Class |
|
A set of related counters keyed by an arbitrary string. |
Class |
|
Abstract base class for metrics. |
Class |
|
A context manager that configures metrics and writes their output. |
Class |
|
A watch that supports being called multiple times and recursively. |
Class |
|
A metric to track memory usage via tracemalloc snapshots. |
Class |
|
A counter that measures the time spent in a "with" statement. |
Function | dump |
Write a list of metrics to a json file. |
Function | get |
Returns CPU clock to keep compatibility with various Python versions. |
Function | get |
Return an existing metric or create a new one for the given name. |
Function | get |
Return a string listing all metrics, one per line. |
Function | load |
Read a list of metrics from a json file. |
Function | merge |
Merge metrics recorded in another file into the current metrics. |
Class | _ |
Metaclass that registers subclasses in _METRIC_TYPES. |
Function | _deserialize |
Construct a Metric from a typename and payload loaded from json. |
Function | _prepare |
Setup metrics collection for a test. |
Function | _serialize |
Return a json-serializable form of object. |
Function | _validate |
Undocumented |
Constant | _METRIC |
Undocumented |
Constant | _METRIC |
Undocumented |
Variable | _enabled |
Undocumented |
Variable | _platform |
Undocumented |
Variable | _registered |
Undocumented |
Return an existing metric or create a new one for the given name. Args: name: The name of the metric. constructor: A class to instantiate if a new metric is required. *args: Additional positional args to pass to the constructor. **kwargs: Keyword args for the constructor. Returns: The current metric registered to name, or a new one created by invoking constructor(name, *args, **kwargs).