• 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, BinaryProto
18from python.generators.diff_tests.testing import DiffTestBlueprint, TraceInjector
19from python.generators.diff_tests.testing import TestSuite
20from python.generators.diff_tests.testing import PrintProfileProto
21
22
23class TablesSched(TestSuite):
24  # Sched table
25  def test_synth_1_filter_sched(self):
26    return DiffTestBlueprint(
27        trace=Path('../common/synth_1.py'),
28        query="""
29        SELECT ts, cpu, dur FROM sched
30        WHERE
31          cpu = 1
32          AND dur > 50
33          AND dur <= 100
34          AND ts >= 100
35          AND ts <= 400;
36        """,
37        out=Csv("""
38        "ts","cpu","dur"
39        170,1,80
40        """))
41
42  def test_android_sched_and_ps_b119496959(self):
43    return DiffTestBlueprint(
44        trace=DataPath('android_sched_and_ps.pb'),
45        query="""
46        SELECT ts, cpu FROM sched WHERE ts >= 81473797418963 LIMIT 10;
47        """,
48        out=Csv("""
49        "ts","cpu"
50        81473797824982,3
51        81473797942847,3
52        81473798135399,0
53        81473798786857,2
54        81473798875451,3
55        81473799019930,2
56        81473799079982,0
57        81473800089357,3
58        81473800144461,3
59        81473800441805,3
60        """))
61
62  def test_android_sched_and_ps_b119301023(self):
63    return DiffTestBlueprint(
64        trace=DataPath('android_sched_and_ps.pb'),
65        query="""
66        SELECT ts FROM sched
67        WHERE ts > 0.1 + 1e9
68        LIMIT 10;
69        """,
70        out=Csv("""
71        "ts"
72        81473010031230
73        81473010109251
74        81473010121751
75        81473010179772
76        81473010203886
77        81473010234720
78        81473010278522
79        81473010308470
80        81473010341386
81        81473010352792
82        """))
83
84  def test_sched_wakeup(self):
85    return DiffTestBlueprint(
86        trace=DataPath('sched_wakeup_trace.atr'),
87        query="""
88        SELECT * FROM spurious_sched_wakeup
89        ORDER BY ts LIMIT 10
90        """,
91        out=Csv("""
92        "id","type","ts","thread_state_id","irq_context","utid","waker_utid"
93        0,"spurious_sched_wakeup",1735850782904,423,0,230,1465
94        1,"spurious_sched_wakeup",1736413914899,886,0,230,1467
95        2,"spurious_sched_wakeup",1736977755745,1298,0,230,1469
96        3,"spurious_sched_wakeup",1737046900004,1473,0,1472,1473
97        4,"spurious_sched_wakeup",1737047159060,1502,0,1474,1472
98        5,"spurious_sched_wakeup",1737081636170,2992,0,1214,1319
99        6,"spurious_sched_wakeup",1737108696536,5010,0,501,557
100        7,"spurious_sched_wakeup",1737153309978,6431,0,11,506
101        8,"spurious_sched_wakeup",1737165240546,6915,0,565,499
102        9,"spurious_sched_wakeup",1737211563344,8999,0,178,1195
103        """))
104
105  def test_sched_waker_id(self):
106    return DiffTestBlueprint(
107        trace=DataPath('sched_wakeup_trace.atr'),
108        query="""
109        SELECT parent.id
110        FROM thread_state parent
111        JOIN thread_state child
112          ON parent.utid = child.waker_utid AND child.ts BETWEEN parent.ts AND parent.ts + parent.dur
113        WHERE child.id = 15750
114        UNION ALL
115        SELECT waker_id AS id FROM thread_state WHERE id = 15750
116        """,
117        out=Csv("""
118        "id"
119        15748
120        15748
121        """))
122
123  def test_raw_common_flags(self):
124    return DiffTestBlueprint(
125        trace=DataPath('sched_wakeup_trace.atr'),
126        query="""
127        SELECT id, type, ts, name, cpu, utid, arg_set_id, common_flags
128        FROM raw WHERE common_flags != 0 ORDER BY ts LIMIT 10
129        """,
130        out=Csv("""
131        "id","type","ts","name","cpu","utid","arg_set_id","common_flags"
132        3,"__intrinsic_ftrace_event",1735489788930,"sched_waking",0,300,4,1
133        4,"__intrinsic_ftrace_event",1735489812571,"sched_waking",0,300,5,1
134        5,"__intrinsic_ftrace_event",1735489833977,"sched_waking",1,305,6,1
135        8,"__intrinsic_ftrace_event",1735489876788,"sched_waking",1,297,9,1
136        9,"__intrinsic_ftrace_event",1735489879097,"sched_waking",0,304,10,1
137        12,"__intrinsic_ftrace_event",1735489933912,"sched_waking",0,428,13,1
138        14,"__intrinsic_ftrace_event",1735489972385,"sched_waking",1,232,15,1
139        17,"__intrinsic_ftrace_event",1735489999987,"sched_waking",1,232,15,1
140        19,"__intrinsic_ftrace_event",1735490039439,"sched_waking",1,298,18,1
141        20,"__intrinsic_ftrace_event",1735490042084,"sched_waking",1,298,19,1
142        """))
143
144  def test_thread_executing_span_graph(self):
145    return DiffTestBlueprint(
146        trace=DataPath('sched_wakeup_trace.atr'),
147        query="""
148        INCLUDE PERFETTO MODULE sched.thread_executing_span;
149        SELECT
150          waker_id,
151          prev_id,
152          prev_end_ts,
153          id,
154          ts,
155          end_ts,
156          is_kernel,
157          utid,
158          state,
159          blocked_function
160        FROM _wakeup_graph
161        ORDER BY ts
162        LIMIT 10
163        """,
164        out=Csv("""
165        "waker_id","prev_id","prev_end_ts","id","ts","end_ts","is_kernel","utid","state","blocked_function"
166        "[NULL]","[NULL]","[NULL]",5,1735489812571,1735489896509,0,304,"[NULL]","[NULL]"
167        6,"[NULL]","[NULL]",11,1735489876788,1735489953773,0,428,"[NULL]","[NULL]"
168        5,"[NULL]","[NULL]",12,1735489879097,1735490217277,0,243,"[NULL]","[NULL]"
169        11,"[NULL]","[NULL]",17,1735489933912,1735490587658,0,230,"[NULL]","[NULL]"
170        "[NULL]","[NULL]","[NULL]",20,1735489972385,1735489995809,0,298,"[NULL]","[NULL]"
171        "[NULL]",20,1735489995809,25,1735489999987,1735490055966,0,298,"S","[NULL]"
172        25,"[NULL]","[NULL]",28,1735490039439,1735490610238,0,421,"[NULL]","[NULL]"
173        25,"[NULL]","[NULL]",29,1735490042084,1735490068213,0,420,"[NULL]","[NULL]"
174        25,"[NULL]","[NULL]",30,1735490045825,1735491418790,0,1,"[NULL]","[NULL]"
175        17,"[NULL]","[NULL]",41,1735490544063,1735490598211,0,427,"[NULL]","[NULL]"
176        """))
177
178  def test_thread_executing_span_graph_contains_forked_states(self):
179    return DiffTestBlueprint(
180        trace=DataPath('sched_wakeup_trace.atr'),
181        query="""
182        INCLUDE PERFETTO MODULE sched.thread_executing_span;
183        SELECT
184          id,
185          waker_id,
186          prev_id
187        FROM _wakeup_graph
188          WHERE ts = 1735842081507 AND end_ts = 1735842081507 + 293868
189        """,
190        out=Csv("""
191        "id","waker_id","prev_id"
192        376,369,"[NULL]"
193        """))
194
195  def test_thread_executing_span_runnable_state_has_no_running(self):
196    return DiffTestBlueprint(
197        trace=DataPath('sched_wakeup_trace.atr'),
198        query="""
199        INCLUDE PERFETTO MODULE sched.thread_executing_span;
200        SELECT COUNT(*) AS count FROM _runnable_state WHERE state = 'Running'
201        """,
202        out=Csv("""
203        "count"
204        0
205        """))
206
207  def test_thread_executing_span_graph_has_no_null_dur(self):
208    return DiffTestBlueprint(
209        trace=DataPath('sched_wakeup_trace.atr'),
210        query="""
211        INCLUDE PERFETTO MODULE sched.thread_executing_span;
212        SELECT ts,end_ts FROM _wakeup_graph
213          WHERE end_ts IS NULL OR ts IS NULL
214        """,
215        out=Csv("""
216        "ts","end_ts"
217        """))
218
219  def test_thread_executing_span_graph_accepts_null_irq_context(self):
220    return DiffTestBlueprint(
221        trace=DataPath('sched_switch_original.pb'),
222        query="""
223        INCLUDE PERFETTO MODULE sched.thread_executing_span;
224        SELECT COUNT(*) AS count FROM _wakeup_graph
225        """,
226        out=Csv("""
227        "count"
228        17
229        """))
230
231  def test_thread_executing_span_flatten_critical_path_tasks(self):
232    return DiffTestBlueprint(
233        trace=DataPath('sched_switch_original.pb'),
234        query="""
235        INCLUDE PERFETTO MODULE sched.thread_executing_span;
236
237        CREATE PERFETTO TABLE graph AS
238        SELECT
239          id AS source_node_id,
240          COALESCE(waker_id, id) AS dest_node_id,
241          id - COALESCE(waker_id, id) AS edge_weight
242        FROM _wakeup_graph;
243
244        CREATE PERFETTO TABLE roots AS
245        SELECT
246          _wakeup_graph.id AS root_node_id,
247          _wakeup_graph.id - COALESCE(prev_id, _wakeup_graph.id) AS root_target_weight,
248          id,
249          ts,
250          end_ts,
251          utid
252        FROM _wakeup_graph LIMIT 10;
253
254        CREATE PERFETTO TABLE critical_path AS
255        SELECT * FROM graph_reachable_weight_bounded_dfs!(graph, roots, 1);
256
257        SELECT * FROM _flatten_critical_path_tasks!(critical_path);
258        """,
259        out=Csv("""
260        "ts","root_node_id","node_id","dur","node_utid","prev_end_ts"
261        807082868359903,29,29,"[NULL]",8,"[NULL]"
262        807082871734539,35,35,"[NULL]",9,"[NULL]"
263        807082871734539,38,35,45052,9,"[NULL]"
264        807082871779591,38,38,"[NULL]",5,807082871764903
265        807082878623081,45,45,"[NULL]",9,807082871805424
266        807082947156994,57,57,"[NULL]",9,807082878865945
267        807082947246838,62,62,"[NULL]",6,807082879179539
268        807082947261525,63,63,"[NULL]",12,"[NULL]"
269        807082947267463,64,64,"[NULL]",13,"[NULL]"
270        807082947278140,65,65,"[NULL]",14,"[NULL]"
271        807082947288765,66,66,"[NULL]",15,"[NULL]"
272        """))
273
274  def test_thread_executing_span_intervals_to_roots_edge_case(self):
275    return DiffTestBlueprint(
276        trace=DataPath('sched_wakeup_trace.atr'),
277        query="""
278        INCLUDE PERFETTO MODULE sched.thread_executing_span;
279
280        SELECT * FROM
281        _intervals_to_roots!((SELECT 1477 AS utid, trace_start() AS ts, trace_end() - trace_start() AS dur))
282        LIMIT 10;
283        """,
284        out=Csv("""
285        "id"
286        11889
287        11892
288        11893
289        11896
290        11897
291        11900
292        11911
293        11916
294        11917
295        11921
296        """))
297
298  def test_thread_executing_span_intervals_to_roots(self):
299    return DiffTestBlueprint(
300        trace=DataPath('sched_wakeup_trace.atr'),
301        query="""
302        INCLUDE PERFETTO MODULE sched.thread_executing_span;
303
304        SELECT * FROM
305        _intervals_to_roots!((SELECT 1477 AS utid, 1737362149192 AS ts, CAST(2e7 AS INT) AS dur))
306        LIMIT 10;
307        """,
308        out=Csv("""
309        "id"
310        11980
311        11983
312        11984
313        11989
314        11990
315        11991
316        11992
317        11993
318        12001
319        12006
320        """))
321
322  def test_thread_executing_span_flatten_critical_paths(self):
323    return DiffTestBlueprint(
324        trace=DataPath('sched_switch_original.pb'),
325        query="""
326        INCLUDE PERFETTO MODULE sched.thread_executing_span;
327
328        CREATE PERFETTO TABLE graph AS
329        SELECT
330          id AS source_node_id,
331          COALESCE(waker_id, id) AS dest_node_id,
332          id - COALESCE(waker_id, id) AS edge_weight
333        FROM _wakeup_graph;
334
335        CREATE PERFETTO TABLE roots AS
336        SELECT
337          _wakeup_graph.id AS root_node_id,
338          _wakeup_graph.id - COALESCE(prev_id, _wakeup_graph.id) AS root_target_weight,
339          id,
340          ts,
341          end_ts,
342          utid
343        FROM _wakeup_graph;
344
345        CREATE PERFETTO TABLE critical_path AS
346        SELECT * FROM graph_reachable_weight_bounded_dfs!(graph, roots, 1);
347
348        SELECT * FROM _flatten_critical_paths!(critical_path, _sleep);
349        """,
350        out=Csv("""
351        "ts","dur","utid","id","root_id","prev_end_ts","critical_path_utid","critical_path_id","critical_path_blocked_dur","critical_path_blocked_state","critical_path_blocked_function"
352        807082871764903,14688,9,35,38,"[NULL]",5,38,14688,"S","[NULL]"
353        807082947156994,351302,9,57,76,807082878865945,5,76,68858913,"S","[NULL]"
354        807083031589763,324114,21,127,130,"[NULL]",5,130,80026987,"S","[NULL]"
355        """))
356
357  def test_thread_executing_span_critical_path(self):
358    return DiffTestBlueprint(
359        trace=DataPath('sched_switch_original.pb'),
360        query="""
361        INCLUDE PERFETTO MODULE sched.thread_executing_span;
362
363        CREATE PERFETTO TABLE graph AS
364        SELECT
365          id AS source_node_id,
366          COALESCE(waker_id, id) AS dest_node_id,
367          id - COALESCE(waker_id, id) AS edge_weight
368        FROM _wakeup_graph;
369
370        CREATE PERFETTO TABLE roots AS
371        SELECT
372          _wakeup_graph.id AS root_node_id,
373          _wakeup_graph.id - COALESCE(prev_id, _wakeup_graph.id) AS root_target_weight,
374          id,
375          ts,
376          end_ts,
377          utid
378        FROM _wakeup_graph;
379
380        SELECT * FROM _critical_path!(graph, roots, _sleep);
381        """,
382        out=Csv("""
383        "ts","dur","root_id","id","utid","critical_path_utid","critical_path_id","critical_path_blocked_dur","critical_path_blocked_state","critical_path_blocked_function"
384        807082868359903,81302,29,29,8,8,"[NULL]","[NULL]","[NULL]","[NULL]"
385        807082871734539,70885,35,35,9,9,"[NULL]","[NULL]","[NULL]","[NULL]"
386        807082871764903,14688,38,35,9,5,38,14688,"S","[NULL]"
387        807082871779591,55729,38,38,5,5,"[NULL]","[NULL]","[NULL]","[NULL]"
388        807082878623081,242864,45,45,9,9,"[NULL]","[NULL]","[NULL]","[NULL]"
389        807082947156994,436354,57,57,9,9,"[NULL]","[NULL]","[NULL]","[NULL]"
390        807082947246838,1038854,62,62,6,6,"[NULL]","[NULL]","[NULL]","[NULL]"
391        807082947261525,293594,63,63,12,12,"[NULL]","[NULL]","[NULL]","[NULL]"
392        807082947267463,228958,64,64,13,13,"[NULL]","[NULL]","[NULL]","[NULL]"
393        807082947278140,54114,65,65,14,14,"[NULL]","[NULL]","[NULL]","[NULL]"
394        807082947288765,338802,66,66,15,15,"[NULL]","[NULL]","[NULL]","[NULL]"
395        807082947294182,296875,67,67,16,16,"[NULL]","[NULL]","[NULL]","[NULL]"
396        807082947156994,351302,76,57,9,5,76,68858913,"S","[NULL]"
397        807082947508296,122083,76,76,5,5,"[NULL]","[NULL]","[NULL]","[NULL]"
398        807082951822463,104427,96,96,9,9,"[NULL]","[NULL]","[NULL]","[NULL]"
399        807082959173506,215104,107,107,6,6,"[NULL]","[NULL]","[NULL]","[NULL]"
400        807083031589763,436198,127,127,21,21,"[NULL]","[NULL]","[NULL]","[NULL]"
401        807083031589763,324114,130,127,21,5,130,80026987,"S","[NULL]"
402        807083031913877,166302,130,130,5,5,"[NULL]","[NULL]","[NULL]","[NULL]"
403        807083032278825,208490,135,135,2,2,"[NULL]","[NULL]","[NULL]","[NULL]"
404        """))
405
406  def test_thread_executing_span_critical_path_by_roots(self):
407    return DiffTestBlueprint(
408        trace=DataPath('sched_switch_original.pb'),
409        query="""
410        INCLUDE PERFETTO MODULE sched.thread_executing_span;
411
412        SELECT * FROM _critical_path_by_roots!(_intervals_to_roots!((SELECT 6 AS utid, trace_start() AS ts, trace_end() - trace_start() AS dur)));
413        """,
414        out=Csv("""
415        "id","ts","dur","utid","critical_path_id","critical_path_blocked_dur","critical_path_blocked_state","critical_path_blocked_function","critical_path_utid"
416        62,807082947246838,1038854,6,"[NULL]","[NULL]","[NULL]","[NULL]",6
417        63,807082947261525,293594,12,"[NULL]","[NULL]","[NULL]","[NULL]",12
418        64,807082947267463,228958,13,"[NULL]","[NULL]","[NULL]","[NULL]",13
419        65,807082947278140,54114,14,"[NULL]","[NULL]","[NULL]","[NULL]",14
420        66,807082947288765,338802,15,"[NULL]","[NULL]","[NULL]","[NULL]",15
421        67,807082947294182,296875,16,"[NULL]","[NULL]","[NULL]","[NULL]",16
422        57,807082947156994,351302,9,76,68858913,"S","[NULL]",5
423        76,807082947508296,122083,5,"[NULL]","[NULL]","[NULL]","[NULL]",5
424        96,807082951822463,104427,9,"[NULL]","[NULL]","[NULL]","[NULL]",9
425        107,807082959173506,215104,6,"[NULL]","[NULL]","[NULL]","[NULL]",6
426        """))
427
428  def test_thread_executing_span_critical_path_by_intervals(self):
429    return DiffTestBlueprint(
430        trace=DataPath('sched_switch_original.pb'),
431        query="""
432        INCLUDE PERFETTO MODULE sched.thread_executing_span;
433
434        SELECT * FROM _critical_path_by_intervals!((SELECT 6 AS utid, trace_start() AS ts, trace_end() - trace_start() AS dur));
435        """,
436        out=Csv("""
437        "id","ts","dur","utid","critical_path_id","critical_path_blocked_dur","critical_path_blocked_state","critical_path_blocked_function","critical_path_utid"
438        62,807082947246838,1038854,6,"[NULL]","[NULL]","[NULL]","[NULL]",6
439        107,807082959173506,215104,6,"[NULL]","[NULL]","[NULL]","[NULL]",6
440        """))
441
442  def test_thread_executing_span_critical_path_utid(self):
443    return DiffTestBlueprint(
444        trace=DataPath('sched_wakeup_trace.atr'),
445        query="""
446        INCLUDE PERFETTO MODULE sched.thread_executing_span;
447        SELECT
448          id,
449          ts,
450          dur,
451          utid,
452          critical_path_id,
453          critical_path_blocked_dur,
454          critical_path_blocked_state,
455          critical_path_blocked_function,
456          critical_path_utid
457        FROM _thread_executing_span_critical_path((select utid from thread where tid = 3487), start_ts, end_ts), trace_bounds
458        ORDER BY ts
459        LIMIT 10
460        """,
461        out=Csv("""
462        "id","ts","dur","utid","critical_path_id","critical_path_blocked_dur","critical_path_blocked_state","critical_path_blocked_function","critical_path_utid"
463        11889,1737349401439,7705561,1477,"[NULL]","[NULL]","[NULL]","[NULL]",1477
464        11952,1737357107000,547583,1480,11980,547583,"S","[NULL]",1477
465        11980,1737357654583,8430762,1477,"[NULL]","[NULL]","[NULL]","[NULL]",1477
466        12052,1737366085345,50400,91,12057,50400,"S","[NULL]",1477
467        12057,1737366135745,6635927,1477,"[NULL]","[NULL]","[NULL]","[NULL]",1477
468        12081,1737372771672,12798314,1488,12254,12798314,"S","[NULL]",1477
469        12254,1737385569986,21830622,1477,"[NULL]","[NULL]","[NULL]","[NULL]",1477
470        12517,1737407400608,241267,91,12521,241267,"S","[NULL]",1477
471        12521,1737407641875,1830015,1477,"[NULL]","[NULL]","[NULL]","[NULL]",1477
472        12669,1737409471890,68590,91,12672,68590,"S","[NULL]",1477
473        """))
474
475  def test_thread_executing_span_critical_path_stack(self):
476    return DiffTestBlueprint(
477        trace=DataPath('sched_wakeup_trace.atr'),
478        query="""
479        INCLUDE PERFETTO MODULE sched.thread_executing_span_with_slice;
480        SELECT
481          id,
482          ts,
483          dur,
484          utid,
485          stack_depth,
486          name,
487          table_name,
488          critical_path_utid
489        FROM _thread_executing_span_critical_path_stack((select utid from thread where tid = 3487), start_ts, end_ts), trace_bounds
490        WHERE ts = 1737500355691
491        ORDER BY utid, id
492        """,
493        out=Csv("""
494        "id","ts","dur","utid","stack_depth","name","table_name","critical_path_utid"
495        4271,1737500355691,1456753,1477,5,"bindApplication","slice",1477
496        13120,1737500355691,1456753,1477,0,"thread_state: S","thread_state",1477
497        13120,1737500355691,1456753,1477,1,"[NULL]","thread_state",1477
498        13120,1737500355691,1456753,1477,2,"[NULL]","thread_state",1477
499        13120,1737500355691,1456753,1477,3,"process_name: com.android.providers.media.module","thread_state",1477
500        13120,1737500355691,1456753,1477,4,"thread_name: rs.media.module","thread_state",1477
501        4800,1737500355691,1456753,1498,11,"HIDL::IComponentStore::getStructDescriptors::client","slice",1477
502        4801,1737500355691,1456753,1498,12,"binder transaction","slice",1477
503        13648,1737500355691,1456753,1498,6,"blocking thread_state: R+","thread_state",1477
504        13648,1737500355691,1456753,1498,7,"blocking process_name: com.android.providers.media.module","thread_state",1477
505        13648,1737500355691,1456753,1498,8,"blocking thread_name: CodecLooper","thread_state",1477
506        13648,1737500355691,1456753,1498,9,"[NULL]","thread_state",1477
507        13648,1737500355691,1456753,1498,10,"[NULL]","thread_state",1477
508        """))
509
510  def test_thread_executing_span_critical_path_graph(self):
511    return DiffTestBlueprint(
512        trace=DataPath('sched_wakeup_trace.atr'),
513        query="""
514        INCLUDE PERFETTO MODULE sched.thread_executing_span_with_slice;
515        SELECT HEX(pprof) FROM _thread_executing_span_critical_path_graph("critical path", (select utid from thread where tid = 3487), 1737488133487, 16000), trace_bounds
516      """,
517        out=BinaryProto(
518            message_type="perfetto.third_party.perftools.profiles.Profile",
519            post_processing=PrintProfileProto,
520            contents="""
521        Sample:
522        Values: 0
523        Stack:
524        bindApplication (0x0)
525        thread_name: rs.media.module (0x0)
526        process_name: com.android.providers.media.module (0x0)
527        thread_state: R (0x0)
528        critical path (0x0)
529
530        Sample:
531        Values: 0
532        Stack:
533        bindApplication (0x0)
534        thread_name: rs.media.module (0x0)
535        process_name: com.android.providers.media.module (0x0)
536        thread_state: S (0x0)
537        critical path (0x0)
538
539        Sample:
540        Values: 0
541        Stack:
542        binder reply (0x0)
543        blocking thread_name: binder:553_3 (0x0)
544        blocking process_name: /system/bin/mediaserver (0x0)
545        blocking thread_state: Running (0x0)
546        binder transaction (0x0)
547        bindApplication (0x0)
548        thread_name: rs.media.module (0x0)
549        process_name: com.android.providers.media.module (0x0)
550        thread_state: S (0x0)
551        critical path (0x0)
552
553        Sample:
554        Values: 0
555        Stack:
556        binder transaction (0x0)
557        bindApplication (0x0)
558        thread_name: rs.media.module (0x0)
559        process_name: com.android.providers.media.module (0x0)
560        thread_state: S (0x0)
561        critical path (0x0)
562
563        Sample:
564        Values: 0
565        Stack:
566        blocking process_name: /system/bin/mediaserver (0x0)
567        blocking thread_state: Running (0x0)
568        binder transaction (0x0)
569        bindApplication (0x0)
570        thread_name: rs.media.module (0x0)
571        process_name: com.android.providers.media.module (0x0)
572        thread_state: S (0x0)
573        critical path (0x0)
574
575        Sample:
576        Values: 0
577        Stack:
578        blocking thread_name: binder:553_3 (0x0)
579        blocking process_name: /system/bin/mediaserver (0x0)
580        blocking thread_state: Running (0x0)
581        binder transaction (0x0)
582        bindApplication (0x0)
583        thread_name: rs.media.module (0x0)
584        process_name: com.android.providers.media.module (0x0)
585        thread_state: S (0x0)
586        critical path (0x0)
587
588        Sample:
589        Values: 0
590        Stack:
591        blocking thread_state: Running (0x0)
592        binder transaction (0x0)
593        bindApplication (0x0)
594        thread_name: rs.media.module (0x0)
595        process_name: com.android.providers.media.module (0x0)
596        thread_state: S (0x0)
597        critical path (0x0)
598
599        Sample:
600        Values: 0
601        Stack:
602        process_name: com.android.providers.media.module (0x0)
603        thread_state: R (0x0)
604        critical path (0x0)
605
606        Sample:
607        Values: 0
608        Stack:
609        process_name: com.android.providers.media.module (0x0)
610        thread_state: S (0x0)
611        critical path (0x0)
612
613        Sample:
614        Values: 0
615        Stack:
616        thread_name: rs.media.module (0x0)
617        process_name: com.android.providers.media.module (0x0)
618        thread_state: R (0x0)
619        critical path (0x0)
620
621        Sample:
622        Values: 0
623        Stack:
624        thread_name: rs.media.module (0x0)
625        process_name: com.android.providers.media.module (0x0)
626        thread_state: S (0x0)
627        critical path (0x0)
628
629        Sample:
630        Values: 0
631        Stack:
632        thread_state: R (0x0)
633        critical path (0x0)
634
635        Sample:
636        Values: 0
637        Stack:
638        thread_state: S (0x0)
639        critical path (0x0)
640
641        Sample:
642        Values: 1101
643        Stack:
644        binder transaction (0x0)
645        bindApplication (0x0)
646        thread_name: rs.media.module (0x0)
647        process_name: com.android.providers.media.module (0x0)
648        thread_state: R (0x0)
649        critical path (0x0)
650
651        Sample:
652        Values: 13010
653        Stack:
654        cpu: 0 (0x0)
655        binder reply (0x0)
656        blocking thread_name: binder:553_3 (0x0)
657        blocking process_name: /system/bin/mediaserver (0x0)
658        blocking thread_state: Running (0x0)
659        binder transaction (0x0)
660        bindApplication (0x0)
661        thread_name: rs.media.module (0x0)
662        process_name: com.android.providers.media.module (0x0)
663        thread_state: S (0x0)
664        critical path (0x0)
665
666        Sample:
667        Values: 1889
668        Stack:
669        cpu: 0 (0x0)
670        blocking thread_name: binder:553_3 (0x0)
671        blocking process_name: /system/bin/mediaserver (0x0)
672        blocking thread_state: Running (0x0)
673        binder transaction (0x0)
674        bindApplication (0x0)
675        thread_name: rs.media.module (0x0)
676        process_name: com.android.providers.media.module (0x0)
677        thread_state: S (0x0)
678        critical path (0x0)
679        """))
680
681  # Test machine_id ID of the sched table.
682  def test_android_sched_and_ps_machine_id(self):
683    return DiffTestBlueprint(
684        trace=DataPath('android_sched_and_ps.pb'),
685        trace_modifier=TraceInjector(['ftrace_events'], {'machine_id': 1001}),
686        query="""
687        SELECT ts, cpu.cpu, machine_id
688        FROM sched LEFT JOIN cpu USING (ucpu)
689        WHERE ts >= 81473797418963 LIMIT 10;
690        """,
691        out=Csv("""
692        "ts","cpu","machine_id"
693        81473797824982,3,1
694        81473797942847,3,1
695        81473798135399,0,1
696        81473798786857,2,1
697        81473798875451,3,1
698        81473799019930,2,1
699        81473799079982,0,1
700        81473800089357,3,1
701        81473800144461,3,1
702        81473800441805,3,1
703        """))
704
705  # Test the support of machine_id ID of the raw table.
706  def test_raw_machine_id(self):
707    return DiffTestBlueprint(
708        trace=DataPath('android_sched_and_ps.pb'),
709        trace_modifier=TraceInjector(['ftrace_events'], {'machine_id': 1001}),
710        query="""
711        SELECT count(*)
712        FROM raw LEFT JOIN cpu USING (ucpu)
713        WHERE machine_id is NULL;
714        """,
715        out=Csv("""
716        "count(*)"
717        0
718        """))
719
720  def test_sched_cpu_id(self):
721    return DiffTestBlueprint(
722        trace=DataPath('sched_switch_original.pb'),
723        query="""
724        SELECT cpu, cluster_id
725        FROM cpu
726        """,
727        out=Csv("""
728        "cpu","cluster_id"
729        0,0
730        1,0
731        2,0
732        3,0
733        4,0
734        7,0
735        """))
736
737  def test_sched_cpu_id_machine_id(self):
738    return DiffTestBlueprint(
739        trace=DataPath('sched_switch_original.pb'),
740        trace_modifier=TraceInjector(['ftrace_events'], {'machine_id': 1001}),
741        query="""
742        SELECT cpu, cluster_id, machine.raw_id as raw_machine_id
743        FROM cpu
744        JOIN machine ON cpu.machine_id = machine.id
745        """,
746        out=Csv("""
747        "cpu","cluster_id","raw_machine_id"
748        0,0,1001
749        1,0,1001
750        2,0,1001
751        3,0,1001
752        4,0,1001
753        7,0,1001
754        """))
755