• 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 PerfettoTable(TestSuite):
23
24  def test_create_table(self):
25    return DiffTestBlueprint(
26        trace=TextProto(r''),
27        query="""
28        CREATE PERFETTO TABLE foo AS SELECT 42 as a;
29
30        SELECT * FROM foo;
31        """,
32        out=Csv("""
33        "a"
34        42
35        """))
36
37  def test_replace_table(self):
38    return DiffTestBlueprint(
39        trace=TextProto(r''),
40        query="""
41        CREATE PERFETTO TABLE foo AS SELECT 42 as a;
42        CREATE OR REPLACE PERFETTO TABLE foo AS SELECT 43 as a;
43
44        SELECT * FROM foo;
45        """,
46        out=Csv("""
47        "a"
48        43
49        """))
50
51  def test_create_perfetto_table_double_metric_run(self):
52    return DiffTestBlueprint(
53        trace=TextProto(r''),
54        query="""
55        SELECT RUN_METRIC('android/cpu_info.sql');
56        SELECT RUN_METRIC('android/cpu_info.sql');
57
58        SELECT * FROM cluster_core_type;
59        """,
60        out=Csv("""
61        "cluster","core_type"
62        0,"little"
63        1,"big"
64        2,"bigger"
65        """))
66
67  def test_perfetto_table_info_static_table(self):
68    return DiffTestBlueprint(
69        trace=DataPath('android_boot.pftrace'),
70        query="""
71        SELECT id, name, col_type, nullable, sorted
72        FROM perfetto_table_info('__intrinsic_counter');
73        """,
74        out=Csv("""
75        "id","name","col_type","nullable","sorted"
76        0,"id","id",0,1
77        1,"ts","int64",0,1
78        2,"track_id","uint32",0,0
79        3,"value","double",0,0
80        4,"arg_set_id","uint32",1,0
81        """))
82
83  def test_perfetto_table_info_runtime_table(self):
84    return DiffTestBlueprint(
85        trace=TextProto(''),
86        query="""
87        CREATE PERFETTO TABLE foo AS
88        SELECT * FROM
89        (SELECT 2 AS c
90        UNION
91        SELECT 0 AS c
92        UNION
93        SELECT 1 AS c)
94        ORDER BY c desc;
95
96        SELECT id, name, col_type, nullable, sorted from perfetto_table_info('foo');
97        """,
98        out=Csv("""
99        "id","name","col_type","nullable","sorted"
100        0,"c","int64",0,0
101        """))
102
103  def test_create_perfetto_table_nullable_column(self):
104    return DiffTestBlueprint(
105        trace=DataPath('android_boot.pftrace'),
106        query="""
107        CREATE PERFETTO TABLE foo AS
108        SELECT thread_ts FROM slice
109        WHERE thread_ts IS NOT NULL;
110
111        SELECT nullable FROM perfetto_table_info('foo')
112        WHERE name = 'thread_ts';
113        """,
114        out=Csv("""
115        "nullable"
116        0
117        """))
118
119  def test_create_perfetto_table_sorted_column(self):
120    return DiffTestBlueprint(
121        trace=DataPath('android_boot.pftrace'),
122        query="""
123        CREATE PERFETTO TABLE foo AS
124        SELECT dur FROM slice ORDER BY dur;
125
126        SELECT sorted FROM perfetto_table_info('foo')
127        WHERE name = 'dur';
128        """,
129        out=Csv("""
130        "sorted"
131        1
132        """))
133
134  def test_create_perfetto_table_id_column(self):
135    return DiffTestBlueprint(
136        trace=TextProto(''),
137        query="""
138        CREATE PERFETTO TABLE foo AS
139        SELECT 2 AS c
140        UNION
141        SELECT 4
142        UNION
143        SELECT 6;
144
145        SELECT col_type FROM perfetto_table_info('foo')
146        WHERE name = 'c';
147        """,
148        out=Csv("""
149        "col_type"
150        "id"
151        """))
152
153  def test_distinct_trivial(self):
154    return DiffTestBlueprint(
155        trace=DataPath('example_android_trace_30s.pb'),
156        query="""
157        WITH trivial_count AS (
158          SELECT DISTINCT name FROM slice
159        ),
160        few_results AS (
161          SELECT DISTINCT depth FROM slice
162        ),
163        simple_nullable AS (
164          SELECT DISTINCT parent_id FROM slice
165        ),
166        selector AS (
167          SELECT DISTINCT cpu FROM ftrace_event
168        )
169        SELECT
170          (SELECT COUNT(*) FROM trivial_count) AS name,
171          (SELECT COUNT(*) FROM few_results) AS depth,
172          (SELECT COUNT(*) FROM simple_nullable) AS parent_id,
173          (SELECT COUNT(*) FROM selector) AS cpu_from_ftrace;
174        """,
175        out=Csv("""
176        "name","depth","parent_id","cpu_from_ftrace"
177        3073,8,4529,8
178        """))
179
180  def test_distinct_multi_column(self):
181    return DiffTestBlueprint(
182        trace=TextProto(''),
183        query="""
184        CREATE PERFETTO TABLE foo AS
185        WITH data(a, b) AS (
186          VALUES
187            -- Needed to defeat any id/sorted detection.
188            (2, 3),
189            (0, 2),
190            (0, 1)
191        )
192        SELECT * FROM data;
193
194        CREATE TABLE bar AS
195        SELECT 1 AS b;
196
197        WITH multi_col_distinct AS (
198          SELECT DISTINCT a FROM foo CROSS JOIN bar USING (b)
199        ), multi_col_group_by AS (
200          SELECT a FROM foo CROSS JOIN bar USING (b) GROUP BY a
201        )
202        SELECT
203          (SELECT COUNT(*) FROM multi_col_distinct) AS cnt_distinct,
204          (SELECT COUNT(*) FROM multi_col_group_by) AS cnt_group_by
205        """,
206        out=Csv("""
207        "cnt_distinct","cnt_group_by"
208        1,1
209        """))
210
211  def test_limit(self):
212    return DiffTestBlueprint(
213        trace=TextProto(''),
214        query="""
215        WITH data(a, b) AS (
216          VALUES
217            (0, 1),
218            (1, 10),
219            (2, 20),
220            (3, 30),
221            (4, 40),
222            (5, 50)
223        )
224        SELECT * FROM data LIMIT 3;
225        """,
226        out=Csv("""
227        "a","b"
228        0,1
229        1,10
230        2,20
231        """))
232
233  def test_limit_and_offset_in_bounds(self):
234    return DiffTestBlueprint(
235        trace=TextProto(''),
236        query="""
237        WITH data(a, b) AS (
238          VALUES
239            (0, 1),
240            (1, 10),
241            (2, 20),
242            (3, 30),
243            (4, 40),
244            (5, 50),
245            (6, 60),
246            (7, 70),
247            (8, 80),
248            (9, 90)
249        )
250        SELECT * FROM data LIMIT 2 OFFSET 3;
251        """,
252        out=Csv("""
253        "a","b"
254        3,30
255        4,40
256        """))
257
258  def test_limit_and_offset_not_in_bounds(self):
259    return DiffTestBlueprint(
260        trace=TextProto(''),
261        query="""
262        WITH data(a, b) AS (
263          VALUES
264            (0, 1),
265            (1, 10),
266            (2, 20),
267            (3, 30),
268            (4, 40),
269            (5, 50),
270            (6, 60),
271            (7, 70),
272            (8, 80),
273            (9, 90)
274        )
275        SELECT * FROM data LIMIT 5 OFFSET 6;
276        """,
277        out=Csv("""
278        "a","b"
279        6,60
280        7,70
281        8,80
282        9,90
283        """))
284
285  def test_max(self):
286    return DiffTestBlueprint(
287        trace=DataPath('example_android_trace_30s.pb'),
288        query="""
289        CREATE PERFETTO MACRO max(col ColumnName)
290        RETURNS TableOrSubquery AS (
291          SELECT id, $col
292          FROM slice
293          ORDER BY $col DESC
294          LIMIT 1
295        );
296
297        SELECT
298          (SELECT id FROM max!(id)) AS id,
299          (SELECT id FROM max!(dur)) AS numeric,
300          (SELECT id FROM max!(name)) AS string,
301          (SELECT id FROM max!(parent_id)) AS nullable;
302        """,
303        out=Csv("""
304        "id","numeric","string","nullable"
305        20745,2698,148,20729
306        """))
307
308  def test_min(self):
309    return DiffTestBlueprint(
310        trace=DataPath('example_android_trace_30s.pb'),
311        query="""
312        CREATE PERFETTO MACRO min(col ColumnName)
313        RETURNS TableOrSubquery AS (
314          SELECT id, $col
315          FROM slice
316          ORDER BY $col ASC
317          LIMIT 1
318        );
319
320        SELECT
321          (SELECT id FROM min!(id)) AS id,
322          (SELECT id FROM min!(dur)) AS numeric,
323          (SELECT id FROM min!(name)) AS string,
324          (SELECT id FROM min!(parent_id)) AS nullable;
325        """,
326        out=Csv("""
327        "id","numeric","string","nullable"
328        0,3111,460,0
329        """))
330
331  def test_create_perfetto_index(self):
332    return DiffTestBlueprint(
333        trace=DataPath('example_android_trace_30s.pb'),
334        query="""
335        CREATE PERFETTO INDEX foo ON __intrinsic_slice(track_id);
336        CREATE PERFETTO INDEX foo_name ON __intrinsic_slice(name);
337
338        SELECT
339          COUNT() FILTER (WHERE track_id > 10) AS track_idx,
340          COUNT() FILTER (WHERE name > "g") AS name_idx
341        FROM __intrinsic_slice;
342        """,
343        out=Csv("""
344        "track_idx","name_idx"
345        20717,7098
346        """))
347
348  def test_create_perfetto_index_multiple_cols(self):
349    return DiffTestBlueprint(
350        trace=DataPath('example_android_trace_30s.pb'),
351        query="""
352          CREATE PERFETTO INDEX foo ON __intrinsic_slice(track_id, name);
353
354          WITH
355            ttid AS (
356              SELECT thread_track.id
357              FROM thread_track
358              JOIN thread USING (utid)
359              WHERE thread.name = 'android.bg'
360              LIMIT 1
361            ),
362            agg AS MATERIALIZED (
363              SELECT
364                MIN(track_id) AS min_track_id,
365                MAX(name) AS min_name
366              FROM __intrinsic_slice
367              WHERE track_id = (SELECT id FROM ttid) AND name > "c"
368            )
369            SELECT
370              min_track_id = (SELECT id FROM ttid) AS is_correct_track_id,
371              min_name
372            FROM agg
373        """,
374        out=Csv("""
375          "is_correct_track_id","min_name"
376          1,"virtual bool art::ElfOatFile::Load(const std::string &, bool, bool, bool, art::MemMap *, std::string *)"
377        """))
378
379  def test_create_perfetto_index_multiple_smoke(self):
380    return DiffTestBlueprint(
381        trace=DataPath('example_android_trace_30s.pb'),
382        query="""
383          CREATE PERFETTO INDEX idx ON __intrinsic_slice(track_id, name);
384          CREATE PERFETTO TABLE bar AS SELECT * FROM slice;
385
386          WITH ttid AS (
387            SELECT thread_track.id
388            FROM thread_track
389            JOIN thread USING (utid)
390            WHERE thread.name = 'android.bg'
391            LIMIT 1
392          )
393          SELECT (
394            SELECT count()
395            FROM bar
396            WHERE track_id = (SELECT id FROM ttid) AND dur > 1000 AND name > "b"
397          ) AS non_indexes_stats,
398          (
399            SELECT count()
400            FROM __intrinsic_slice
401            WHERE track_id = (SELECT id FROM ttid) AND dur > 1000 AND name > "b"
402          ) AS indexed_stats
403        """,
404        out=Csv("""
405          "non_indexes_stats","indexed_stats"
406          39,39
407        """))
408
409  def test_create_or_replace_perfetto_index(self):
410    return DiffTestBlueprint(
411        trace=DataPath('example_android_trace_30s.pb'),
412        query="""
413          CREATE PERFETTO INDEX idx ON __intrinsic_slice(track_id, name);
414          CREATE OR REPLACE PERFETTO INDEX idx ON __intrinsic_slice(name);
415
416          WITH ttid AS (
417            SELECT thread_track.id
418            FROM thread_track
419            JOIN thread USING (utid)
420            WHERE thread.name = 'android.bg'
421            LIMIT 1
422          )
423          SELECT MAX(id)
424          FROM __intrinsic_slice
425          WHERE track_id = (SELECT id FROM ttid);
426        """,
427        out=Csv("""
428        "MAX(id)"
429        20745
430        """))
431
432  def test_create_and_drop_perfetto_index(self):
433    return DiffTestBlueprint(
434        trace=DataPath('example_android_trace_30s.pb'),
435        query="""
436        CREATE PERFETTO INDEX idx ON __intrinsic_slice(track_id, name);
437        DROP PERFETTO INDEX idx ON __intrinsic_slice;
438
439        WITH ttid AS (
440          SELECT thread_track.id
441          FROM thread_track
442          JOIN thread USING (utid)
443          WHERE thread.name = 'android.bg'
444          LIMIT 1
445        )
446        SELECT MAX(id) FROM __intrinsic_slice
447        WHERE track_id = (SELECT id FROM ttid);
448        """,
449        out=Csv("""
450        "MAX(id)"
451        20745
452        """))
453
454  def test_winscope_proto_to_args_with_defaults_with_nested_fields(self):
455    return DiffTestBlueprint(
456        trace=Path('../parser/android/surfaceflinger_layers.textproto'),
457        query="""
458        SELECT flat_key, key, int_value, string_value, real_value FROM __intrinsic_winscope_proto_to_args_with_defaults('surfaceflinger_layer') AS sfl
459        ORDER BY sfl.base64_proto_id, key
460        LIMIT 95
461        """,
462        out=Csv("""
463        "flat_key","key","int_value","string_value","real_value"
464        "active_buffer","active_buffer","[NULL]","[NULL]","[NULL]"
465        "app_id","app_id",0,"[NULL]","[NULL]"
466        "background_blur_radius","background_blur_radius",0,"[NULL]","[NULL]"
467        "barrier_layer","barrier_layer","[NULL]","[NULL]","[NULL]"
468        "blur_regions","blur_regions","[NULL]","[NULL]","[NULL]"
469        "bounds.bottom","bounds.bottom","[NULL]","[NULL]",24000.000000
470        "bounds.left","bounds.left","[NULL]","[NULL]",-10800.000000
471        "bounds.right","bounds.right","[NULL]","[NULL]",10800.000000
472        "bounds.top","bounds.top","[NULL]","[NULL]",-24000.000000
473        "buffer_transform","buffer_transform","[NULL]","[NULL]","[NULL]"
474        "children","children[0]",4,"[NULL]","[NULL]"
475        "children","children[1]",35,"[NULL]","[NULL]"
476        "children","children[2]",43,"[NULL]","[NULL]"
477        "children","children[3]",45,"[NULL]","[NULL]"
478        "children","children[4]",44,"[NULL]","[NULL]"
479        "children","children[5]",77,"[NULL]","[NULL]"
480        "children","children[6]",87,"[NULL]","[NULL]"
481        "color.a","color.a","[NULL]","[NULL]",1.000000
482        "color.b","color.b","[NULL]","[NULL]",-1.000000
483        "color.g","color.g","[NULL]","[NULL]",-1.000000
484        "color.r","color.r","[NULL]","[NULL]",-1.000000
485        "color_transform","color_transform","[NULL]","[NULL]","[NULL]"
486        "corner_radius","corner_radius","[NULL]","[NULL]",0.000000
487        "corner_radius_crop","corner_radius_crop","[NULL]","[NULL]","[NULL]"
488        "crop.bottom","crop.bottom",-1,"[NULL]","[NULL]"
489        "crop.left","crop.left",0,"[NULL]","[NULL]"
490        "crop.right","crop.right",-1,"[NULL]","[NULL]"
491        "crop.top","crop.top",0,"[NULL]","[NULL]"
492        "curr_frame","curr_frame",0,"[NULL]","[NULL]"
493        "damage_region","damage_region","[NULL]","[NULL]","[NULL]"
494        "dataspace","dataspace","[NULL]","BT709 sRGB Full range","[NULL]"
495        "destination_frame.bottom","destination_frame.bottom",-1,"[NULL]","[NULL]"
496        "destination_frame.left","destination_frame.left",0,"[NULL]","[NULL]"
497        "destination_frame.right","destination_frame.right",-1,"[NULL]","[NULL]"
498        "destination_frame.top","destination_frame.top",0,"[NULL]","[NULL]"
499        "effective_scaling_mode","effective_scaling_mode",0,"[NULL]","[NULL]"
500        "effective_transform","effective_transform","[NULL]","[NULL]","[NULL]"
501        "final_crop","final_crop","[NULL]","[NULL]","[NULL]"
502        "flags","flags",2,"[NULL]","[NULL]"
503        "hwc_composition_type","hwc_composition_type","[NULL]","HWC_TYPE_UNSPECIFIED","[NULL]"
504        "hwc_crop","hwc_crop","[NULL]","[NULL]","[NULL]"
505        "hwc_frame","hwc_frame","[NULL]","[NULL]","[NULL]"
506        "hwc_transform","hwc_transform",0,"[NULL]","[NULL]"
507        "id","id",3,"[NULL]","[NULL]"
508        "input_window_info","input_window_info","[NULL]","[NULL]","[NULL]"
509        "invalidate","invalidate",1,"[NULL]","[NULL]"
510        "is_opaque","is_opaque",0,"[NULL]","[NULL]"
511        "is_protected","is_protected",0,"[NULL]","[NULL]"
512        "is_relative_of","is_relative_of",0,"[NULL]","[NULL]"
513        "is_trusted_overlay","is_trusted_overlay",0,"[NULL]","[NULL]"
514        "layer_stack","layer_stack",0,"[NULL]","[NULL]"
515        "metadata","metadata","[NULL]","[NULL]","[NULL]"
516        "name","name","[NULL]","Display 0 name=\"Built-in Screen\"#3","[NULL]"
517        "original_id","original_id",0,"[NULL]","[NULL]"
518        "owner_uid","owner_uid",1000,"[NULL]","[NULL]"
519        "parent","parent",0,"[NULL]","[NULL]"
520        "pixel_format","pixel_format","[NULL]","Unknown/None","[NULL]"
521        "position","position","[NULL]","[NULL]","[NULL]"
522        "queued_frames","queued_frames",0,"[NULL]","[NULL]"
523        "refresh_pending","refresh_pending",0,"[NULL]","[NULL]"
524        "relatives","relatives","[NULL]","[NULL]","[NULL]"
525        "requested_color.a","requested_color.a","[NULL]","[NULL]",1.000000
526        "requested_color.b","requested_color.b","[NULL]","[NULL]",-1.000000
527        "requested_color.g","requested_color.g","[NULL]","[NULL]",-1.000000
528        "requested_color.r","requested_color.r","[NULL]","[NULL]",-1.000000
529        "requested_corner_radius","requested_corner_radius","[NULL]","[NULL]",0.000000
530        "requested_position","requested_position","[NULL]","[NULL]","[NULL]"
531        "requested_transform.dsdx","requested_transform.dsdx","[NULL]","[NULL]",0.000000
532        "requested_transform.dsdy","requested_transform.dsdy","[NULL]","[NULL]",0.000000
533        "requested_transform.dtdx","requested_transform.dtdx","[NULL]","[NULL]",0.000000
534        "requested_transform.dtdy","requested_transform.dtdy","[NULL]","[NULL]",0.000000
535        "requested_transform.type","requested_transform.type",0,"[NULL]","[NULL]"
536        "screen_bounds.bottom","screen_bounds.bottom","[NULL]","[NULL]",24000.000000
537        "screen_bounds.left","screen_bounds.left","[NULL]","[NULL]",-10800.000000
538        "screen_bounds.right","screen_bounds.right","[NULL]","[NULL]",10800.000000
539        "screen_bounds.top","screen_bounds.top","[NULL]","[NULL]",-24000.000000
540        "shadow_radius","shadow_radius","[NULL]","[NULL]",0.000000
541        "size","size","[NULL]","[NULL]","[NULL]"
542        "source_bounds.bottom","source_bounds.bottom","[NULL]","[NULL]",24000.000000
543        "source_bounds.left","source_bounds.left","[NULL]","[NULL]",-10800.000000
544        "source_bounds.right","source_bounds.right","[NULL]","[NULL]",10800.000000
545        "source_bounds.top","source_bounds.top","[NULL]","[NULL]",-24000.000000
546        "transform.dsdx","transform.dsdx","[NULL]","[NULL]",0.000000
547        "transform.dsdy","transform.dsdy","[NULL]","[NULL]",0.000000
548        "transform.dtdx","transform.dtdx","[NULL]","[NULL]",0.000000
549        "transform.dtdy","transform.dtdy","[NULL]","[NULL]",0.000000
550        "transform.type","transform.type",0,"[NULL]","[NULL]"
551        "transparent_region","transparent_region","[NULL]","[NULL]","[NULL]"
552        "trusted_overlay","trusted_overlay","[NULL]","UNSET","[NULL]"
553        "type","type","[NULL]","[NULL]","[NULL]"
554        "visible_region","visible_region","[NULL]","[NULL]","[NULL]"
555        "window_type","window_type",0,"[NULL]","[NULL]"
556        "z","z",0,"[NULL]","[NULL]"
557        "z_order_relative_of","z_order_relative_of",0,"[NULL]","[NULL]"
558        "active_buffer","active_buffer","[NULL]","[NULL]","[NULL]"
559        """))
560
561  def test_winscope_proto_to_args_with_defaults_with_repeated_fields(self):
562    return DiffTestBlueprint(
563        trace=Path('../parser/android/surfaceflinger_layers.textproto'),
564        query="""
565        SELECT flat_key, key, int_value, string_value, real_value FROM __intrinsic_winscope_proto_to_args_with_defaults('surfaceflinger_layers_snapshot') AS sfs
566        WHERE key != "hwc_blob"
567        ORDER BY sfs.base64_proto_id DESC, key ASC
568        LIMIT 36
569        """,
570        out=Csv("""
571        "flat_key","key","int_value","string_value","real_value"
572        "displays.dpi_x","displays[0].dpi_x","[NULL]","[NULL]",0.000000
573        "displays.dpi_y","displays[0].dpi_y","[NULL]","[NULL]",0.000000
574        "displays.id","displays[0].id",4619827677550801152,"[NULL]","[NULL]"
575        "displays.is_virtual","displays[0].is_virtual",0,"[NULL]","[NULL]"
576        "displays.layer_stack","displays[0].layer_stack",0,"[NULL]","[NULL]"
577        "displays.layer_stack_space_rect.bottom","displays[0].layer_stack_space_rect.bottom",2400,"[NULL]","[NULL]"
578        "displays.layer_stack_space_rect.left","displays[0].layer_stack_space_rect.left",0,"[NULL]","[NULL]"
579        "displays.layer_stack_space_rect.right","displays[0].layer_stack_space_rect.right",1080,"[NULL]","[NULL]"
580        "displays.layer_stack_space_rect.top","displays[0].layer_stack_space_rect.top",0,"[NULL]","[NULL]"
581        "displays.name","displays[0].name","[NULL]","Common Panel","[NULL]"
582        "displays.size.h","displays[0].size.h",2400,"[NULL]","[NULL]"
583        "displays.size.w","displays[0].size.w",1080,"[NULL]","[NULL]"
584        "displays.transform.dsdx","displays[0].transform.dsdx","[NULL]","[NULL]",0.000000
585        "displays.transform.dsdy","displays[0].transform.dsdy","[NULL]","[NULL]",0.000000
586        "displays.transform.dtdx","displays[0].transform.dtdx","[NULL]","[NULL]",0.000000
587        "displays.transform.dtdy","displays[0].transform.dtdy","[NULL]","[NULL]",0.000000
588        "displays.transform.type","displays[0].transform.type",0,"[NULL]","[NULL]"
589        "displays.dpi_x","displays[1].dpi_x","[NULL]","[NULL]",0.000000
590        "displays.dpi_y","displays[1].dpi_y","[NULL]","[NULL]",0.000000
591        "displays.id","displays[1].id",4619827677550801153,"[NULL]","[NULL]"
592        "displays.is_virtual","displays[1].is_virtual",0,"[NULL]","[NULL]"
593        "displays.layer_stack","displays[1].layer_stack",0,"[NULL]","[NULL]"
594        "displays.layer_stack_space_rect.bottom","displays[1].layer_stack_space_rect.bottom",2400,"[NULL]","[NULL]"
595        "displays.layer_stack_space_rect.left","displays[1].layer_stack_space_rect.left",0,"[NULL]","[NULL]"
596        "displays.layer_stack_space_rect.right","displays[1].layer_stack_space_rect.right",1080,"[NULL]","[NULL]"
597        "displays.layer_stack_space_rect.top","displays[1].layer_stack_space_rect.top",0,"[NULL]","[NULL]"
598        "displays.name","displays[1].name","[NULL]","Common Panel","[NULL]"
599        "displays.size.h","displays[1].size.h",2400,"[NULL]","[NULL]"
600        "displays.size.w","displays[1].size.w",1080,"[NULL]","[NULL]"
601        "displays.transform","displays[1].transform","[NULL]","[NULL]","[NULL]"
602        "elapsed_realtime_nanos","elapsed_realtime_nanos",2749500341063,"[NULL]","[NULL]"
603        "excludes_composition_state","excludes_composition_state",0,"[NULL]","[NULL]"
604        "missed_entries","missed_entries",0,"[NULL]","[NULL]"
605        "vsync_id","vsync_id",24767,"[NULL]","[NULL]"
606        "where","where","[NULL]","bufferLatched","[NULL]"
607        "displays.dpi_x","displays[0].dpi_x","[NULL]","[NULL]",0.000000
608        """))
609
610  def test_winscope_proto_to_args_with_defaults_with_multiple_packets_per_proto(self):
611      return DiffTestBlueprint(
612          trace=Path('../parser/android/shell_transitions.textproto'),
613          query="""
614          SELECT key, int_value, real_value FROM __intrinsic_winscope_proto_to_args_with_defaults('__intrinsic_window_manager_shell_transition_protos') as tbl
615          ORDER BY tbl.base64_proto_id, key
616          LIMIT 53
617          """,
618          out=Csv("""
619          "key","int_value","real_value"
620          "create_time_ns",76799049027,"[NULL]"
621          "finish_time_ns",0,"[NULL]"
622          "finish_transaction_id",5604932321954,"[NULL]"
623          "flags",0,"[NULL]"
624          "merge_request_time_ns",0,"[NULL]"
625          "merge_target",0,"[NULL]"
626          "merge_time_ns",0,"[NULL]"
627          "send_time_ns",76875395422,"[NULL]"
628          "shell_abort_time_ns",0,"[NULL]"
629          "start_transaction_id",5604932321952,"[NULL]"
630          "targets","[NULL]","[NULL]"
631          "type",0,"[NULL]"
632          "wm_abort_time_ns",0,"[NULL]"
633          "create_time_ns",77854865352,"[NULL]"
634          "finish_transaction_id",5604932322159,"[NULL]"
635          "flags",0,"[NULL]"
636          "merge_request_time_ns",0,"[NULL]"
637          "merge_target",0,"[NULL]"
638          "merge_time_ns",0,"[NULL]"
639          "send_time_ns",77894307328,"[NULL]"
640          "shell_abort_time_ns",0,"[NULL]"
641          "start_transaction_id",5604932322158,"[NULL]"
642          "starting_window_remove_time_ns",0,"[NULL]"
643          "targets","[NULL]","[NULL]"
644          "type",0,"[NULL]"
645          "wm_abort_time_ns",0,"[NULL]"
646          "create_time_ns",82498121051,"[NULL]"
647          "finish_time_ns",0,"[NULL]"
648          "finish_transaction_id",5604932322347,"[NULL]"
649          "flags",0,"[NULL]"
650          "merge_request_time_ns",0,"[NULL]"
651          "merge_target",0,"[NULL]"
652          "merge_time_ns",0,"[NULL]"
653          "send_time_ns",82535513345,"[NULL]"
654          "shell_abort_time_ns",0,"[NULL]"
655          "start_transaction_id",5604932322346,"[NULL]"
656          "starting_window_remove_time_ns",0,"[NULL]"
657          "targets","[NULL]","[NULL]"
658          "type",0,"[NULL]"
659          "wm_abort_time_ns",0,"[NULL]"
660          "create_time_ns",76955664017,"[NULL]"
661          "finish_time_ns",0,"[NULL]"
662          "finish_transaction_id",5604932322029,"[NULL]"
663          "flags",0,"[NULL]"
664          "merge_request_time_ns",0,"[NULL]"
665          "send_time_ns",77277756832,"[NULL]"
666          "shell_abort_time_ns",0,"[NULL]"
667          "start_transaction_id",5604932322028,"[NULL]"
668          "starting_window_remove_time_ns",0,"[NULL]"
669          "targets","[NULL]","[NULL]"
670          "type",0,"[NULL]"
671          "wm_abort_time_ns",0,"[NULL]"
672          "starting_window_remove_time_ns",77706603918,"[NULL]"
673          """))
674
675  def test_winscope_proto_to_args_with_defaults_with_interned_strings(self):
676    return DiffTestBlueprint(
677        trace=Path('../parser/android/viewcapture.textproto'),
678        query="""
679        SELECT flat_key, key, int_value, string_value FROM __intrinsic_winscope_proto_to_args_with_defaults('__intrinsic_viewcapture_view')
680        WHERE flat_key LIKE '%_iid'
681          OR flat_key LIKE '%_name'
682          OR flat_key LIKE '%view_id'
683        ORDER BY base64_proto_id, key
684        """,
685        out=Csv("""
686        "flat_key","key","int_value","string_value"
687        "class_name","class_name","[NULL]","com.android.internal.policy.PhoneWindow@6cec234"
688        "view_id","view_id","[NULL]","NO_ID"
689        "class_name","class_name","[NULL]","com.android.internal.policy.DecorView"
690        "view_id","view_id","[NULL]","STRING DE-INTERNING ERROR"
691        "view_id_iid","view_id_iid",3,"[NULL]"
692        "class_name","class_name","[NULL]","STRING DE-INTERNING ERROR"
693        "class_name_iid","class_name_iid",3,"[NULL]"
694        "view_id","view_id","[NULL]","NO_ID"
695        """))