xref: /aosp_15_r20/external/angle/build/fuchsia/test/monitors.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2024 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4""" The module to provide measurements when it's supported. """
5
6import os
7import sys
8
9from contextlib import AbstractContextManager
10
11from common import DIR_SRC_ROOT
12
13PROTO_DIR = os.path.abspath(
14    os.path.join(DIR_SRC_ROOT, 'build', 'util', 'lib', 'proto'))
15if os.path.isdir(PROTO_DIR):
16    sys.path.append(PROTO_DIR)
17    # pylint: disable=import-error, unused-import
18    from measures import average, clear, count, data_points, dump, tag, \
19            time_consumption
20else:
21
22    class Dummy(AbstractContextManager):
23        """Dummy implementation when measures components do not exist."""
24
25        # pylint: disable=no-self-use
26        def record(self, *_) -> None:
27            """Dummy implementation of Measure.record."""
28
29        # pylint: disable=no-self-use
30        def dump(self) -> None:
31            """Dummy implementation of Measure.dump."""
32            # Shouldn't be called.
33            assert False
34
35        # pylint: disable=no-self-use
36        def __enter__(self) -> None:
37            pass
38
39        # pylint: disable=no-self-use
40        def __exit__(self, *_) -> bool:
41            return False
42
43    def average(*_) -> Dummy:
44        """Dummy implementation of measures.average."""
45        return Dummy()
46
47    def count(*_) -> Dummy:
48        """Dummy implementation of measures.count."""
49        return Dummy()
50
51    def clear(*_) -> None:
52        """Dummy implementation of measures.clear."""
53
54    def data_points(*_) -> Dummy:
55        """Dummy implementation of measures.data_points."""
56        return Dummy()
57
58    def time_consumption(*_) -> Dummy:
59        """Dummy implementation of measures.time_consumption."""
60        return Dummy()
61
62    def dump(*_) -> None:
63        """Dummy implementation of measures.dump."""
64
65    def tag(*_) -> None:
66        """Dummy implementation of measures.tag."""
67