1-- 2-- Copyright 2024 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 at 7-- 8-- https://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 16INCLUDE PERFETTO MODULE prelude.after_eof.views; 17 18-- Lists all metrics built-into trace processor. 19CREATE PERFETTO VIEW trace_metrics( 20 -- The name of the metric. 21 name STRING 22) AS 23SELECT name FROM _trace_metrics; 24 25-- Definition of `trace_bounds` table. The values are being filled by Trace 26-- Processor when parsing the trace. 27-- It is recommended to depend on the `trace_start()` and `trace_end()` 28-- functions rather than directly on `trace_bounds`. 29CREATE PERFETTO VIEW trace_bounds( 30 -- First ts in the trace. 31 start_ts TIMESTAMP, 32 -- End of the trace. 33 end_ts TIMESTAMP 34) AS 35SELECT start_ts, end_ts FROM _trace_bounds; 36 37-- Tracks are a fundamental concept in trace processor and represent a 38-- "timeline" for events of the same type and with the same context. See 39-- https://perfetto.dev/docs/analysis/trace-processor#tracks for a more 40-- detailed explanation, with examples. 41CREATE PERFETTO VIEW track ( 42 -- Unique identifier for this track. Identical to |track_id|, prefer using 43 -- |track_id| instead. 44 id ID, 45 -- The name of the "most-specific" child table containing this row. 46 type STRING, 47 -- Name of the track; can be null for some types of tracks (e.g. thread 48 -- tracks). 49 name STRING, 50 -- The classification of a track indicates the "type of data" the track 51 -- contains. 52 -- 53 -- Every track is uniquely identified by the the combination of the 54 -- classification and a set of dimensions: classifications allow identifying 55 -- a set of tracks with the same type of data within the whole universe of 56 -- tracks while dimensions allow distinguishing between different tracks in 57 -- that set. 58 classification STRING, 59 -- The dimensions of the track which uniquely identify the track within a 60 -- given classification. 61 -- 62 -- Join with the `args` table or use the `EXTRACT_ARG` helper function to 63 -- expand the args. 64 dimension_arg_set_id ARGSETID, 65 -- The track which is the "parent" of this track. Only non-null for tracks 66 -- created using Perfetto's track_event API. 67 parent_id JOINID(track.id), 68 -- Generic key-value pairs containing extra information about the track. 69 -- 70 -- Join with the `args` table or use the `EXTRACT_ARG` helper function to 71 -- expand the args. 72 source_arg_set_id ARGSETID, 73 -- Machine identifier, non-null for tracks on a remote machine. 74 machine_id LONG 75) AS 76SELECT 77 id, 78 type, 79 name, 80 classification, 81 dimension_arg_set_id, 82 parent_id, 83 source_arg_set_id, 84 machine_id 85FROM __intrinsic_track; 86 87-- Contains information about the CPUs on the device this trace was taken on. 88CREATE PERFETTO VIEW cpu ( 89 -- Unique identifier for this CPU. Identical to |ucpu|, prefer using |ucpu| 90 -- instead. 91 id ID, 92 -- Unique identifier for this CPU. Isn't equal to |cpu| for remote machines 93 -- and is equal to |cpu| for the host machine. 94 ucpu ID, 95 -- The 0-based CPU core identifier. 96 cpu LONG, 97 -- The name of the "most-specific" child table containing this row. 98 type STRING, 99 -- The cluster id is shared by CPUs in the same cluster. 100 cluster_id LONG, 101 -- A string describing this core. 102 processor STRING, 103 -- Machine identifier, non-null for CPUs on a remote machine. 104 machine_id LONG, 105 -- Capacity of a CPU of a device, a metric which indicates the 106 -- relative performance of a CPU on a device 107 -- For details see: 108 -- https://www.kernel.org/doc/Documentation/devicetree/bindings/arm/cpu-capacity.txt 109 capacity LONG, 110 -- Extra key/value pairs associated with this cpu. 111 arg_set_id ARGSETID 112) AS 113SELECT 114 id, 115 id AS ucpu, 116 cpu, 117 type AS type, 118 cluster_id, 119 processor, 120 machine_id, 121 capacity, 122 arg_set_id 123FROM 124 __intrinsic_cpu 125WHERE 126 cpu IS NOT NULL; 127 128-- Contains the frequency values that the CPUs on the device are capable of 129-- running at. 130CREATE PERFETTO VIEW cpu_available_frequencies ( 131 -- Unique identifier for this cpu frequency. 132 id ID, 133 -- The CPU for this frequency, meaningful only in single machine traces. 134 -- For multi-machine, join with the `cpu` table on `ucpu` to get the CPU 135 -- identifier of each machine. 136 cpu LONG, 137 -- CPU frequency in KHz. 138 freq LONG, 139 -- The CPU that the slice executed on (meaningful only in single machine 140 -- traces). For multi-machine, join with the `cpu` table on `ucpu` to get the 141 -- CPU identifier of each machine. 142 ucpu LONG 143) AS 144SELECT 145 id, 146 ucpu AS cpu, 147 freq, 148 ucpu 149FROM 150 __intrinsic_cpu_freq; 151 152-- This table holds slices with kernel thread scheduling information. These 153-- slices are collected when the Linux "ftrace" data source is used with the 154-- "sched/switch" and "sched/wakeup*" events enabled. 155-- 156-- The rows in this table will always have a matching row in the |thread_state| 157-- table with |thread_state.state| = 'Running' 158CREATE PERFETTO VIEW sched_slice ( 159 -- Unique identifier for this scheduling slice. 160 id ID, 161 -- The name of the "most-specific" child table containing this row. 162 type STRING, 163 -- The timestamp at the start of the slice. 164 ts TIMESTAMP, 165 -- The duration of the slice. 166 dur DURATION, 167 -- The CPU that the slice executed on (meaningful only in single machine 168 -- traces). For multi-machine, join with the `cpu` table on `ucpu` to get the 169 -- CPU identifier of each machine. 170 cpu LONG, 171 -- The thread's unique id in the trace. 172 utid JOINID(thread.id), 173 -- A string representing the scheduling state of the kernel 174 -- thread at the end of the slice. The individual characters in 175 -- the string mean the following: R (runnable), S (awaiting a 176 -- wakeup), D (in an uninterruptible sleep), T (suspended), 177 -- t (being traced), X (exiting), P (parked), W (waking), 178 -- I (idle), N (not contributing to the load average), 179 -- K (wakeable on fatal signals) and Z (zombie, awaiting 180 -- cleanup). 181 end_state STRING, 182 -- The kernel priority that the thread ran at. 183 priority LONG, 184 -- The unique CPU identifier that the slice executed on. 185 ucpu LONG 186) AS 187SELECT 188 id, 189 type, 190 ts, 191 dur, 192 ucpu AS cpu, 193 utid, 194 end_state, 195 priority, 196 ucpu 197FROM 198 __intrinsic_sched_slice; 199 200-- Shorter alias for table `sched_slice`. 201CREATE PERFETTO VIEW sched( 202 -- Alias for `sched_slice.id`. 203 id ID, 204 -- Alias for `sched_slice.type`. 205 type STRING, 206 -- Alias for `sched_slice.ts`. 207 ts TIMESTAMP, 208 -- Alias for `sched_slice.dur`. 209 dur DURATION, 210 -- Alias for `sched_slice.cpu`. 211 cpu LONG, 212 -- Alias for `sched_slice.utid`. 213 utid JOINID(thread.id), 214 -- Alias for `sched_slice.end_state`. 215 end_state STRING, 216 -- Alias for `sched_slice.priority`. 217 priority LONG, 218 -- Alias for `sched_slice.ucpu`. 219 ucpu LONG, 220 -- Legacy column, should no longer be used. 221 ts_end LONG 222) AS 223SELECT *, ts + dur as ts_end 224FROM sched_slice; 225 226-- This table contains the scheduling state of every thread on the system during 227-- the trace. 228-- 229-- The rows in this table which have |state| = 'Running', will have a 230-- corresponding row in the |sched_slice| table. 231CREATE PERFETTO VIEW thread_state( 232 -- Unique identifier for this thread state. 233 id ID, 234 -- The name of the "most-specific" child table containing this row. 235 type STRING, 236 -- The timestamp at the start of the slice. 237 ts TIMESTAMP, 238 -- The duration of the slice. 239 dur DURATION, 240 -- The CPU that the thread executed on (meaningful only in single machine 241 -- traces). For multi-machine, join with the `cpu` table on `ucpu` to get the 242 -- CPU identifier of each machine. 243 cpu LONG, 244 -- The thread's unique id in the trace. 245 utid JOINID(thread.id), 246 -- The scheduling state of the thread. Can be "Running" or any of the states 247 -- described in |sched_slice.end_state|. 248 state STRING, 249 -- Indicates whether this thread was blocked on IO. 250 io_wait LONG, 251 -- The function in the kernel this thread was blocked on. 252 blocked_function STRING, 253 -- The unique thread id of the thread which caused a wakeup of this thread. 254 waker_utid JOINID(thread.id), 255 -- The unique thread state id which caused a wakeup of this thread. 256 waker_id JOINID(thread_state.id), 257 -- Whether the wakeup was from interrupt context or process context. 258 irq_context LONG, 259 -- The unique CPU identifier that the thread executed on. 260 ucpu LONG 261) AS 262SELECT 263 id, 264 type, 265 ts, 266 dur, 267 ucpu AS cpu, 268 utid, 269 state, 270 io_wait, 271 blocked_function, 272 waker_utid, 273 waker_id, 274 irq_context, 275 ucpu 276FROM 277 __intrinsic_thread_state; 278 279-- Contains 'raw' events from the trace for some types of events. This table 280-- only exists for debugging purposes and should not be relied on in production 281-- usecases (i.e. metrics, standard library etc.) 282CREATE PERFETTO VIEW raw ( 283 -- Unique identifier for this raw event. 284 id ID, 285 -- The name of the "most-specific" child table containing this row. 286 type STRING, 287 -- The timestamp of this event. 288 ts TIMESTAMP, 289 -- The name of the event. For ftrace events, this will be the ftrace event 290 -- name. 291 name STRING, 292 -- The CPU this event was emitted on (meaningful only in single machine 293 -- traces). For multi-machine, join with the `cpu` table on `ucpu` to get the 294 -- CPU identifier of each machine. 295 cpu LONG, 296 -- The thread this event was emitted on. 297 utid JOINID(thread.id), 298 -- The set of key/value pairs associated with this event. 299 arg_set_id ARGSETID, 300 -- Ftrace event flags for this event. Currently only emitted for sched_waking 301 -- events. 302 common_flags LONG, 303 -- The unique CPU identifier that this event was emitted on. 304 ucpu LONG 305) AS 306SELECT 307 id, 308 type, 309 ts, 310 name, 311 ucpu AS cpu, 312 utid, 313 arg_set_id, 314 common_flags, 315 ucpu 316FROM 317 __intrinsic_raw; 318 319-- Contains all the ftrace events in the trace. This table exists only for 320-- debugging purposes and should not be relied on in production usecases (i.e. 321-- metrics, standard library etc). Note also that this table might be empty if 322-- raw ftrace parsing has been disabled. 323CREATE PERFETTO VIEW ftrace_event ( 324 -- Unique identifier for this ftrace event. 325 id ID, 326 -- The name of the "most-specific" child table containing this row. 327 type STRING, 328 -- The timestamp of this event. 329 ts TIMESTAMP, 330 -- The ftrace event name. 331 name STRING, 332 -- The CPU this event was emitted on (meaningful only in single machine 333 -- traces). For multi-machine, join with the `cpu` table on `ucpu` to get the 334 -- CPU identifier of each machine. 335 cpu LONG, 336 -- The thread this event was emitted on. 337 utid JOINID(thread.id), 338 -- The set of key/value pairs associated with this event. 339 arg_set_id ARGSETID, 340 -- Ftrace event flags for this event. Currently only emitted for 341 -- sched_waking events. 342 common_flags LONG, 343 -- The unique CPU identifier that this event was emitted on. 344 ucpu LONG 345) AS 346SELECT 347 id, 348 type, 349 ts, 350 name, 351 ucpu AS cpu, 352 utid, 353 arg_set_id, 354 common_flags, 355 ucpu 356FROM 357 __intrinsic_ftrace_event; 358 359-- The sched_slice table with the upid column. 360CREATE PERFETTO VIEW experimental_sched_upid ( 361 -- Unique identifier for this scheduling slice. 362 id ID, 363 -- The name of the "most-specific" child table containing this row. 364 type STRING, 365 -- The timestamp at the start of the slice. 366 ts TIMESTAMP, 367 -- The duration of the slice. 368 dur DURATION, 369 -- The CPU that the slice executed on (meaningful only in single machine 370 -- traces). For multi-machine, join with the `cpu` table on `ucpu` to get the 371 -- CPU identifier of each machine. 372 cpu LONG, 373 -- The thread's unique id in the trace. 374 utid JOINID(thread.id), 375 -- A string representing the scheduling state of the kernel thread at the end 376 -- of the slice. The individual characters in the string mean the following: R 377 -- (runnable), S (awaiting a wakeup), D (in an uninterruptible sleep), T 378 -- (suspended), t (being traced), X (exiting), P (parked), W (waking), I 379 -- (idle), N (not contributing to the load average), K (wakeable on fatal 380 -- signals) and Z (zombie, awaiting cleanup). 381 end_state STRING, 382 -- The kernel priority that the thread ran at. 383 priority LONG, 384 -- The unique CPU identifier that the slice executed on. 385 ucpu LONG, 386 -- The process's unique id in the trace. 387 upid JOINID(process.id) 388) AS 389SELECT 390 id, 391 type, 392 ts, 393 dur, 394 ucpu AS cpu, 395 utid, 396 end_state, 397 priority, 398 ucpu, 399 upid 400FROM 401 __intrinsic_sched_upid; 402 403-- Tracks which are associated to a single CPU. 404CREATE PERFETTO VIEW cpu_track ( 405 -- Unique identifier for this cpu track. 406 id ID, 407 -- The name of the "most-specific" child table containing this row. 408 type STRING, 409 -- Name of the track. 410 name STRING, 411 -- The track which is the "parent" of this track. Only non-null for tracks 412 -- created using Perfetto's track_event API. 413 parent_id LONG, 414 -- Args for this track which store information about "source" of this track in 415 -- the trace. For example: whether this track orginated from atrace, Chrome 416 -- tracepoints etc. 417 source_arg_set_id ARGSETID, 418 -- Machine identifier, non-null for tracks on a remote machine. 419 machine_id LONG, 420 -- The CPU that the track is associated with. 421 cpu LONG 422) AS 423SELECT 424 id, 425 type, 426 name, 427 parent_id, 428 source_arg_set_id, 429 machine_id, 430 cpu 431FROM 432 __intrinsic_cpu_track; 433 434-- Tracks containing counter-like events. 435CREATE PERFETTO VIEW counter_track ( 436 -- Unique identifier for this cpu counter track. 437 id ID, 438 -- The name of the "most-specific" child table containing this row. 439 type STRING, 440 -- Name of the track. 441 name STRING, 442 -- The track which is the "parent" of this track. Only non-null for tracks 443 -- created using Perfetto's track_event API. 444 parent_id JOINID(track.id), 445 -- The classification of a track indicates the "type of data" the track 446 -- contains. 447 -- 448 -- Every track is uniquely identified by the the combination of the 449 -- classification and a set of dimensions: classifications allow identifying 450 -- a set of tracks with the same type of data within the whole universe of 451 -- tracks while dimensions allow distinguishing between different tracks in 452 -- that set. 453 classification STRING, 454 -- The dimensions of the track which uniquely identify the track within a 455 -- given classification. 456 dimension_arg_set_id ARGSETID, 457 -- Args for this track which store information about "source" of this track in 458 -- the trace. For example: whether this track orginated from atrace, Chrome 459 -- tracepoints etc. 460 source_arg_set_id ARGSETID, 461 -- Machine identifier, non-null for tracks on a remote machine. 462 machine_id LONG, 463 -- The units of the counter. This column is rarely filled. 464 unit STRING, 465 -- The description for this track. For debugging purposes only. 466 description STRING 467) AS 468SELECT 469 id, 470 type, 471 name, 472 NULL AS parent_id, 473 classification, 474 dimension_arg_set_id, 475 source_arg_set_id, 476 machine_id, 477 counter_unit AS unit, 478 EXTRACT_ARG(source_arg_set_id, 'description') AS description 479FROM __intrinsic_track 480WHERE event_type = 'counter'; 481 482-- Tracks containing counter-like events associated to a CPU. 483CREATE PERFETTO TABLE cpu_counter_track ( 484 -- Unique identifier for this cpu counter track. 485 id ID, 486 -- The name of the "most-specific" child table containing this row. 487 type STRING, 488 -- Name of the track. 489 name STRING, 490 -- The track which is the "parent" of this track. Only non-null for tracks 491 -- created using Perfetto's track_event API. 492 parent_id JOINID(track.id), 493 -- Args for this track which store information about "source" of this track in 494 -- the trace. For example: whether this track orginated from atrace, Chrome 495 -- tracepoints etc. 496 source_arg_set_id ARGSETID, 497 -- Machine identifier, non-null for tracks on a remote machine. 498 machine_id LONG, 499 -- The units of the counter. This column is rarely filled. 500 unit STRING, 501 -- The description for this track. For debugging purposes only. 502 description STRING, 503 -- The CPU that the track is associated with. 504 cpu LONG 505) AS 506SELECT 507 ct.id, 508 ct.type, 509 ct.name, 510 ct.parent_id, 511 ct.source_arg_set_id, 512 ct.machine_id, 513 ct.unit, 514 ct.description, 515 args.int_value as cpu 516FROM counter_track AS ct 517JOIN args ON ct.dimension_arg_set_id = args.arg_set_id 518WHERE args.key = 'cpu'; 519 520-- Tracks containing counter-like events associated to a GPU. 521CREATE PERFETTO TABLE gpu_counter_track ( 522 -- Unique identifier for this gpu counter track. 523 id ID, 524 -- The name of the "most-specific" child table containing this row. 525 type STRING, 526 -- Name of the track. 527 name STRING, 528 -- The track which is the "parent" of this track. Only non-null for tracks 529 -- created using Perfetto's track_event API. 530 parent_id JOINID(track.id), 531 -- Args for this track which store information about "source" of this track in 532 -- the trace. For example: whether this track orginated from atrace, Chrome 533 -- tracepoints etc. 534 source_arg_set_id LONG, 535 -- Machine identifier, non-null for tracks on a remote machine. 536 machine_id LONG, 537 -- The units of the counter. This column is rarely filled. 538 unit STRING, 539 -- The description for this track. For debugging purposes only. 540 description STRING, 541 -- The GPU that the track is associated with. 542 gpu_id LONG 543) AS 544SELECT 545 ct.id, 546 ct.type, 547 ct.name, 548 ct.parent_id, 549 ct.source_arg_set_id, 550 ct.machine_id, 551 ct.unit, 552 ct.description, 553 args.int_value AS gpu_id 554FROM counter_track AS ct 555JOIN args ON ct.dimension_arg_set_id = args.arg_set_id 556WHERE args.key = 'gpu'; 557 558-- Tracks containing counter-like events associated to a process. 559CREATE PERFETTO TABLE process_counter_track ( 560 -- Unique identifier for this process counter track. 561 id ID, 562 -- The name of the "most-specific" child table containing this row. 563 type STRING, 564 -- Name of the track. 565 name STRING, 566 -- The track which is the "parent" of this track. Only non-null for tracks 567 -- created using Perfetto's track_event API. 568 parent_id JOINID(track.id), 569 -- Args for this track which store information about "source" of this track in 570 -- the trace. For example: whether this track orginated from atrace, Chrome 571 -- tracepoints etc. 572 source_arg_set_id LONG, 573 -- Machine identifier, non-null for tracks on a remote machine. 574 machine_id LONG, 575 -- The units of the counter. This column is rarely filled. 576 unit STRING, 577 -- The description for this track. For debugging purposes only. 578 description STRING, 579 -- The upid of the process that the track is associated with. 580 upid LONG 581) AS 582SELECT 583 ct.id, 584 ct.type, 585 ct.name, 586 ct.parent_id, 587 ct.source_arg_set_id, 588 ct.machine_id, 589 ct.unit, 590 ct.description, 591 args.int_value AS upid 592FROM counter_track AS ct 593JOIN args ON ct.dimension_arg_set_id = args.arg_set_id 594WHERE args.key = 'upid'; 595 596-- Tracks containing counter-like events associated to a thread. 597CREATE PERFETTO TABLE thread_counter_track ( 598 -- Unique identifier for this thread counter track. 599 id ID, 600 -- The name of the "most-specific" child table containing this row. 601 type STRING, 602 -- Name of the track. 603 name STRING, 604 -- The track which is the "parent" of this track. Only non-null for tracks 605 -- created using Perfetto's track_event API. 606 parent_id JOINID(track.id), 607 -- Args for this track which store information about "source" of this track in 608 -- the trace. For example: whether this track orginated from atrace, Chrome 609 -- tracepoints etc. 610 source_arg_set_id LONG, 611 -- Machine identifier, non-null for tracks on a remote machine. 612 machine_id LONG, 613 -- The units of the counter. This column is rarely filled. 614 unit STRING, 615 -- The description for this track. For debugging purposes only. 616 description STRING, 617 -- The utid of the thread that the track is associated with. 618 utid LONG 619) AS 620SELECT 621 ct.id, 622 ct.type, 623 ct.name, 624 ct.parent_id, 625 ct.source_arg_set_id, 626 ct.machine_id, 627 ct.unit, 628 ct.description, 629 args.int_value AS utid 630FROM counter_track AS ct 631JOIN args ON ct.dimension_arg_set_id = args.arg_set_id 632WHERE args.key = 'utid'; 633 634-- Tracks containing counter-like events collected from Linux perf. 635CREATE PERFETTO TABLE perf_counter_track ( 636 -- Unique identifier for this thread counter track. 637 id ID, 638 -- The name of the "most-specific" child table containing this row. 639 type STRING, 640 -- Name of the track. 641 name STRING, 642 -- The track which is the "parent" of this track. Only non-null for tracks 643 -- created using Perfetto's track_event API. 644 parent_id JOINID(track.id), 645 -- Args for this track which store information about "source" of this track in 646 -- the trace. For example: whether this track orginated from atrace, Chrome 647 -- tracepoints etc. 648 source_arg_set_id LONG, 649 -- Machine identifier, non-null for tracks on a remote machine. 650 machine_id LONG, 651 -- The units of the counter. This column is rarely filled. 652 unit STRING, 653 -- The description for this track. For debugging purposes only. 654 description STRING, 655 -- The id of the perf session this counter was captured on. 656 perf_session_id LONG, 657 -- The CPU the counter is associated with. 658 cpu LONG, 659 -- Whether this counter is the sampling timebase for the session. 660 is_timebase BOOL 661) AS 662SELECT 663 ct.id, 664 ct.type, 665 ct.name, 666 ct.parent_id, 667 ct.source_arg_set_id, 668 ct.machine_id, 669 ct.unit, 670 ct.description, 671 extract_arg(ct.dimension_arg_set_id, 'perf_session_id') AS perf_session_id, 672 extract_arg(ct.dimension_arg_set_id, 'cpu') AS cpu, 673 extract_arg(ct.source_arg_set_id, 'is_timebase') AS is_timebase 674FROM counter_track AS ct 675WHERE ct.classification = 'perf_counter'; 676 677-- Alias of the `counter` table. 678CREATE PERFETTO VIEW counters( 679 -- Alias of `counter.id`. 680 id ID, 681 -- Alias of `counter.type`. 682 type STRING, 683 -- Alias of `counter.ts`. 684 ts TIMESTAMP, 685 -- Alias of `counter.track_id`. 686 track_id JOINID(track.id), 687 -- Alias of `counter.value`. 688 value DOUBLE, 689 -- Alias of `counter.arg_set_id`. 690 arg_set_id LONG, 691 -- Legacy column, should no longer be used. 692 name STRING, 693 -- Legacy column, should no longer be used. 694 unit STRING 695) AS 696SELECT v.*, t.name, t.unit 697FROM counter v 698JOIN counter_track t ON v.track_id = t.id 699ORDER BY ts; 700