• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 2023 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 Fuchsia(TestSuite):
23  # Contains tests for parsing Fuchsia traces. Smoke test a bunch of different
24  # types.
25  def test_fuchsia_smoke(self):
26    return DiffTestBlueprint(
27        trace=DataPath('fuchsia_trace.fxt'),
28        query="""
29        SELECT
30          ts,
31          cpu,
32          dur,
33          end_state,
34          priority,
35          tid
36        FROM sched
37        JOIN thread USING(utid)
38        ORDER BY ts
39        LIMIT 10;
40        """,
41        out=Csv("""
42        "ts","cpu","dur","end_state","priority","tid"
43        19675868967,2,79022,"S",20,4344
44        19676000188,3,504797,"S",20,6547
45        19676504985,3,42877,"S",20,6525
46        19676582005,0,48467,"S",20,11566
47        19676989045,2,138116,"S",20,9949
48        19677162311,3,48655,"S",20,6525
49        19677305405,3,48814,"S",20,6525
50        19677412330,0,177220,"S",20,4344
51        19677680485,2,91422,"S",20,6537
52        19677791779,3,96082,"S",20,1680
53        """))
54
55  def test_fuchsia_sched(self):
56    return DiffTestBlueprint(
57        trace=DataPath('fuchsia_trace_sched.fxt'),
58        query="""
59        SELECT
60          ts,
61          cpu,
62          dur,
63          end_state,
64          priority,
65          tid
66        FROM sched
67        JOIN thread USING(utid)
68        ORDER BY ts
69        LIMIT 10;
70        """,
71        out=Csv("""
72        "ts","cpu","dur","end_state","priority","tid"
73        68988611421,3,313611,"S",3122,3196
74        68988925032,3,98697,"S",3122,23416
75        68988957574,0,632536,"S",3122,3189
76        68989023729,3,51371,"S",3122,3196
77        68989075100,3,46773,"R",3122,25332
78        68989121873,3,53620,"S",2147483647,24654
79        68989175493,3,5241,"S",3122,25332
80        68989180734,3,138507,"S",3122,30933
81        68989319241,3,25028,"S",3122,30297
82        68989344269,3,52723,"S",3122,28343
83        """))
84
85  def test_fuchsia_smoke_slices(self):
86    return DiffTestBlueprint(
87        trace=DataPath('fuchsia_trace.fxt'),
88        query="""
89        SELECT track.type AS type, depth, count(*) AS count
90        FROM slice
91        JOIN track ON slice.track_id = track.id
92        GROUP BY track.type, depth
93        ORDER BY track.type, depth;
94        """,
95        out=Csv("""
96        "type","depth","count"
97        "thread_track",0,2153
98        "thread_track",1,1004
99        """))
100
101  def test_fuchsia_smoke_instants(self):
102    return DiffTestBlueprint(
103        trace=DataPath('fuchsia_trace.fxt'),
104        query="""
105        SELECT
106          ts,
107          name
108        FROM slice
109        WHERE
110          dur = 0
111        LIMIT 10;
112        """,
113        out=Csv("""
114        "ts","name"
115        21442756010,"task_start"
116        21446583438,"task_end"
117        21448366538,"task_start"
118        21450363277,"task_end"
119        21454255741,"task_start"
120        21457834528,"task_end"
121        21459006408,"task_start"
122        21460601866,"task_end"
123        21461282720,"task_start"
124        21462998487,"task_end"
125        """))
126
127  def test_fuchsia_smoke_counters(self):
128    return DiffTestBlueprint(
129        trace=DataPath('fuchsia_trace.fxt'),
130        query="""
131        SELECT
132          ts,
133          value,
134          name
135        FROM counters
136        LIMIT 10;
137        """,
138        out=Csv("""
139        "ts","value","name"
140        20329439768,30.331177,"cpu_usage:average_cpu_percentage:0"
141        21331281870,7.829745,"cpu_usage:average_cpu_percentage:0"
142        22332302017,9.669818,"cpu_usage:average_cpu_percentage:0"
143        23332974162,6.421237,"cpu_usage:average_cpu_percentage:0"
144        24333405767,12.079849,"cpu_usage:average_cpu_percentage:0"
145        """))
146
147  def test_fuchsia_smoke_flow(self):
148    return DiffTestBlueprint(
149        trace=DataPath('fuchsia_trace.fxt'),
150        query="""
151        SELECT
152          id,
153          slice_out,
154          slice_in
155        FROM flow
156        LIMIT 10;
157        """,
158        out=Csv("""
159        "id","slice_out","slice_in"
160        0,0,1
161        1,2,3
162        2,4,5
163        3,6,7
164        4,8,9
165        5,10,11
166        6,12,13
167        7,14,15
168        8,16,17
169        9,18,19
170        """))
171
172  def test_fuchsia_smoke_type(self):
173    return DiffTestBlueprint(
174        trace=DataPath('fuchsia_trace.fxt'),
175        query="""
176        SELECT
177          id,
178          name,
179          type
180        FROM track
181        LIMIT 10;
182        """,
183        out=Csv("""
184        "id","name","type"
185        0,"[NULL]","thread_track"
186        1,"[NULL]","thread_track"
187        2,"[NULL]","thread_track"
188        3,"[NULL]","thread_track"
189        4,"[NULL]","thread_track"
190        5,"cpu_usage:average_cpu_percentage:0","process_counter_track"
191        6,"[NULL]","thread_track"
192        7,"[NULL]","thread_track"
193        8,"[NULL]","thread_track"
194        9,"[NULL]","thread_track"
195        """))
196
197  # Smoke test a high-CPU trace.
198  def test_fuchsia_workstation_smoke_slices(self):
199    return DiffTestBlueprint(
200        trace=DataPath('fuchsia_workstation.fxt'),
201        query="""
202        SELECT track.type AS type, depth, count(*) AS count
203        FROM slice
204        JOIN track ON slice.track_id = track.id
205        GROUP BY track.type, depth
206        ORDER BY track.type, depth;
207        """,
208        out=Path('fuchsia_workstation_smoke_slices.out'))
209
210  def test_fuchsia_workstation_smoke_args(self):
211    return DiffTestBlueprint(
212        trace=DataPath('fuchsia_workstation.fxt'),
213        query="""
214        SELECT
215          key,
216          COUNT(*)
217        FROM args
218        GROUP BY key
219        LIMIT 10;
220        """,
221        out=Csv("""
222        "key","COUNT(*)"
223        "Dart Arguments",3
224        "Escher frame number",33
225        "Expected presentation time",17
226        "Frame number",33
227        "MinikinFontsCount",2
228        "Predicted frame duration(ms)",21
229        "Render time(ms)",21
230        "Timestamp",917
231        "Update time(ms)",21
232        "Vsync interval",900
233        """))
234
235  def test_fuchsia_args_import(self):
236    return DiffTestBlueprint(
237        trace=DataPath('fuchsia_events_and_args.fxt'),
238        query="""
239        SELECT key,int_value,string_value,real_value,value_type,display_value
240        FROM args
241        LIMIT 12;
242        """,
243        out=Csv("""
244        "key","int_value","string_value","real_value","value_type","display_value"
245        "SomeNullArg","[NULL]","null","[NULL]","string","null"
246        "Someuint32",2145,"[NULL]","[NULL]","int","2145"
247        "Someuint64",423621626134123415,"[NULL]","[NULL]","int","423621626134123415"
248        "Someint32",-7,"[NULL]","[NULL]","int","-7"
249        "Someint64",-234516543631231,"[NULL]","[NULL]","int","-234516543631231"
250        "Somedouble","[NULL]","[NULL]",3.141500,"real","3.1415"
251        "ping","[NULL]","pong","[NULL]","string","pong"
252        "somepointer",3285933758964,"[NULL]","[NULL]","pointer","0x2fd10ea19f4"
253        "someotherpointer",43981,"[NULL]","[NULL]","pointer","0xabcd"
254        "somekoid",18,"[NULL]","[NULL]","int","18"
255        "somebool",1,"[NULL]","[NULL]","bool","true"
256        "someotherbool",0,"[NULL]","[NULL]","bool","false"
257        """))
258