-
Notifications
You must be signed in to change notification settings - Fork 617
Add skipped sample as a separate track #3255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5b10313
d0ac527
174886a
c46c63a
1d0c1a0
0bbd8d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -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> = { | ||
| 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); | ||
|
|
||
|
|
@@ -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)`, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still not a fan of "skipped" because:
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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
||
There was a problem hiding this comment.
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.