• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 2024 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License a
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from python.generators.diff_tests.testing import Path, DataPath, Metric
17from python.generators.diff_tests.testing import Csv, Json, TextProto
18from python.generators.diff_tests.testing import DiffTestBlueprint
19from python.generators.diff_tests.testing import TestSuite
20
21
22class CloneDurationMetrics(TestSuite):
23
24  def test_clone_duration_by_buffer(self):
25    return DiffTestBlueprint(
26        trace=TextProto(r"""
27        packet {
28          timestamp: 1000000
29          trace_uuid {
30            msb: 1
31            lsb: 2
32          }
33        }
34        packet {
35          timestamp: 1000000
36          service_event {
37            clone_started: true
38          }
39        }
40        packet {
41          timestamp: 2000000
42          service_event {
43            buffer_cloned: 1
44          }
45        }
46        packet {
47          timestamp: 3000000
48          service_event {
49            buffer_cloned: 2
50          }
51        }
52        packet {
53          timestamp: 4000000
54          service_event {
55            buffer_cloned: 0
56          }
57        }
58        """),
59        query=Metric('clone_duration'),
60        out=TextProto(r"""
61        clone_duration {
62          by_buffer {
63            buffer: 0
64            duration_ns: 3000000
65          }
66          by_buffer {
67            buffer: 1
68            duration_ns: 1000000
69          }
70          by_buffer {
71            buffer: 2
72            duration_ns: 2000000
73          }
74        }
75        """))
76
77  def test_clone_duration_by_buffer_missing_clone_started(self):
78    return DiffTestBlueprint(
79        trace=TextProto(r"""
80        packet {
81          timestamp: 1000000
82          trace_uuid {
83            msb: 1
84            lsb: 2
85          }
86        }
87        packet {
88          timestamp: 2000000
89          service_event {
90            buffer_cloned: 1
91          }
92        }
93        packet {
94          timestamp: 3000000
95          service_event {
96            buffer_cloned: 2
97          }
98        }
99        packet {
100          timestamp: 4000000
101          service_event {
102            buffer_cloned: 0
103          }
104        }
105        """),
106        query=Metric('clone_duration'),
107        out=TextProto(r"""
108        clone_duration {
109        }
110        """))
111
112  def test_clone_duration_by_buffer_missing_buffer_cloned(self):
113    return DiffTestBlueprint(
114        trace=TextProto(r"""
115        packet {
116          timestamp: 1000000
117          trace_uuid {
118            msb: 1
119            lsb: 2
120          }
121        }
122        packet {
123          timestamp: 1000000
124          service_event {
125            clone_started: true
126          }
127        }
128        """),
129        query=Metric('clone_duration'),
130        out=TextProto(r"""
131        clone_duration {
132        }
133        """))
134