• 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 Csv, Path, DataPath
17from python.generators.diff_tests.testing import DiffTestBlueprint
18from python.generators.diff_tests.testing import TestSuite
19
20
21class Cpu(TestSuite):
22
23  def test_cpu_utilization_per_second(self):
24    return DiffTestBlueprint(
25        trace=DataPath('example_android_trace_30s.pb'),
26        query="""
27        INCLUDE PERFETTO MODULE cpu.utilization.system;
28
29        SELECT * FROM cpu_utilization_per_second;
30        """,
31        out=Csv("""
32        "ts","utilization","unnormalized_utilization"
33        70000000000,0.004545,0.036362
34        71000000000,0.022596,0.180764
35        72000000000,0.163393,1.307146
36        73000000000,0.452122,3.616972
37        74000000000,0.525557,4.204453
38        75000000000,0.388632,3.109057
39        76000000000,0.425447,3.403579
40        77000000000,0.201112,1.608896
41        78000000000,0.280247,2.241977
42        79000000000,0.345228,2.761827
43        80000000000,0.303258,2.426064
44        81000000000,0.487522,3.900172
45        82000000000,0.080542,0.644336
46        83000000000,0.362450,2.899601
47        84000000000,0.076438,0.611501
48        85000000000,0.110689,0.885514
49        86000000000,0.681488,5.451901
50        87000000000,0.808331,6.466652
51        88000000000,0.941768,7.534142
52        89000000000,0.480556,3.844446
53        90000000000,0.453268,3.626142
54        91000000000,0.280310,2.242478
55        92000000000,0.006381,0.051049
56        93000000000,0.030991,0.247932
57        94000000000,0.031981,0.255845
58        95000000000,0.027931,0.223446
59        96000000000,0.063066,0.504529
60        97000000000,0.023847,0.190773
61        98000000000,0.011291,0.090328
62        99000000000,0.024065,0.192518
63        100000000000,0.001964,0.015711
64        """))
65
66  def test_cpu_process_utilization_per_second(self):
67    return DiffTestBlueprint(
68        trace=DataPath('example_android_trace_30s.pb'),
69        query="""
70        INCLUDE PERFETTO MODULE cpu.utilization.process;
71
72        SELECT *
73        FROM cpu_process_utilization_per_second(10);
74        """,
75        out=Csv("""
76        "ts","utilization","unnormalized_utilization"
77        72000000000,0.000187,0.001495
78        73000000000,0.000182,0.001460
79        77000000000,0.000072,0.000579
80        78000000000,0.000275,0.002204
81        82000000000,0.000300,0.002404
82        83000000000,0.000004,0.000034
83        87000000000,0.000133,0.001065
84        88000000000,0.000052,0.000416
85        89000000000,0.000212,0.001697
86        92000000000,0.000207,0.001658
87        97000000000,0.000353,0.002823
88        """))
89
90  def test_cpu_thread_utilization_per_second(self):
91    return DiffTestBlueprint(
92        trace=DataPath('example_android_trace_30s.pb'),
93        query="""
94        INCLUDE PERFETTO MODULE cpu.utilization.thread;
95
96        SELECT *
97        FROM cpu_thread_utilization_per_second(10);
98        """,
99        out=Csv("""
100        "ts","utilization","unnormalized_utilization"
101        70000000000,0.000024,0.000195
102        72000000000,0.000025,0.000200
103        73000000000,0.000053,0.000420
104        74000000000,0.000044,0.000352
105        75000000000,0.000058,0.000461
106        76000000000,0.000075,0.000603
107        77000000000,0.000051,0.000407
108        78000000000,0.000047,0.000374
109        79000000000,0.000049,0.000396
110        80000000000,0.000084,0.000673
111        81000000000,0.000041,0.000329
112        82000000000,0.000048,0.000383
113        83000000000,0.000040,0.000323
114        84000000000,0.000018,0.000145
115        85000000000,0.000053,0.000421
116        86000000000,0.000121,0.000972
117        87000000000,0.000049,0.000392
118        88000000000,0.000036,0.000285
119        89000000000,0.000033,0.000266
120        90000000000,0.000050,0.000401
121        91000000000,0.000025,0.000201
122        92000000000,0.000009,0.000071
123        """))
124
125  def test_cpu_cycles_per_cpu(self):
126    return DiffTestBlueprint(
127        trace=DataPath('android_postboot_unlock.pftrace'),
128        query=("""
129             INCLUDE PERFETTO MODULE cpu.utilization.system;
130
131             SELECT
132               *
133             FROM cpu_cycles_per_cpu;
134             """),
135        out=Csv("""
136          "cpu","cpu_type","millicycles","megacycles","runtime","min_freq","max_freq","avg_freq"
137          0,"little",4007488375822,4007,2260291804,930000,1803000,1775516
138          1,"little",3985923237512,3985,2247149674,930000,1803000,1776869
139          2,"little",4047926756581,4047,2276274170,930000,1803000,1781496
140          3,"little",3992276081242,3992,2248956757,930000,1803000,1778975
141          4,"mid",5134318459625,5134,2203887266,553000,2348000,2335531
142          5,"mid",5615703220380,5615,2438499077,553000,2348000,2308698
143          6,"big",4715590442538,4715,1737264802,500000,2850000,2725191
144          7,"big",4594701918170,4594,1719270548,500000,2850000,2685290
145            """))
146
147  def test_cpu_cycles_per_thread(self):
148    return DiffTestBlueprint(
149        trace=DataPath('android_cpu_eos.pb'),
150        query=("""
151             INCLUDE PERFETTO MODULE cpu.utilization.thread;
152
153             SELECT
154               AVG(millicycles) AS millicycles,
155               AVG(megacycles) AS megacycles,
156               AVG(runtime) AS runtime,
157               AVG(min_freq) AS min_freq,
158               AVG(max_freq) AS max_freq,
159               AVG(avg_freq) AS avg_freq
160             FROM cpu_cycles_per_thread;
161             """),
162        out=Csv("""
163            "millicycles","megacycles","runtime","min_freq","max_freq","avg_freq"
164            25048302186.035053,24.624742,16080173.697531,1402708.453608,1648468.453608,1582627.707216
165            """))
166
167  def test_cpu_cycles_per_process(self):
168    return DiffTestBlueprint(
169        trace=DataPath('android_cpu_eos.pb'),
170        query=("""
171             INCLUDE PERFETTO MODULE cpu.utilization.process;
172
173             SELECT
174               AVG(millicycles) AS millicycles,
175               AVG(megacycles) AS megacycles,
176               AVG(runtime) AS runtime,
177               AVG(min_freq) AS min_freq,
178               AVG(max_freq) AS max_freq,
179               AVG(avg_freq) AS avg_freq
180             FROM cpu_cycles_per_process;
181             """),
182        out=Csv("""
183            "millicycles","megacycles","runtime","min_freq","max_freq","avg_freq"
184            83208401098.424652,82.753425,53163023.244898,1189742.465753,1683945.205479,1534667.547945
185            """))
186
187  # Test CPU frequency counter grouping.
188  def test_cpu_eos_counters_freq(self):
189    return DiffTestBlueprint(
190        trace=DataPath('android_cpu_eos.pb'),
191        query=("""
192             INCLUDE PERFETTO MODULE cpu.freq;
193             select
194               track_id,
195               freq,
196               cpu,
197               sum(dur) as dur
198             from cpu_freq_counters
199             GROUP BY freq, cpu
200             """),
201        out=Csv("""
202            "track_id","freq","cpu","dur"
203            33,614400,0,4755967239
204            34,614400,1,4755971561
205            35,614400,2,4755968228
206            36,614400,3,4755964320
207            33,864000,0,442371195
208            34,864000,1,442397134
209            35,864000,2,442417916
210            36,864000,3,442434530
211            33,1363200,0,897122398
212            34,1363200,1,897144167
213            35,1363200,2,897180154
214            36,1363200,3,897216772
215            33,1708800,0,2553979530
216            34,1708800,1,2553923073
217            35,1708800,2,2553866772
218            36,1708800,3,2553814688
219            """))
220
221  # Test CPU idle state counter grouping.
222  def test_cpu_eos_counters_idle(self):
223    return DiffTestBlueprint(
224        trace=DataPath('android_cpu_eos.pb'),
225        query=("""
226             INCLUDE PERFETTO MODULE cpu.idle;
227             select
228               track_id,
229               idle,
230               cpu,
231               sum(dur) as dur
232             from cpu_idle_counters
233             GROUP BY idle, cpu
234             """),
235        out=Csv("""
236             "track_id","idle","cpu","dur"
237             0,-1,0,2839828332
238             37,-1,1,1977033843
239             32,-1,2,1800498713
240             1,-1,3,1884366297
241             0,0,0,1833971336
242             37,0,1,2285260950
243             32,0,2,1348416182
244             1,0,3,1338508968
245             0,1,0,4013820433
246             37,1,1,4386917600
247             32,1,2,5532102915
248             1,1,3,5462026920
249            """))
250