forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitors.py
57 lines (44 loc) · 1.71 KB
/
monitors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright 2024 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" The module to provide measurements when it's supported. """
import os
import sys
from contextlib import AbstractContextManager
PROTO_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', 'util/lib/proto/'))
if os.path.isdir(PROTO_DIR):
sys.path.append(PROTO_DIR)
# pylint: disable=import-error, unused-import
from measures import average, count, data_points, dump, time_consumption
else:
class Dummy(AbstractContextManager):
"""Dummy implementation when measures components do not exist."""
# pylint: disable=no-self-use
def record(self, *_) -> None:
"""Dummy implementation of Measure.record."""
# pylint: disable=no-self-use
def dump(self) -> None:
"""Dummy implementation of Measure.dump."""
# Shouldn't be called.
assert False
# pylint: disable=no-self-use
def __enter__(self) -> None:
pass
# pylint: disable=no-self-use
def __exit__(self, *_) -> bool:
return False
def average(*_) -> Dummy:
"""Dummy implementation of measures.average."""
return Dummy()
def count(*_) -> Dummy:
"""Dummy implementation of measures.count."""
return Dummy()
def data_points(*_) -> Dummy:
"""Dummy implementation of measures.data_points."""
return Dummy()
def time_consumption(*_) -> Dummy:
"""Dummy implementation of measures.time_consumption."""
return Dummy()
def dump(*_) -> None:
"""Dummy implementation of measures.dump."""