module documentation

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 Counter A monotonically increasing metric.
Class Distribution A metric to track simple statistics from a distribution of values.
Class MapCounter A set of related counters keyed by an arbitrary string.
Class Metric Abstract base class for metrics.
Class MetricsContext A context manager that configures metrics and writes their output.
Class ReentrantStopWatch A watch that supports being called multiple times and recursively.
Class Snapshot A metric to track memory usage via tracemalloc snapshots.
Class StopWatch A counter that measures the time spent in a "with" statement.
Function dump_all Write a list of metrics to a json file.
Function get_cpu_clock Returns CPU clock to keep compatibility with various Python versions.
Function get_metric Return an existing metric or create a new one for the given name.
Function get_report Return a string listing all metrics, one per line.
Function load_all Read a list of metrics from a json file.
Function merge_from_file Merge metrics recorded in another file into the current metrics.
Class _RegistryMeta Metaclass that registers subclasses in _METRIC_TYPES.
Function _deserialize Construct a Metric from a typename and payload loaded from json.
Function _prepare_for_test Setup metrics collection for a test.
Function _serialize Return a json-serializable form of object.
Function _validate_metric_name Undocumented
Constant _METRIC_NAME_RE Undocumented
Constant _METRIC_TYPES Undocumented
Variable _enabled Undocumented
Variable _platform_timer Undocumented
Variable _registered_metrics Undocumented
def dump_all(objs, fp): (source)

Write a list of metrics to a json file.

def get_cpu_clock(): (source)

Returns CPU clock to keep compatibility with various Python versions.

def get_metric(name, constructor, *args, **kwargs): (source)

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).

def get_report(): (source)

Return a string listing all metrics, one per line.

def load_all(fp): (source)

Read a list of metrics from a json file.

def merge_from_file(metrics_file): (source)

Merge metrics recorded in another file into the current metrics.

def _deserialize(typ, payload): (source)

Construct a Metric from a typename and payload loaded from json.

def _prepare_for_test(enabled=True): (source)

Setup metrics collection for a test.

def _serialize(obj): (source)

Return a json-serializable form of object.

def _validate_metric_name(name): (source)

Undocumented

_METRIC_NAME_RE = (source)

Undocumented

Value
re.compile(r'^[a-zA-Z_]\w+$')
_METRIC_TYPES: dict = (source)

Undocumented

Value
{}
_enabled: bool = (source)

Undocumented

_platform_timer = (source)

Undocumented

_registered_metrics: dict = (source)

Undocumented