• 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 Atrace(TestSuite):
23  # Match legacy Catapult behaviour when we see multiple S events b2b with the
24  # cookie name and upid.
25  def test_android_b2b_async_begin_list_slices(self):
26    return DiffTestBlueprint(
27        trace=Path('android_b2b_async_begin.textproto'),
28        query="""
29        SELECT ts, dur, name
30        FROM slice;
31        """,
32        out=Csv("""
33        "ts","dur","name"
34        1000,30,"multistart"
35        1015,45,"multistart"
36        1030,20,"multistart"
37        """))
38
39  # Android userspace async slices
40  def test_process_track_slices_android_async_slice(self):
41    return DiffTestBlueprint(
42        trace=TextProto(r"""
43        packet {
44          ftrace_events {
45            cpu: 3
46            event {
47              timestamp: 74289018336
48              pid: 4064
49              print {
50                ip: 18446743562018522420
51                buf: "S|1204|launching: com.android.chrome|0\n"
52              }
53            }
54          }
55        }
56        packet {
57          ftrace_events {
58            cpu: 2
59            event {
60              timestamp: 74662603008
61              pid: 1257
62              print {
63                ip: 18446743562018522420
64                buf: "F|1204|launching: com.android.chrome|0\n"
65              }
66            }
67          }
68        }
69        """),
70        query="""
71        SELECT
72          ts,
73          dur,
74          pid,
75          slice.name AS slice_name,
76          process_track.name AS track_name
77        FROM slice
78        JOIN process_track ON slice.track_id = process_track.id
79        JOIN process USING (upid);
80        """,
81        out=Path('process_track_slices_android_async_slice.out'))
82
83  def test_async_track_atrace_process_track_slices(self):
84    return DiffTestBlueprint(
85        trace=Path('async_track_atrace.py'),
86        query="""
87        SELECT
88          ts,
89          dur,
90          pid,
91          slice.name AS slice_name,
92          process_track.name AS track_name
93        FROM slice
94        JOIN process_track ON slice.track_id = process_track.id
95        JOIN process USING (upid);
96        """,
97        out=Csv("""
98        "ts","dur","pid","slice_name","track_name"
99        50,25,1,"ev","track"
100        55,15,1,"ev","track"
101        60,5,2,"ev","track"
102        """))
103
104  # Resolving slice nesting issues when tracing both atrace and sys_write
105  def test_sys_write_and_atrace(self):
106    return DiffTestBlueprint(
107        trace=Path('sys_write_and_atrace.py'),
108        query="""
109        SELECT slice.ts, slice.dur, slice.name, slice.depth
110        FROM slice
111        JOIN thread_track ON (slice.track_id = thread_track.id)
112        JOIN thread USING (utid)
113        WHERE tid = 42;
114        """,
115        out=Csv("""
116        "ts","dur","name","depth"
117        100,100,"sys_write",0
118        300,50,"sys_write",0
119        350,300,"test",0
120        600,50,"sys_write",1
121        """))
122