Skip to content

Commit

Permalink
Merge "stdlib: Add a pixel.camera module" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Dec 9, 2024
2 parents 353efaf + 621f02f commit 7a525fd
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 0 deletions.
1 change: 1 addition & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -13674,6 +13674,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",
Expand Down
9 changes: 9 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3146,6 +3146,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",
Expand Down Expand Up @@ -3310,6 +3318,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",
Expand Down
1 change: 1 addition & 0 deletions src/trace_processor/perfetto_sql/stdlib/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ perfetto_amalgamated_sql_header("stdlib") {
"graphs",
"intervals",
"linux",
"pixel",
"pkvm",
"prelude",
"sched",
Expand Down
19 changes: 19 additions & 0 deletions src/trace_processor/perfetto_sql/stdlib/pixel/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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" ]
}
59 changes: 59 additions & 0 deletions src/trace_processor/perfetto_sql/stdlib/pixel/camera.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.
--

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;
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 @@ -133,6 +133,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
Expand Down Expand Up @@ -348,6 +349,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 = [
Expand Down
56 changes: 56 additions & 0 deletions test/trace_processor/diff_tests/stdlib/pixel/tests.py
Original file line number Diff line number Diff line change
@@ -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
"""))

0 comments on commit 7a525fd

Please sign in to comment.