Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ SELECT
utid,
count() AS perf_sample_cnt
FROM perf_sample
WHERE
callsite_id IS NOT NULL
GROUP BY
utid;

Expand Down
70 changes: 68 additions & 2 deletions ui/src/plugins/dev.perfetto.LinuxPerf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
import {PerfettoPlugin} from '../../public/plugin';
import {AreaSelection, areaSelectionsEqual} from '../../public/selection';
import {Trace} from '../../public/trace';
import {Setting, SettingDescriptor} from '../../public/settings';
import {App} from '../../public/app';
import {COUNTER_TRACK_KIND} from '../../public/track_kinds';
import {getThreadUriPrefix} from '../../public/utils';
import {TrackNode} from '../../public/workspace';
Expand All @@ -28,23 +30,44 @@ import {Flamegraph} from '../../widgets/flamegraph';
import ProcessThreadGroupsPlugin from '../dev.perfetto.ProcessThreadGroups';
import TraceProcessorTrackPlugin from '../dev.perfetto.TraceProcessorTrack';
import {TraceProcessorCounterTrack} from '../dev.perfetto.TraceProcessorTrack/trace_processor_counter_track';
import {createPerfCallsitesTrack} from './perf_samples_profile_track';
import {
createPerfCallsitesTrack,
createSkippedCallsitesTrack,
} from './perf_samples_profile_track';
import {z} from 'zod';

const PERF_SAMPLES_PROFILE_TRACK_KIND = 'PerfSamplesProfileTrack';

function makeUriForProc(upid: number, sessionId: number) {
return `/process_${upid}/perf_samples_profile_${sessionId}`;
}

export default class implements PerfettoPlugin {
export default class LinuxPerf implements PerfettoPlugin {
static readonly id = 'dev.perfetto.LinuxPerf';
static readonly dependencies = [
ProcessThreadGroupsPlugin,
TraceProcessorTrackPlugin,
];
private static showSkippedPerfSamples: Setting<boolean>;

static onActivate(app: App): void {
const boolSettingDesc: SettingDescriptor<boolean> = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we discussed flagging, I meant feature_flags.ts, not settings.

The settings are toggles for end users that we expect to keep around, while flags are for things that are still in development or where the UX is not finalised (which is the case here).

However I'm also no longer insisting on this being flagged. We can always roll back if the tracks prove surprising.

id: `showSkippedPerfSamples`,
name: 'Show skipped perf samples',
description:
'Whether to display the skipped perf samples under the process track.',
schema: z.boolean(),
defaultValue: true,
requiresReload: false,
};
this.showSkippedPerfSamples = app.settings.register(boolSettingDesc);
}

async onTraceLoad(trace: Trace): Promise<void> {
await this.addProcessPerfSamplesTracks(trace);
if (LinuxPerf.showSkippedPerfSamples.get()) {
await this.addSkippedProcessPerfSamplesTracks(trace);
}
await this.addThreadPerfSamplesTracks(trace);
await this.addPerfCounterTracks(trace);

Expand Down Expand Up @@ -152,6 +175,49 @@ export default class implements PerfettoPlugin {
});
}

private async addSkippedProcessPerfSamplesTracks(trace: Trace) {
const pResult = await trace.engine.query(`
SELECT DISTINCT upid
FROM perf_sample
JOIN thread USING (utid)
JOIN perf_counter_track AS pct USING (perf_session_id)
WHERE
callsite_id IS NULL AND
upid IS NOT NULL AND
pct.is_timebase
ORDER BY upid
`);

const upids: number[] = [];
for (const it = pResult.iter({upid: NUM}); it.valid(); it.next()) {
upids.push(it.upid);
}

for (const upid of upids) {
// Only add one track since we are only adding skipped samples;
const uri = `/process_${upid}/perf_samples_profile`;
trace.tracks.registerTrack({
uri,
tags: {
kinds: [PERF_SAMPLES_PROFILE_TRACK_KIND],
upid,
},
renderer: createSkippedCallsitesTrack(trace, uri, upid),
});
const group = trace.plugins
.getPlugin(ProcessThreadGroupsPlugin)
.getGroupForProcess(upid);
const summaryTrack = new TrackNode({
uri,
name: `Process callstacks (skipped)`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not a fan of "skipped" because:

  1. it's not clear to users what is meant by a skipped sample (is it an error?)
  2. it's completely valid to do sampling of counters without callstacks, in which case all samples will appear "skipped".

I'm struggling to suggest a better name. How about "Unclassified perf samples"?

isSummary: false,
headless: false,
sortOrder: -40,
});
group?.addChildInOrder(summaryTrack);
}
}

private async addThreadPerfSamplesTracks(trace: Trace) {
const tResult = await trace.engine.query(`
SELECT DISTINCT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,52 @@ export function createPerfCallsitesTrack(
});
}

export function createSkippedCallsitesTrack(
trace: Trace,
uri: string,
upid?: number,
utid?: number,
sessionId?: number,
) {
const constraints = [];
if (upid !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's quite a bit of copypasted code that is never used. I've started a more minimal implementation here (including a different visual styling to avoid confusion with callstacks). Can we similarly cut down the unnecessary code in this patch?

constraints.push(`(upid = ${upid})`);
}
if (utid !== undefined) {
constraints.push(`(utid = ${utid})`);
}
if (sessionId !== undefined) {
constraints.push(`(perf_session_id = ${sessionId})`);
}
const trackConstraints = constraints.join(' AND ');

return SliceTrack.create({
trace,
uri,
dataset: new SourceDataset({
schema: {
id: NUM,
ts: LONG,
callsiteId: NUM,
},
src: `
SELECT
p.id,
ts,
0 AS callsiteId,
upid
FROM perf_sample AS p
JOIN thread USING (utid)
WHERE callsite_id IS NULL
AND ${trackConstraints}
ORDER BY ts
`,
}),
sliceName: () => 'Perf sample (skipped)',
colorizer: (row) => getColorForSample(row.callsiteId),
});
}

function renderDetailsPanel(
trace: Trace,
flamegraph: QueryFlamegraph,
Expand Down
Loading