sapling/edenscm/mercurial/metrics.py
Jun Wu ea16e76336 metrics: make ui.metrics.gauge log to the sampling extension
Summary:
Make it possible to use `ui.metrics.gauge` to collect metrics for a single
command, via the sampling extension.

Differential Revision: D14515775

fbshipit-source-id: e8a53549b00c1bc7b6509a5990a51d955d767d7e
2019-03-20 22:49:18 -07:00

31 lines
816 B
Python

# metrics.py - generic metrics framework
#
# Copyright Mercurial Contributors
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
class metrics(object):
"""Abstract base class for metrics"""
def __init__(self, ui):
self.ui = ui
self.stats = {}
def gauge(self, key, value=1, entity=None):
"""If entity is None, log locally. Otherwise, send it to a global counter."""
if entity is None:
self.stats.setdefault(key, 0)
self.stats[key] += value
def client(ui):
"""Returns the appropriate metrics module"""
# @fb-only: from . import fb
# @fb-only: return fb.fbmetrics(ui)
return metrics(ui) # @oss-only