Skip to content

Commit

Permalink
tp: UI uses TrackDescriptor ordered tracks
Browse files Browse the repository at this point in the history
Change-Id: Ieee14e82d1edf48cc7dba68acb3cdcc05f18bed0
  • Loading branch information
aMayzner committed Oct 24, 2024
1 parent e372718 commit bbd80b5
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 10 deletions.
5 changes: 3 additions & 2 deletions protos/perfetto/trace/perfetto_trace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15447,8 +15447,9 @@ message TrackDescriptor {
// If set the ordering will be accessible to the UI via the `track` table.
optional ChildTracksOrdering child_ordering = 11;

// Only makes sense if the parent tracks has `child_ordering` set to
// `EXPLICIT`. Lowest value has the highest priority.
// As tracks with the same name under the same `parent_uuid` are grouped
// together in the UI, the `sibling_order_z_index` of the grouped track
// would be the minimum `sibling_order_z_index` of grouped tracks.
optional int32 sibling_order_z_index = 12;
}

Expand Down
5 changes: 3 additions & 2 deletions protos/perfetto/trace/track_event/track_descriptor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ message TrackDescriptor {
// If set the ordering will be accessible to the UI via the `track` table.
optional ChildTracksOrdering child_ordering = 11;

// Only makes sense if the parent tracks has `child_ordering` set to
// `EXPLICIT`. Lowest value has the highest priority.
// As tracks with the same name under the same `parent_uuid` are grouped
// together in the UI, the `sibling_order_z_index` of the grouped track
// would be the minimum `sibling_order_z_index` of grouped tracks.
optional int32 sibling_order_z_index = 12;
}
90 changes: 88 additions & 2 deletions src/trace_processor/perfetto_sql/stdlib/viz/summary/tracks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,90 @@

INCLUDE PERFETTO MODULE viz.summary.slices;

CREATE PERFETTO VIEW _track_event_tracks_unordered AS
WITH extracted AS (
SELECT
t.id,
t.parent_id,
t.name,
EXTRACT_ARG(t.source_arg_set_id, 'child_ordering') AS ordering,
EXTRACT_ARG(t.source_arg_set_id, 'sibling_order_z_index') AS z_index
FROM track t
)
SELECT
t.id,
t.parent_id,
t.name,
t.ordering,
p.ordering AS parent_ordering,
t.z_index,
t.z_index IS NULL AS no_z_index
FROM extracted t
LEFT JOIN extracted p ON t.parent_id = p.id
WHERE p.ordering IS NOT NULL;

CREATE PERFETTO TABLE _track_event_tracks_ordered AS
WITH lexicographic_and_none AS (
SELECT
id, parent_id, name,
ROW_NUMBER() OVER (ORDER BY parent_id, name) AS order_id
FROM _track_event_tracks_unordered
WHERE parent_ordering = "lexicographic"
),
explicit AS (
SELECT
id, parent_id, name,
ROW_NUMBER() OVER (ORDER BY parent_id, no_z_index, z_index) AS order_id
FROM _track_event_tracks_unordered
WHERE parent_ordering = "explicit"
),
slice_chronological AS (
SELECT
t.*,
min(ts) AS min_ts
FROM _track_event_tracks_unordered t
JOIN slice s on t.id = s.track_id
WHERE parent_ordering = "chronological"
GROUP BY track_id
),
counter_chronological AS (
SELECT
t.*,
min(ts) AS min_ts
FROM _track_event_tracks_unordered t
JOIN counter s on t.id = s.track_id
WHERE parent_ordering = "chronological"
GROUP BY track_id
),
slice_and_counter_chronological AS (
SELECT t.*, u.min_ts
FROM _track_event_tracks_unordered t
LEFT JOIN (
SELECT * FROM slice_chronological
UNION ALL
SELECT * FROM counter_chronological) u USING (id)
WHERE t.parent_ordering = "chronological"
),
chronological AS (
SELECT
id, parent_id, name,
ROW_NUMBER() OVER (ORDER BY parent_id, min_ts) AS order_id
FROM slice_and_counter_chronological
),
all_tracks AS (
SELECT id, parent_id, name, order_id
FROM lexicographic_and_none
UNION
SELECT id, parent_id, name, order_id
FROM explicit
UNION
SELECT id, parent_id, name, order_id
FROM chronological
)
SELECT id, order_id
FROM all_tracks all_t
ORDER BY parent_id, order_id;

CREATE PERFETTO TABLE _thread_track_summary_by_utid_and_name AS
SELECT
utid,
Expand All @@ -28,7 +112,8 @@ SELECT
COUNT() AS track_count
FROM thread_track
JOIN _slice_track_summary USING (id)
GROUP BY utid, parent_id, name;
LEFT JOIN _track_event_tracks_ordered USING (id)
GROUP BY utid, parent_id, order_id, name;

CREATE PERFETTO TABLE _process_track_summary_by_upid_and_parent_id_and_name AS
SELECT
Expand All @@ -40,4 +125,5 @@ SELECT
COUNT() AS track_count
FROM process_track
JOIN _slice_track_summary USING (id)
GROUP BY upid, parent_id, name;
LEFT JOIN _track_event_tracks_ordered USING (id)
GROUP BY upid, parent_id, order_id, name;
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 @@ -144,6 +144,7 @@
from diff_tests.stdlib.span_join.tests_smoke import SpanJoinSmoke
from diff_tests.stdlib.tests import StdlibSmoke
from diff_tests.stdlib.timestamps.tests import Timestamps
from diff_tests.stdlib.viz.tests import Viz
from diff_tests.stdlib.wattson.tests import WattsonStdlib
from diff_tests.syntax.filtering_tests import PerfettoFiltering
from diff_tests.syntax.function_tests import PerfettoFunction
Expand Down Expand Up @@ -340,6 +341,7 @@ def fetch_all_diff_tests(index_path: str) -> List['testing.TestCase']:
'StdlibIntervalsIntersect').fetch(),
*Startups(index_path, 'stdlib/android', 'Startups').fetch(),
*Timestamps(index_path, 'stdlib/timestamps', 'Timestamps').fetch(),
*Viz(index_path, 'stdlib/viz', 'Viz').fetch(),
*WattsonStdlib(index_path, 'stdlib/wattson', 'WattsonStdlib').fetch(),
] + chrome_stdlib_tests

