Skip to content

Commit fbe4e83

Browse files
committed
[dns] slice summary tracks
1 parent 743955d commit fbe4e83

File tree

3 files changed

+104
-237
lines changed

3 files changed

+104
-237
lines changed

ui/src/plugins/dev.perfetto.ProcessSummary/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ import {
3030
ProcessSchedulingTrack,
3131
} from './process_scheduling_track';
3232
import {
33-
Config as ProcessSummaryTrackConfig,
34-
PROCESS_SUMMARY_TRACK_KIND,
35-
ProcessSummaryTrack,
36-
} from './process_summary_track';
33+
Config as SliceTrackSummaryConfig,
34+
SLICE_TRACK_SUMMARY_KIND,
35+
SliceTrackSummary,
36+
} from './slice_track_summary';
3737

3838
// This plugin is responsible for adding summary tracks for process and thread
3939
// groups.
@@ -55,12 +55,12 @@ export default class implements PerfettoPlugin {
5555
name: `__process_scheduling_${uuidv4Sql()}`,
5656
on: `__intrinsic_sched_slice(utid)`,
5757
});
58-
// Makes the queries in `ProcessSummaryTrack` significantly faster.
58+
// Makes the queries in `SliceTrackSummary` significantly faster.
5959
// TODO(lalitm): figure out a better way to do this without hardcoding this
6060
// here.
6161
await createPerfettoIndex({
6262
engine: ctx.engine,
63-
name: `__process_summary_${uuidv4Sql()}`,
63+
name: `__slice_track_summary_${uuidv4Sql()}`,
6464
on: `__intrinsic_slice(track_id)`,
6565
});
6666

@@ -188,7 +188,7 @@ export default class implements PerfettoPlugin {
188188
subtitle,
189189
});
190190
} else {
191-
const config: ProcessSummaryTrackConfig = {
191+
const config: SliceTrackSummaryConfig = {
192192
pidForColor,
193193
upid,
194194
utid,
@@ -197,10 +197,10 @@ export default class implements PerfettoPlugin {
197197
ctx.tracks.registerTrack({
198198
uri,
199199
tags: {
200-
kinds: [PROCESS_SUMMARY_TRACK_KIND],
200+
kinds: [SLICE_TRACK_SUMMARY_KIND],
201201
},
202202
chips,
203-
renderer: new ProcessSummaryTrack(ctx.engine, config),
203+
renderer: new SliceTrackSummary(ctx, uri, config),
204204
subtitle,
205205
});
206206
}
@@ -246,7 +246,7 @@ export default class implements PerfettoPlugin {
246246
return;
247247
}
248248

249-
const config: ProcessSummaryTrackConfig = {
249+
const config: SliceTrackSummaryConfig = {
250250
pidForColor: 2,
251251
upid: it.upid,
252252
utid: it.utid,
@@ -255,9 +255,9 @@ export default class implements PerfettoPlugin {
255255
ctx.tracks.registerTrack({
256256
uri: '/kernel',
257257
tags: {
258-
kinds: [PROCESS_SUMMARY_TRACK_KIND],
258+
kinds: [SLICE_TRACK_SUMMARY_KIND],
259259
},
260-
renderer: new ProcessSummaryTrack(ctx.engine, config),
260+
renderer: new SliceTrackSummary(ctx, '/kernel', config),
261261
});
262262
}
263263
}

ui/src/plugins/dev.perfetto.ProcessSummary/process_summary_track.ts

Lines changed: 0 additions & 225 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (C) 2025 The Android Open Source Project
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import {BaseCounterTrack} from '../../components/tracks/base_counter_track';
16+
import {Trace} from '../../public/trace';
17+
import {createUnionDataset, Dataset} from '../../trace_processor/dataset';
18+
import {LONG} from '../../trace_processor/query_result';
19+
20+
export const SLICE_TRACK_SUMMARY_KIND = 'SliceTrackSummary';
21+
22+
export interface Config {
23+
pidForColor: number | bigint;
24+
upid: number | null;
25+
utid: number | null;
26+
}
27+
28+
export class SliceTrackSummary extends BaseCounterTrack {
29+
constructor(trace: Trace, uri: string, _config: Config) {
30+
super(trace, uri);
31+
}
32+
33+
async onInit() {
34+
// Include the intervals module
35+
await this.engine.query('INCLUDE PERFETTO MODULE intervals.overlap');
36+
}
37+
38+
getSqlSource(): string {
39+
// Get the TrackNode for this track
40+
const trackNode = this.trace.workspaces.currentWorkspace.getTrackByUri(
41+
this.uri,
42+
);
43+
if (trackNode === undefined) {
44+
// If we can't find our track node, return empty query
45+
return 'select cast(0 as bigint) as ts, cast(0 as real) as value where 0';
46+
}
47+
48+
// Get all child track datasets
49+
const childDatasets: Dataset[] = [];
50+
for (const child of trackNode.children) {
51+
if (child.uri === undefined) continue;
52+
53+
const childTrack = this.trace.tracks.getTrack(child.uri);
54+
if (childTrack === undefined) continue;
55+
56+
const dataset = childTrack.renderer.getDataset?.();
57+
if (dataset !== undefined) {
58+
childDatasets.push(dataset);
59+
}
60+
}
61+
62+
// If no child datasets, return empty query
63+
if (childDatasets.length === 0) {
64+
return 'select cast(0 as bigint) as ts, cast(0 as real) as value where 0';
65+
}
66+
67+
// Create a union of all child datasets
68+
const unionDataset = createUnionDataset(childDatasets).optimize();
69+
70+
// Check if the union dataset implements the required schema (ts and dur columns)
71+
const requiredSchema = {ts: LONG, dur: LONG};
72+
if (!unionDataset.implements(requiredSchema)) {
73+
// Dataset doesn't have ts/dur, can't create summary
74+
return 'select cast(0 as bigint) as ts, cast(0 as real) as value where 0';
75+
}
76+
77+
// Use intervals_overlap_count to compute the number of active intervals
78+
// across all child tracks at any point in time
79+
return `
80+
select ts, cast(value as real) as value
81+
from intervals_overlap_count!(
82+
(
83+
select ts, dur
84+
from (${unionDataset.query()})
85+
where dur != -1
86+
),
87+
ts,
88+
dur
89+
)
90+
`;
91+
}
92+
}

0 commit comments

Comments
 (0)