diff --git a/Android.bp b/Android.bp index ce2d1a252d..04dc001feb 100644 --- a/Android.bp +++ b/Android.bp @@ -13671,6 +13671,7 @@ genrule { "src/trace_processor/perfetto_sql/stdlib/linux/perf/samples.sql", "src/trace_processor/perfetto_sql/stdlib/linux/perf/spe.sql", "src/trace_processor/perfetto_sql/stdlib/linux/threads.sql", + "src/trace_processor/perfetto_sql/stdlib/pixel/camera.sql", "src/trace_processor/perfetto_sql/stdlib/pkvm/hypervisor.sql", "src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/casts.sql", "src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/slices.sql", diff --git a/BUILD b/BUILD index 471a1031a0..29b8a76eb6 100644 --- a/BUILD +++ b/BUILD @@ -3144,6 +3144,14 @@ perfetto_filegroup( ], ) +# GN target: //src/trace_processor/perfetto_sql/stdlib/pixel:pixel +perfetto_filegroup( + name = "src_trace_processor_perfetto_sql_stdlib_pixel_pixel", + srcs = [ + "src/trace_processor/perfetto_sql/stdlib/pixel/camera.sql", + ], +) + # GN target: //src/trace_processor/perfetto_sql/stdlib/pkvm:pkvm perfetto_filegroup( name = "src_trace_processor_perfetto_sql_stdlib_pkvm_pkvm", @@ -3308,6 +3316,7 @@ perfetto_cc_amalgamated_sql( ":src_trace_processor_perfetto_sql_stdlib_linux_linux", ":src_trace_processor_perfetto_sql_stdlib_linux_memory_memory", ":src_trace_processor_perfetto_sql_stdlib_linux_perf_perf", + ":src_trace_processor_perfetto_sql_stdlib_pixel_pixel", ":src_trace_processor_perfetto_sql_stdlib_pkvm_pkvm", ":src_trace_processor_perfetto_sql_stdlib_prelude_after_eof_after_eof", ":src_trace_processor_perfetto_sql_stdlib_prelude_before_eof_before_eof", diff --git a/src/trace_processor/perfetto_sql/stdlib/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/BUILD.gn index adaeb73995..92150ae548 100644 --- a/src/trace_processor/perfetto_sql/stdlib/BUILD.gn +++ b/src/trace_processor/perfetto_sql/stdlib/BUILD.gn @@ -27,6 +27,7 @@ perfetto_amalgamated_sql_header("stdlib") { "graphs", "intervals", "linux", + "pixel", "pkvm", "prelude", "sched", diff --git a/src/trace_processor/perfetto_sql/stdlib/pixel/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/pixel/BUILD.gn new file mode 100644 index 0000000000..cd19df398c --- /dev/null +++ b/src/trace_processor/perfetto_sql/stdlib/pixel/BUILD.gn @@ -0,0 +1,19 @@ +# 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 at +# +# 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. + +import("../../../../../gn/perfetto_sql.gni") + +perfetto_sql_source_set("pixel") { + sources = [ "camera.sql" ] +} diff --git a/src/trace_processor/perfetto_sql/stdlib/pixel/camera.sql b/src/trace_processor/perfetto_sql/stdlib/pixel/camera.sql new file mode 100644 index 0000000000..5daf24d14c --- /dev/null +++ b/src/trace_processor/perfetto_sql/stdlib/pixel/camera.sql @@ -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. +-- + +INCLUDE PERFETTO MODULE slices.with_context; + +-- Break down camera Camera graph execution slices per node, port group, and frame. +-- This table extracts key identifiers from Camera graph execution slice names and +-- provides timing information for each processing stage. +CREATE PERFETTO TABLE pixel_camera_frames( + -- Unique identifier for this slice. + id JOINID(slice.id), + -- Start timestamp of the slice. + ts TIMESTAMP, + -- Duration of the slice execution. + dur DURATION, + -- Track ID for this slice. + track_id JOINID(track.id), + -- Thread ID (utid) executing this slice. + utid JOINID(thread.id), + -- Name of the thread executing this slice. + thread_name STRING, + -- Name of the processing node in the Camera graph. + node STRING, + -- Port group name for the node. + port_group STRING, + -- Frame number being processed. + frame_number LONG, + -- Camera ID associated with this slice. + cam_id LONG +) AS + SELECT + id, + ts, + dur, + track_id, + utid, + thread_name, + -- Slices follow the pattern "camX_Y:Z (frame N)" where X is the camera ID, + -- Y is the node name, Z is the port group, and N is the frame number + SUBSTR(STR_SPLIT(name, ':', 0), 6) AS node, + STR_SPLIT(STR_SPLIT(name, ':', 1), ' (', 0) AS port_group, + cast_int!(STR_SPLIT(STR_SPLIT(name, '(frame', 1), ')', 0)) AS frame_number, + cast_int!(STR_SPLIT(STR_SPLIT(name, 'cam', 1), '_', 0)) AS cam_id +FROM thread_slice +-- Only include slices matching the Camera graph pattern and with valid durations +WHERE name GLOB 'cam*_*:* (frame *)' AND dur != -1; diff --git a/test/trace_processor/diff_tests/include_index.py b/test/trace_processor/diff_tests/include_index.py index 6d84e99e94..d71eb6c5cf 100644 --- a/test/trace_processor/diff_tests/include_index.py +++ b/test/trace_processor/diff_tests/include_index.py @@ -131,6 +131,7 @@ 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.pixel.tests import PixelStdlib from diff_tests.stdlib.pkvm.tests import Pkvm from diff_tests.stdlib.prelude.math_functions_tests import PreludeMathFunctions from diff_tests.stdlib.prelude.pprof_functions_tests import PreludePprofFunctions @@ -343,6 +344,7 @@ def fetch_all_diff_tests(index_path: str) -> List['testing.TestCase']: *Viz(index_path, 'stdlib/viz', 'Viz').fetch(), *WattsonStdlib(index_path, 'stdlib/wattson', 'WattsonStdlib').fetch(), *HeapProfile(index_path, 'stdlib/android', 'HeapProfile').fetch(), + *PixelStdlib(index_path, 'stdlib/pixel', 'PixelStdlib').fetch(), ] + chrome_stdlib_tests syntax_tests = [ diff --git a/test/trace_processor/diff_tests/stdlib/pixel/tests.py b/test/trace_processor/diff_tests/stdlib/pixel/tests.py new file mode 100644 index 0000000000..c6bf7319ee --- /dev/null +++ b/test/trace_processor/diff_tests/stdlib/pixel/tests.py @@ -0,0 +1,56 @@ +#!/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 Csv, TextProto +from python.generators.diff_tests.testing import DiffTestBlueprint +from python.generators.diff_tests.testing import TestSuite + + +class PixelStdlib(TestSuite): + def test_android_camera_frames(self): + return DiffTestBlueprint( + trace=TextProto(r""" + packet { ftrace_events { + cpu: 0 + previous_bundle_end_timestamp: 2000 + event { + timestamp: 2200 + pid: 42 + print { buf: "B|42|cam1_filter:output (frame 123)\n" } + } + event { + timestamp: 2700 + pid: 42 + print { buf: "E|42\n" } + } + }} + """), + query=""" + INCLUDE PERFETTO MODULE pixel.camera; + + SELECT + ts, + node, + port_group, + frame_number, + cam_id, + dur + FROM pixel_camera_frames + ORDER BY ts + """, + out=Csv(""" + "ts","node","port_group","frame_number","cam_id","dur" + 2200,"filter","output",123,1,500 + """))