Expand Down
75 changes: 75 additions & 0 deletions test/trace_processor/diff_tests/stdlib/viz/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python3
# Copyright (C) 2023 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
from python.generators.diff_tests.testing import Csv, Json, TextProto
from python.generators.diff_tests.testing import DiffTestBlueprint, TraceInjector
from python.generators.diff_tests.testing import TestSuite


class Viz(TestSuite):

def test_track_event_tracks_ordering(self):
return DiffTestBlueprint(
trace=Path('track_event_tracks_ordering.textproto'),
query="""
SELECT
id,
parent_id,
EXTRACT_ARG(source_arg_set_id, 'child_ordering') AS ordering,
EXTRACT_ARG(source_arg_set_id, 'sibling_order_z_index') AS z_index
FROM track;
""",
out=Csv("""
"id","parent_id","ordering","z_index"
0,"[NULL]","explicit",-10
1,0,"[NULL]","[NULL]"
2,0,"[NULL]",5
3,0,"[NULL]",-5
4,"[NULL]","chronological","[NULL]"
5,4,"[NULL]","[NULL]"
6,4,"[NULL]","[NULL]"
7,4,"[NULL]","[NULL]"
8,0,"[NULL]",-5
9,"[NULL]","lexicographic","[NULL]"
10,9,"[NULL]","[NULL]"
11,9,"[NULL]","[NULL]"
12,9,"[NULL]","[NULL]"
13,9,"[NULL]","[NULL]"
"""))

def test_all_tracks_ordered(self):
return DiffTestBlueprint(
trace=Path('track_event_tracks_ordering.textproto'),
query="""
INCLUDE PERFETTO MODULE viz.summary.tracks;
SELECT id, order_id
FROM _track_event_tracks_ordered
ORDER BY id;
""",
out=Csv("""
"id","order_id"
1,4
2,3
3,1
5,1
6,2
7,3
8,2
10,1
11,2
12,4
13,3
"""))
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Explicit tracks.

## Parent
packet {
trusted_packet_sequence_id: 1
timestamp: 0
incremental_state_cleared: true
first_packet_on_sequence: true
track_descriptor {
uuid: 100
child_ordering: 3
name: "explicit_parent"
sibling_order_z_index: -10
}
trace_packet_defaults {
track_event_defaults {
track_uuid: 1
}
}
}

## Children
packet {
trusted_packet_sequence_id: 2
timestamp: 0
incremental_state_cleared: true
first_packet_on_sequence: true
track_descriptor {
uuid: 2
parent_uuid: 100
name: "explicit_child:no z-index"
}
trace_packet_defaults {
track_event_defaults {
track_uuid: 2
}
}
}
packet {
trusted_packet_sequence_id: 1
timestamp: 0
track_descriptor {
uuid: 3
parent_uuid: 100
name: "explicit_child:5 z-index"
sibling_order_z_index: 5
}
}
packet {
trusted_packet_sequence_id: 1
timestamp: 0
track_descriptor {
uuid: 4
parent_uuid: 100
name: "explicit_child:-5 z-index"
sibling_order_z_index: -5
}
}
packet {
trusted_packet_sequence_id: 1
timestamp: 100
track_descriptor {
uuid: 5
parent_uuid: 100
name: "explicit_child:-5 z-index"
sibling_order_z_index: -5
}
}

# Lexicographic tracks.

## Parent
packet {
trusted_packet_sequence_id: 2
timestamp: 200
track_descriptor {
uuid: 200
child_ordering: 1
name: "lexicographic_parent"
}
}

## Children

packet {
trusted_packet_sequence_id: 1
timestamp: 200
track_descriptor {
uuid: 6
parent_uuid: 200
}
}
packet {
trusted_packet_sequence_id: 1
timestamp: 1000
track_descriptor {
uuid: 7
parent_uuid: 200
name: "a"
}
}
packet {
trusted_packet_sequence_id: 2
timestamp: 2000
track_descriptor {
uuid: 8
parent_uuid: 200
name: "b"
}
}
# Should appear on overridden track "t2".
packet {
trusted_packet_sequence_id: 2
timestamp: 2000
track_descriptor {
uuid: 9
parent_uuid: 200
name: "ab"
}
}

# Chronological tracks.

## Parent
packet {
trusted_packet_sequence_id: 2
timestamp: 1000
track_descriptor {
uuid: 300
child_ordering: 2
name: "chronological_parent"
}
}

## Children

packet {
trusted_packet_sequence_id: 1
timestamp: 0
track_descriptor {
uuid: 10
parent_uuid: 300
name: "chrono"
}
}
packet {
trusted_packet_sequence_id: 2
timestamp: 10
track_descriptor {
uuid: 11
parent_uuid: 300
name: "chrono1"
}
}
packet {
trusted_packet_sequence_id: 2
timestamp: 5
track_descriptor {
uuid: 12
parent_uuid: 300
name: "chrono2"
}
}
Loading

0 comments on commit bbd80b5

Please sign in to comment.