zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# DO NOT EDIT THIS FILE!
#
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules.
#
# CDP domain: Performance
from __future__ import annotations
from .util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
 
@dataclass
class Metric:
    '''
    Run-time execution metric.
    '''
    #: Metric name.
    name: str
 
    #: Metric value.
    value: float
 
    def to_json(self):
        json = dict()
        json['name'] = self.name
        json['value'] = self.value
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            name=str(json['name']),
            value=float(json['value']),
        )
 
 
def disable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Disable collecting and reporting metrics.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'Performance.disable',
    }
    json = yield cmd_dict
 
 
def enable(
        time_domain: typing.Optional[str] = None
    ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Enable collecting and reporting metrics.
 
    :param time_domain: *(Optional)* Time domain to use for collecting and reporting duration metrics.
    '''
    params: T_JSON_DICT = dict()
    if time_domain is not None:
        params['timeDomain'] = time_domain
    cmd_dict: T_JSON_DICT = {
        'method': 'Performance.enable',
        'params': params,
    }
    json = yield cmd_dict
 
 
def set_time_domain(
        time_domain: str
    ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Sets time domain to use for collecting and reporting duration metrics.
    Note that this must be called before enabling metrics collection. Calling
    this method while metrics collection is enabled returns an error.
 
    **EXPERIMENTAL**
 
    :param time_domain: Time domain
    '''
    params: T_JSON_DICT = dict()
    params['timeDomain'] = time_domain
    cmd_dict: T_JSON_DICT = {
        'method': 'Performance.setTimeDomain',
        'params': params,
    }
    json = yield cmd_dict
 
 
def get_metrics() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[Metric]]:
    '''
    Retrieve current values of run-time metrics.
 
    :returns: Current values for run-time metrics.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'Performance.getMetrics',
    }
    json = yield cmd_dict
    return [Metric.from_json(i) for i in json['metrics']]
 
 
@event_class('Performance.metrics')
@dataclass
class Metrics:
    '''
    Current values of the metrics.
    '''
    #: Current values of the metrics.
    metrics: typing.List[Metric]
    #: Timestamp title.
    title: str
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> Metrics:
        return cls(
            metrics=[Metric.from_json(i) for i in json['metrics']],
            title=str(json['title'])
        )