aboutsummaryrefslogtreecommitdiff
path: root/test/trace_processor/diff_tests/slices/tests.py
blob: d03cfff2f94ed6330822cca51b5d5389e80073c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python3
# Copyright (C) 2023 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License a
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from python.generators.diff_tests.testing import Path, DataPath, Metric
from python.generators.diff_tests.testing import Csv, Json, TextProto, BinaryProto
from python.generators.diff_tests.testing import DiffTestBlueprint
from python.generators.diff_tests.testing import TestSuite
from google.protobuf import text_format


class Slices(TestSuite):

  def test_thread_slice(self):
    return DiffTestBlueprint(
        trace=Path('trace.py'),
        query="""
        SELECT import('common.slices');

        SELECT name, ts, dur, depth, thread_name, tid, process_name, pid
        FROM thread_slice;
      """,
        out=Csv("""
        "name","ts","dur","depth","thread_name","tid","process_name","pid"
        "ThreadSlice",5,6,0,"Thread",5,"Process",3
      """))

  def test_process_slice(self):
    return DiffTestBlueprint(
        trace=Path('trace.py'),
        query="""
        SELECT import('common.slices');

        SELECT name, ts, dur, depth, process_name, pid
        FROM process_slice;
      """,
        out=Csv("""
        "name","ts","dur","depth","process_name","pid"
        "ProcessSlice",3,4,0,"Process",3
      """))

  def test_slice_with_process_and_thread_info(self):
    return DiffTestBlueprint(
        trace=Path('trace.py'),
        query="""
        SELECT import('experimental.slices');

        SELECT name, ts, dur, depth, thread_name, tid, process_name, pid
        FROM experimental_slice_with_thread_and_process_info;
      """,
        out=Csv("""
        "name","ts","dur","depth","thread_name","tid","process_name","pid"
        "AsyncSlice",1,2,0,"[NULL]","[NULL]","[NULL]","[NULL]"
        "ProcessSlice",3,4,0,"[NULL]","[NULL]","Process",3
        "ThreadSlice",5,6,0,"Thread",5,"Process",3
      """))

  # Common functions
  def test_has_descendant_slice_with_name_true(self):
    return DiffTestBlueprint(
        # We need a trace with a large number of non-chrome slices, so that the
        # reliable range is affected by their filtering.
        trace=DataPath('chrome_input_with_frame_view.pftrace'),
        query="""
        SELECT IMPORT('common.slices');

        SELECT
          HAS_DESCENDANT_SLICE_WITH_NAME(
            (SELECT id from slice where dur = 46046000),
            'SwapEndToPresentationCompositorFrame') AS has_descendant;
        """,
        out=Csv("""
        "has_descendant"
        1
        """))

  def test_has_descendant_slice_with_name_false(self):
    return DiffTestBlueprint(
        # We need a trace with a large number of non-chrome slices, so that the
        # reliable range is affected by their filtering.
        trace=DataPath('chrome_input_with_frame_view.pftrace'),
        query="""
        SELECT IMPORT('common.slices');

        SELECT
          HAS_DESCENDANT_SLICE_WITH_NAME(
            (SELECT id from slice where dur = 11666000),
            'SwapEndToPresentationCompositorFrame') AS has_descendant;
        """,
        out=Csv("""
        "has_descendant"
        0
        """))

  def test_descendant_slice_null(self):
    return DiffTestBlueprint(
        # We need a trace with a large number of non-chrome slices, so that the
        # reliable range is affected by their filtering.
        trace=DataPath('chrome_input_with_frame_view.pftrace'),
        query="""
        SELECT IMPORT('common.slices');

        SELECT
          DESCENDANT_SLICE_END(
            (SELECT id from slice where dur = 11666000),
            'SwapEndToPresentationCompositorFrame') AS end_ts;
        """,
        out=Csv("""
        "end_ts"
        "[NULL]"
        """))

  def test_descendant_slice(self):
    return DiffTestBlueprint(
        # We need a trace with a large number of non-chrome slices, so that the
        # reliable range is affected by their filtering.
        trace=DataPath('chrome_input_with_frame_view.pftrace'),
        query="""
        SELECT IMPORT('common.slices');

        SELECT
          DESCENDANT_SLICE_END(
            (SELECT id from slice where dur = 46046000),
            'SwapEndToPresentationCompositorFrame') AS end_ts;
        """,
        out=Csv("""
        "end_ts"
        174797566610797
        """))

  def test_slice_flattened(self):
    return DiffTestBlueprint(
        trace=DataPath('chrome_input_with_frame_view.pftrace'),
        query="""
        SELECT import('experimental.flat_slices');

        SELECT e.name, e.ts, e.dur, e.depth
        FROM experimental_slice_flattened e
        JOIN thread_track ON e.track_id = thread_track.id
        JOIN thread USING(utid)
        WHERE thread.tid = 30944;
      """,
        out=Csv("""
        "name","ts","dur","depth"
        "ThreadControllerImpl::RunTask",174793737042797,3937000,0
        "ThreadControllerImpl::RunTask",174793741016797,5930000,0
        "ThreadControllerImpl::RunTask",174793747000797,47000,0
        "Receive mojo message",174793747047797,136000,1
        "ThreadControllerImpl::RunTask",174793747183797,17000,0
        "Looper.dispatch: android.os.Handler(Kx3@57873a8)",174793747546797,119000,0
        "ThreadControllerImpl::RunTask",174796099970797,186000,0
        "Looper.dispatch: jy3(null)",174800056530797,1368000,0
        "ThreadControllerImpl::RunTask",174800107962797,132000,0
      """))