-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmeasurer.py
More file actions
59 lines (44 loc) · 1.35 KB
/
measurer.py
File metadata and controls
59 lines (44 loc) · 1.35 KB
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
58
59
import abc
class AbstractMeasurerDelegate(abc.ABC):
"""
Abstract class implemented by the actual measurer.
"""
@abc.abstractmethod
def count(self):
raise NotImplementedError
@abc.abstractmethod
def inc(self):
raise NotImplementedError
@abc.abstractmethod
def dec(self):
raise NotImplementedError
@abc.abstractmethod
def observe(self):
raise NotImplementedError
@abc.abstractmethod
def observe_bucket(self):
raise NotImplementedError
@abc.abstractmethod
def __enter__(self):
raise NotImplementedError
@abc.abstractmethod
def __exit__(self, exc_type, exc_val, exc_tb):
raise NotImplementedError
class AbstractMeasurer(abc.ABC):
"""
Abstract class that must be implemented by tools used for measurement.
This is used to keep tracking of how many times a function is used and
to export this information.
"""
@abc.abstractmethod
def track_call(self, name: str, description: str) -> AbstractMeasurerDelegate:
raise NotImplementedError
@abc.abstractmethod
def export(self) -> bytes:
raise NotImplementedError
@abc.abstractmethod
def __enter__(self):
raise NotImplementedError
@abc.abstractmethod
def __exit__(self, exc_type, exc_val, exc_tb):
raise NotImplementedError