Skip to content

Commit

Permalink
Merge "stdlib: Add linux_kernel_threads" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
aMayzner authored and Gerrit Code Review committed Jul 29, 2024
2 parents 825e672 + d3e5227 commit 021422b
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 1 deletion.
1 change: 1 addition & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -13342,6 +13342,7 @@ genrule {
"src/trace_processor/perfetto_sql/stdlib/linux/memory/high_watermark.sql",
"src/trace_processor/perfetto_sql/stdlib/linux/memory/process.sql",
"src/trace_processor/perfetto_sql/stdlib/linux/perf/samples.sql",
"src/trace_processor/perfetto_sql/stdlib/linux/threads.sql",
"src/trace_processor/perfetto_sql/stdlib/metasql/column_list.sql",
"src/trace_processor/perfetto_sql/stdlib/metasql/table_list.sql",
"src/trace_processor/perfetto_sql/stdlib/pkvm/hypervisor.sql",
Expand Down
3 changes: 3 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2781,6 +2781,9 @@ perfetto_filegroup(
# GN target: //src/trace_processor/perfetto_sql/stdlib/linux:linux
perfetto_filegroup(
name = "src_trace_processor_perfetto_sql_stdlib_linux_linux",
srcs = [
"src/trace_processor/perfetto_sql/stdlib/linux/threads.sql",
],
)

# GN target: //src/trace_processor/perfetto_sql/stdlib/metasql:metasql
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Unreleased:
* Moved `memory.heap_graph_dominator_tree` to
`android.memory.heap_graph.dominator_tree`. This is to allow for the
addition of more modules related to heap graphs.
* Added `linux_kernel_threads` table to `linux.threads` module.
Trace Processor:
* Change `NotifyEndOfFile` method to return a Status object. For backwards
compatibility, this value can be ignored but in the future a [[nodiscard]]
Expand Down
2 changes: 1 addition & 1 deletion src/trace_processor/perfetto_sql/stdlib/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import("../../../../../gn/perfetto_sql.gni")

perfetto_sql_source_set("linux") {
sources = []
sources = [ "threads.sql" ]
deps = [
"cpu",
"memory",
Expand Down
59 changes: 59 additions & 0 deletions src/trace_processor/perfetto_sql/stdlib/linux/threads.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
--
-- Copyright 2024 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 at
--
-- https://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.

-- All kernel threads of the trace. As kernel threads are processes, provides
-- also process data.
CREATE PERFETTO TABLE linux_kernel_threads(
-- Upid of kernel thread. Alias of |process.upid|.
upid INT,
-- Utid of kernel thread. Alias of |thread.utid|.
utid INT,
-- Pid of kernel thread. Alias of |process.pid|.
pid INT,
-- Tid of kernel thread. Alias of |process.pid|.
tid INT,
-- Name of kernel process. Alias of |process.name|.
process_name STRING,
-- Name of kernel thread. Alias of |thread.name|.
thread_name STRING,
-- Machine id of kernel thread. If NULL then it's a single machine trace.
-- Alias of |process.machine_id|.
machine_id INT
) AS
WITH pid_2 AS (
SELECT upid, pid, name, machine_id
FROM process
WHERE pid = 2
),
parent_pid_2 AS (
SELECT p.upid, p.pid, p.name, p.machine_id
FROM process p
JOIN pid_2 ON p.parent_upid = pid_2.upid
)
SELECT
upid,
utid,
pid,
tid,
p.name AS process_name,
t.name AS thread_name,
p.machine_id
FROM
(
SELECT * FROM parent_pid_2
UNION
SELECT * FROM pid_2
) p
JOIN thread t USING (upid);
2 changes: 2 additions & 0 deletions test/trace_processor/diff_tests/include_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
from diff_tests.stdlib.intervals.tests import StdlibIntervals
from diff_tests.stdlib.linux.cpu import LinuxCpu
from diff_tests.stdlib.linux.memory import Memory
from diff_tests.stdlib.linux.tests import LinuxTests
from diff_tests.stdlib.metasql.column_list import ColumnListTests
from diff_tests.stdlib.metasql.table_list import TableListTests
from diff_tests.stdlib.pkvm.tests import Pkvm
Expand Down Expand Up @@ -282,6 +283,7 @@ def fetch_all_diff_tests(index_path: str) -> List['testing.TestCase']:
*AndroidStdlib(index_path, 'stdlib/android', 'AndroidStdlib').fetch(),
*CpuClusters(index_path, 'stdlib/android', 'CpuClusters').fetch(),
*LinuxCpu(index_path, 'stdlib/linux/cpu', 'LinuxCpu').fetch(),
*LinuxTests(index_path, 'stdlib/linux', 'LinuxTests').fetch(),
*DominatorTree(index_path, 'stdlib/graphs', 'DominatorTree').fetch(),
*CriticalPathTests(index_path, 'stdlib/graphs', 'CriticalPath').fetch(),
*GraphScanTests(index_path, 'stdlib/graphs', 'GraphScan').fetch(),
Expand Down
47 changes: 47 additions & 0 deletions test/trace_processor/diff_tests/stdlib/linux/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
# Copyright (C) 2024 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, Systrace
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 python.generators.diff_tests.testing import PrintProfileProto


class LinuxTests(TestSuite):

def test_kernel_threads(self):
return DiffTestBlueprint(
trace=DataPath('android_postboot_unlock.pftrace'),
query="""
INCLUDE PERFETTO MODULE linux.threads;
SELECT upid, utid, pid, tid, process_name, thread_name
FROM linux_kernel_threads
ORDER by utid LIMIT 10;
""",
out=Csv("""
"upid","utid","pid","tid","process_name","thread_name"
7,14,510,510,"sugov:0","sugov:0"
89,23,1365,1365,"com.google.usf.","com.google.usf."
87,37,1249,1249,"irq/357-dwc3","irq/357-dwc3"
31,38,6,6,"kworker/u16:0","kworker/u16:0"
11,42,511,511,"sugov:4","sugov:4"
83,43,1152,1152,"irq/502-fts_ts","irq/502-fts_ts"
93,44,2374,2374,"csf_sync_update","csf_sync_update"
18,45,2379,2379,"csf_kcpu_0","csf_kcpu_0"
12,47,247,247,"decon0_kthread","decon0_kthread"
65,48,159,159,"spi0","spi0"
"""))

0 comments on commit 021422b

Please sign in to comment.