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 id, ts, thread_state_id, irq_context, utid, waker_utid FROM spurious_sched_wakeup 89 ORDER BY ts LIMIT 10 90 """, 91 out=Csv(""" 92 "id","ts","thread_state_id","irq_context","utid","waker_utid" 93 0,1735850782904,423,0,230,1465 94 1,1736413914899,886,0,230,1467 95 2,1736977755745,1298,0,230,1469 96 3,1737046900004,1473,0,1472,1473 97 4,1737047159060,1502,0,1474,1472 98 5,1737081636170,2992,0,1214,1319 99 6,1737108696536,5010,0,501,557 100 7,1737153309978,6431,0,11,506 101 8,1737165240546,6915,0,565,499 102 9,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_ftrace_event_common_flags(self): 124 return DiffTestBlueprint( 125 trace=DataPath('sched_wakeup_trace.atr'), 126 query=""" 127 SELECT id, ts, name, cpu, utid, arg_set_id, common_flags 128 FROM ftrace_event 129 WHERE common_flags != 0 130 ORDER BY ts LIMIT 10 131 """, 132 out=Csv(""" 133 "id","ts","name","cpu","utid","arg_set_id","common_flags" 134 3,1735489788930,"sched_waking",0,300,21,1 135 4,1735489812571,"sched_waking",0,300,25,1 136 5,1735489833977,"sched_waking",1,305,29,1 137 8,1735489876788,"sched_waking",1,297,47,1 138 9,1735489879097,"sched_waking",0,304,51,1 139 12,1735489933912,"sched_waking",0,428,69,1 140 14,1735489972385,"sched_waking",1,232,80,1 141 17,1735489999987,"sched_waking",1,232,80,1 142 19,1735490039439,"sched_waking",1,298,98,1 143 20,1735490042084,"sched_waking",1,298,102,1 144 """)) 145 146 def test_thread_executing_span_graph(self): 147 return DiffTestBlueprint( 148 trace=DataPath('sched_wakeup_trace.atr'), 149 query=""" 150 INCLUDE PERFETTO MODULE sched.thread_executing_span; 151 SELECT 152 waker_id, 153 prev_id, 154 ts - idle_dur AS idle_ts, 155 id, 156 ts, 157 ts + dur AS next_idle_ts , 158 is_idle_reason_self, 159 utid, 160 idle_state, 161 idle_reason 162 FROM _wakeup_graph 163 ORDER BY ts 164 LIMIT 10 165 """, 166 out=Csv(""" 167 "waker_id","prev_id","idle_ts","id","ts","next_idle_ts","is_idle_reason_self","utid","idle_state","idle_reason" 168 "[NULL]","[NULL]","[NULL]",5,1735489812571,1735489896509,1,304,"[NULL]","[NULL]" 169 "[NULL]","[NULL]","[NULL]",6,1735489833977,1735489886440,1,297,"[NULL]","[NULL]" 170 6,"[NULL]","[NULL]",11,1735489876788,1735489953773,0,428,"[NULL]","[NULL]" 171 5,"[NULL]","[NULL]",12,1735489879097,1735490217277,0,243,"[NULL]","[NULL]" 172 11,"[NULL]","[NULL]",17,1735489933912,1735490587658,0,230,"[NULL]","[NULL]" 173 "[NULL]","[NULL]","[NULL]",20,1735489972385,1735489995809,1,298,"[NULL]","[NULL]" 174 "[NULL]",20,1735489995809,25,1735489999987,1735490055966,1,298,"S","[NULL]" 175 25,"[NULL]","[NULL]",28,1735490039439,1735490610238,0,421,"[NULL]","[NULL]" 176 25,"[NULL]","[NULL]",29,1735490042084,1735490068213,0,420,"[NULL]","[NULL]" 177 25,"[NULL]","[NULL]",30,1735490045825,1735491418790,0,1,"[NULL]","[NULL]" 178 """)) 179 180 def test_thread_executing_span_graph_contains_forked_states(self): 181 return DiffTestBlueprint( 182 trace=DataPath('sched_wakeup_trace.atr'), 183 query=""" 184 INCLUDE PERFETTO MODULE sched.thread_executing_span; 185 SELECT 186 id, 187 waker_id, 188 prev_id 189 FROM _wakeup_graph 190 WHERE ts = 1735842081507 AND ts + dur = 1735842081507 + 293868 191 """, 192 out=Csv(""" 193 "id","waker_id","prev_id" 194 376,369,"[NULL]" 195 """)) 196 197 def test_thread_executing_span_runnable_state_has_no_running(self): 198 return DiffTestBlueprint( 199 trace=DataPath('sched_wakeup_trace.atr'), 200 query=""" 201 INCLUDE PERFETTO MODULE sched.thread_executing_span; 202 SELECT COUNT(*) AS count FROM _runnable_state WHERE state = 'Running' 203 """, 204 out=Csv(""" 205 "count" 206 0 207 """)) 208 209 def test_thread_executing_span_graph_has_no_null_dur(self): 210 return DiffTestBlueprint( 211 trace=DataPath('sched_wakeup_trace.atr'), 212 query=""" 213 INCLUDE PERFETTO MODULE sched.thread_executing_span; 214 SELECT ts,dur FROM _wakeup_graph 215 WHERE dur IS NULL OR ts IS NULL 216 """, 217 out=Csv(""" 218 "ts","dur" 219 """)) 220 221 def test_thread_executing_span_graph_accepts_null_irq_context(self): 222 return DiffTestBlueprint( 223 trace=DataPath('sched_switch_original.pb'), 224 query=""" 225 INCLUDE PERFETTO MODULE sched.thread_executing_span; 226 SELECT COUNT(*) AS count FROM _wakeup_graph 227 """, 228 out=Csv(""" 229 "count" 230 30 231 """)) 232 233 def test_thread_executing_span_intervals_to_roots_edge_case(self): 234 return DiffTestBlueprint( 235 trace=DataPath('sched_wakeup_trace.atr'), 236 query=""" 237 INCLUDE PERFETTO MODULE sched.thread_executing_span; 238 239 SELECT * FROM 240 _intervals_to_roots!((SELECT 1477 AS utid, trace_start() AS ts, trace_end() - trace_start() AS dur), _wakeup_graph) 241 ORDER BY root_node_id 242 LIMIT 10; 243 """, 244 out=Csv(""" 245 "root_node_id","capacity" 246 11889,0 247 11980,91 248 12057,77 249 12254,197 250 12521,267 251 12672,151 252 12796,124 253 12802,6 254 12827,25 255 12833,6 256 """)) 257 258 def test_thread_executing_span_intervals_to_roots(self): 259 return DiffTestBlueprint( 260 trace=DataPath('sched_wakeup_trace.atr'), 261 query=""" 262 INCLUDE PERFETTO MODULE sched.thread_executing_span; 263 264 SELECT * FROM 265 _intervals_to_roots!((SELECT 1477 AS utid, 1737362149192 AS ts, CAST(2e7 AS INT) AS dur), _wakeup_graph) 266 ORDER BY root_node_id 267 LIMIT 10; 268 """, 269 out=Csv(""" 270 "root_node_id","capacity" 271 11980,91 272 12057,77 273 12254,197 274 """)) 275 276 def test_thread_executing_span_flatten_critical_paths(self): 277 return DiffTestBlueprint( 278 trace=DataPath('sched_switch_original.pb'), 279 query=""" 280 INCLUDE PERFETTO MODULE sched.thread_executing_span; 281 282 CREATE PERFETTO TABLE graph AS 283 SELECT 284 id AS source_node_id, 285 COALESCE(waker_id, id) AS dest_node_id, 286 id - COALESCE(waker_id, id) AS edge_weight 287 FROM _wakeup_graph; 288 289 CREATE PERFETTO TABLE roots AS 290 SELECT 291 _wakeup_graph.id AS root_node_id, 292 _wakeup_graph.id - COALESCE(prev_id, _wakeup_graph.id) AS root_target_weight, 293 id, 294 ts, 295 dur, 296 utid 297 FROM _wakeup_graph; 298 299 CREATE PERFETTO TABLE critical_path AS 300 SELECT root_node_id AS root_id, node_id AS id, root_node_id AS parent_id FROM graph_reachable_weight_bounded_dfs!(graph, roots, 1); 301 302 SELECT * FROM _critical_path_to_intervals!(critical_path, _wakeup_graph); 303 """, 304 out=Csv(""" 305 "ts","dur","id","root_id" 306 807082871764903,14688,35,38 307 807082871805424,6817657,38,45 308 807082947223556,23282,60,62 309 807082947156994,351302,57,76 310 807082947593348,4229115,76,96 311 807082959078401,95105,105,107 312 807082951886890,79702873,1,130 313 807083031589763,324114,127,130 314 807082947219546,85059279,1,135 315 """)) 316 317 def test_thread_executing_span_critical_path(self): 318 return DiffTestBlueprint( 319 trace=DataPath('sched_switch_original.pb'), 320 query=""" 321 INCLUDE PERFETTO MODULE sched.thread_executing_span; 322 323 SELECT * FROM _critical_path_intervals!(_wakeup_kernel_edges, (SELECT id AS root_node_id, id - COALESCE(prev_id, id) AS capacity FROM _wakeup_graph), _wakeup_graph) ORDER BY root_id; 324 """, 325 out=Csv(""" 326 "root_id","id","ts","dur" 327 1,1,807082862885423,169601892 328 2,2,807082862913183,280521 329 13,13,807082864992767,6772136 330 14,14,807082865019382,14160157 331 17,17,807082865084902,272865 332 29,29,807082868359903,81302 333 35,35,807082871734539,70885 334 38,35,807082871764903,14688 335 38,38,807082871779591,6869792 336 45,38,807082871805424,6817657 337 45,45,807082878623081,242864 338 55,55,807082946856213,609219 339 57,57,807082947156994,436354 340 60,60,807082947223556,83577300 341 62,60,807082947223556,23282 342 62,62,807082947246838,2000260 343 63,63,807082947261525,293594 344 64,64,807082947267463,228958 345 65,65,807082947278140,54114 346 66,66,807082947288765,338802 347 67,67,807082947294182,296875 348 76,57,807082947156994,351302 349 76,76,807082947508296,4378594 350 93,93,807082951711161,2494011 351 96,76,807082947593348,4229115 352 96,96,807082951822463,104427 353 105,105,807082959078401,184115 354 107,105,807082959078401,95105 355 107,107,807082959173506,73362507 356 111,111,807082962662412,149011 357 114,114,807082967942309,334114 358 127,127,807083031589763,436198 359 130,1,807082951886890,79702873 360 130,127,807083031589763,324114 361 130,130,807083031913877,166302 362 135,1,807082947219546,85059279 363 135,135,807083032278825,208490 364 139,139,807083032634138,340625 365 142,142,807083032991378,89218 366 """)) 367 368 def test_thread_executing_span_critical_path_by_roots(self): 369 return DiffTestBlueprint( 370 trace=DataPath('sched_switch_original.pb'), 371 query=""" 372 INCLUDE PERFETTO MODULE sched.thread_executing_span; 373 374 SELECT * 375 FROM _critical_path_by_roots!( 376 _intervals_to_roots!( 377 (SELECT 6 AS utid, trace_start() AS ts, trace_end() - trace_start() AS dur), 378 _wakeup_graph), 379 _wakeup_graph); 380 """, 381 out=Csv(""" 382 "root_id","id","ts","dur" 383 14,14,807082865019382,14160157 384 62,60,807082947223556,23282 385 62,62,807082947246838,2000260 386 107,105,807082959078401,95105 387 107,139,807082959173506,73362507 388 139,139,807083032536013,98125 389 139,142,807083032634138,340625 390 142,142,807083032974763,16615 391 142,142,807083032991378,89218 392 """)) 393 394 def test_thread_executing_span_critical_path_by_intervals(self): 395 return DiffTestBlueprint( 396 trace=DataPath('sched_switch_original.pb'), 397 query=""" 398 INCLUDE PERFETTO MODULE sched.thread_executing_span; 399 400 SELECT root_utid, root_id, id, ts, dur, utid 401 FROM _critical_path_by_intervals!( 402 (SELECT 6 AS utid, trace_start() AS ts, trace_end() - trace_start() AS dur), 403 _wakeup_graph) 404 ORDER BY root_id, ts; 405 """, 406 out=Csv(""" 407 "root_utid","root_id","id","ts","dur","utid" 408 6,14,14,807082865019382,14160157,6 409 6,62,60,807082947223556,23282,11 410 6,62,62,807082947246838,2000260,6 411 6,107,105,807082959078401,95105,18 412 6,107,139,807082959173506,73362507,6 413 6,139,139,807083032536013,98125,6 414 6,139,142,807083032634138,340625,6 415 6,142,142,807083032974763,16615,6 416 6,142,142,807083032991378,89218,6 417 """)) 418 419 def test_thread_executing_span_critical_path_utid(self): 420 return DiffTestBlueprint( 421 trace=DataPath('sched_wakeup_trace.atr'), 422 query=""" 423 INCLUDE PERFETTO MODULE sched.thread_executing_span; 424 SELECT 425 root_id, 426 root_utid, 427 id, 428 ts, 429 dur, 430 utid 431 FROM _thread_executing_span_critical_path((select utid from thread where tid = 3487), start_ts, end_ts), trace_bounds 432 ORDER BY ts 433 LIMIT 10 434 """, 435 out=Csv(""" 436 "root_id","root_utid","id","ts","dur","utid" 437 11889,1477,11889,1737349401439,7705561,1477 438 11980,1477,11952,1737357107000,547583,1480 439 11980,1477,11980,1737357654583,8430762,1477 440 12057,1477,12052,1737366085345,50400,91 441 12057,1477,12057,1737366135745,6635927,1477 442 12254,1477,12251,1737372771672,12594070,1488 443 12254,1477,12251,1737385365742,204244,1488 444 12254,1477,12254,1737385569986,21830622,1477 445 12521,1477,12517,1737407400608,241267,91 446 12521,1477,12521,1737407641875,1830015,1477 447 """)) 448 449 def test_thread_executing_span_critical_path_stack(self): 450 return DiffTestBlueprint( 451 trace=DataPath('sched_wakeup_trace.atr'), 452 query=""" 453 INCLUDE PERFETTO MODULE sched.thread_executing_span_with_slice; 454 SELECT 455 id, 456 ts, 457 dur, 458 utid, 459 stack_depth, 460 name, 461 table_name, 462 root_utid 463 FROM _thread_executing_span_critical_path_stack((select utid from thread where tid = 3487), start_ts, end_ts), trace_bounds 464 WHERE ts = 1737500355691 465 ORDER BY utid, id 466 """, 467 out=Csv(""" 468 "id","ts","dur","utid","stack_depth","name","table_name","root_utid" 469 4271,1737500355691,1456753,1477,5,"bindApplication","slice",1477 470 13120,1737500355691,1456753,1477,0,"thread_state: S","thread_state",1477 471 13120,1737500355691,1456753,1477,1,"[NULL]","thread_state",1477 472 13120,1737500355691,1456753,1477,2,"[NULL]","thread_state",1477 473 13120,1737500355691,1456753,1477,3,"process_name: com.android.providers.media.module","thread_state",1477 474 13120,1737500355691,1456753,1477,4,"thread_name: rs.media.module","thread_state",1477 475 4800,1737500355691,1456753,1498,11,"HIDL::IComponentStore::getStructDescriptors::client","slice",1477 476 4801,1737500355691,1456753,1498,12,"binder transaction","slice",1477 477 13648,1737500355691,1456753,1498,6,"blocking thread_state: R+","thread_state",1477 478 13648,1737500355691,1456753,1498,7,"blocking process_name: com.android.providers.media.module","thread_state",1477 479 13648,1737500355691,1456753,1498,8,"blocking thread_name: CodecLooper","thread_state",1477 480 13648,1737500355691,1456753,1498,9,"[NULL]","thread_state",1477 481 13648,1737500355691,1456753,1498,10,"[NULL]","thread_state",1477 482 """)) 483 484 def test_thread_executing_span_critical_path_graph(self): 485 return DiffTestBlueprint( 486 trace=DataPath('sched_wakeup_trace.atr'), 487 query=""" 488 INCLUDE PERFETTO MODULE sched.thread_executing_span_with_slice; 489 SELECT HEX(pprof) FROM _thread_executing_span_critical_path_graph("critical path", (select utid from thread where tid = 3487), 1737488133487, 16000), trace_bounds 490 """, 491 out=BinaryProto( 492 message_type="perfetto.third_party.perftools.profiles.Profile", 493 post_processing=PrintProfileProto, 494 contents=""" 495 Sample: 496 Values: 0 497 Stack: 498 bindApplication (0x0) 499 thread_name: rs.media.module (0x0) 500 process_name: com.android.providers.media.module (0x0) 501 thread_state: R (0x0) 502 critical path (0x0) 503 504 Sample: 505 Values: 0 506 Stack: 507 bindApplication (0x0) 508 thread_name: rs.media.module (0x0) 509 process_name: com.android.providers.media.module (0x0) 510 thread_state: S (0x0) 511 critical path (0x0) 512 513 Sample: 514 Values: 0 515 Stack: 516 binder reply (0x0) 517 blocking thread_name: binder:553_3 (0x0) 518 blocking process_name: /system/bin/mediaserver (0x0) 519 blocking thread_state: Running (0x0) 520 binder transaction (0x0) 521 bindApplication (0x0) 522 thread_name: rs.media.module (0x0) 523 process_name: com.android.providers.media.module (0x0) 524 thread_state: S (0x0) 525 critical path (0x0) 526 527 Sample: 528 Values: 0 529 Stack: 530 binder transaction (0x0) 531 bindApplication (0x0) 532 thread_name: rs.media.module (0x0) 533 process_name: com.android.providers.media.module (0x0) 534 thread_state: S (0x0) 535 critical path (0x0) 536 537 Sample: 538 Values: 0 539 Stack: 540 blocking process_name: /system/bin/mediaserver (0x0) 541 blocking thread_state: Running (0x0) 542 binder transaction (0x0) 543 bindApplication (0x0) 544 thread_name: rs.media.module (0x0) 545 process_name: com.android.providers.media.module (0x0) 546 thread_state: S (0x0) 547 critical path (0x0) 548 549 Sample: 550 Values: 0 551 Stack: 552 blocking thread_name: binder:553_3 (0x0) 553 blocking process_name: /system/bin/mediaserver (0x0) 554 blocking thread_state: Running (0x0) 555 binder transaction (0x0) 556 bindApplication (0x0) 557 thread_name: rs.media.module (0x0) 558 process_name: com.android.providers.media.module (0x0) 559 thread_state: S (0x0) 560 critical path (0x0) 561 562 Sample: 563 Values: 0 564 Stack: 565 blocking thread_state: Running (0x0) 566 binder transaction (0x0) 567 bindApplication (0x0) 568 thread_name: rs.media.module (0x0) 569 process_name: com.android.providers.media.module (0x0) 570 thread_state: S (0x0) 571 critical path (0x0) 572 573 Sample: 574 Values: 0 575 Stack: 576 process_name: com.android.providers.media.module (0x0) 577 thread_state: R (0x0) 578 critical path (0x0) 579 580 Sample: 581 Values: 0 582 Stack: 583 process_name: com.android.providers.media.module (0x0) 584 thread_state: S (0x0) 585 critical path (0x0) 586 587 Sample: 588 Values: 0 589 Stack: 590 thread_name: rs.media.module (0x0) 591 process_name: com.android.providers.media.module (0x0) 592 thread_state: R (0x0) 593 critical path (0x0) 594 595 Sample: 596 Values: 0 597 Stack: 598 thread_name: rs.media.module (0x0) 599 process_name: com.android.providers.media.module (0x0) 600 thread_state: S (0x0) 601 critical path (0x0) 602 603 Sample: 604 Values: 0 605 Stack: 606 thread_state: R (0x0) 607 critical path (0x0) 608 609 Sample: 610 Values: 0 611 Stack: 612 thread_state: S (0x0) 613 critical path (0x0) 614 615 Sample: 616 Values: 1101 617 Stack: 618 binder transaction (0x0) 619 bindApplication (0x0) 620 thread_name: rs.media.module (0x0) 621 process_name: com.android.providers.media.module (0x0) 622 thread_state: R (0x0) 623 critical path (0x0) 624 625 Sample: 626 Values: 13010 627 Stack: 628 cpu: 0 (0x0) 629 binder reply (0x0) 630 blocking thread_name: binder:553_3 (0x0) 631 blocking process_name: /system/bin/mediaserver (0x0) 632 blocking thread_state: Running (0x0) 633 binder transaction (0x0) 634 bindApplication (0x0) 635 thread_name: rs.media.module (0x0) 636 process_name: com.android.providers.media.module (0x0) 637 thread_state: S (0x0) 638 critical path (0x0) 639 640 Sample: 641 Values: 1889 642 Stack: 643 cpu: 0 (0x0) 644 blocking thread_name: binder:553_3 (0x0) 645 blocking process_name: /system/bin/mediaserver (0x0) 646 blocking thread_state: Running (0x0) 647 binder transaction (0x0) 648 bindApplication (0x0) 649 thread_name: rs.media.module (0x0) 650 process_name: com.android.providers.media.module (0x0) 651 thread_state: S (0x0) 652 critical path (0x0) 653 """)) 654 655 # Test machine_id ID of the sched table. 656 def test_android_sched_and_ps_machine_id(self): 657 return DiffTestBlueprint( 658 trace=DataPath('android_sched_and_ps.pb'), 659 trace_modifier=TraceInjector(['ftrace_events'], {'machine_id': 1001}), 660 query=""" 661 SELECT ts, cpu.cpu, machine_id 662 FROM sched LEFT JOIN cpu USING (ucpu) 663 WHERE ts >= 81473797418963 LIMIT 10; 664 """, 665 out=Csv(""" 666 "ts","cpu","machine_id" 667 81473797824982,3,1 668 81473797942847,3,1 669 81473798135399,0,1 670 81473798786857,2,1 671 81473798875451,3,1 672 81473799019930,2,1 673 81473799079982,0,1 674 81473800089357,3,1 675 81473800144461,3,1 676 81473800441805,3,1 677 """)) 678 679 # Test the support of machine_id ID of the raw table. 680 def test_ftrace_event_machine_id(self): 681 return DiffTestBlueprint( 682 trace=DataPath('android_sched_and_ps.pb'), 683 trace_modifier=TraceInjector(['ftrace_events'], {'machine_id': 1001}), 684 query=""" 685 SELECT count(*) 686 FROM ftrace_event LEFT JOIN cpu USING (ucpu) 687 WHERE machine_id is NULL; 688 """, 689 out=Csv(""" 690 "count(*)" 691 0 692 """)) 693 694 def test_sched_cpu_id(self): 695 return DiffTestBlueprint( 696 trace=DataPath('sched_switch_original.pb'), 697 query=""" 698 SELECT cpu, cluster_id 699 FROM cpu 700 """, 701 out=Csv(""" 702 "cpu","cluster_id" 703 0,0 704 1,0 705 2,0 706 3,0 707 4,0 708 7,0 709 """)) 710 711 def test_sched_cpu_id_machine_id(self): 712 return DiffTestBlueprint( 713 trace=DataPath('sched_switch_original.pb'), 714 trace_modifier=TraceInjector(['ftrace_events'], {'machine_id': 1001}), 715 query=""" 716 SELECT cpu, cluster_id, machine.raw_id as raw_machine_id 717 FROM cpu 718 JOIN machine ON cpu.machine_id = machine.id 719 """, 720 out=Csv(""" 721 "cpu","cluster_id","raw_machine_id" 722 0,0,1001 723 1,0,1001 724 2,0,1001 725 3,0,1001 726 4,0,1001 727 7,0,1001 728 """)) 729 730 def test_sched_with_thread_process(self): 731 return DiffTestBlueprint( 732 trace=DataPath('sched_wakeup_trace.atr'), 733 query=""" 734 INCLUDE PERFETTO MODULE sched.with_context; 735 SELECT id, ts, dur, process_name, thread_name 736 FROM sched_with_thread_process 737 WHERE process_name IS NOT NULL 738 ORDER BY id 739 LIMIT 10; 740 """, 741 out=Csv(""" 742 "id","ts","dur","process_name","thread_name" 743 0,1735489352733,126010,"/system/bin/traced","traced" 744 2,1735489730796,123226,"/system/bin/logd","logd.writer" 745 3,1735489844255,42185,"logcat","logcat" 746 4,1735489854022,42487,"/system/bin/logd","logd.reader.per" 747 5,1735489886440,89626,"/system/bin/traced_probes","traced_probes" 748 6,1735489896509,57264,"/apex/com.android.adbd/bin/adbd","shell svc 3468" 749 7,1735489953773,263504,"/system/bin/logcat","logcat" 750 8,1735489976066,19743,"/system/bin/init","init" 751 9,1735489995809,6031,"/system/bin/traced_probes","traced_probes" 752 10,1735490001840,54126,"/system/bin/init","init" 753 """)) 754