Skip to content

Commit 10f70d5

Browse files
Nancy LiDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Clean up |SyntheticCpuProfile| related code
- Update the declaration since it does not need |SyntheticBased| features. - Add the profile |id| field so we can create one when we create the fake trace event instead of in the Samples Handler. - Remove the |appendEvent| helper function in the SamplesIntegrator Bug: 426512102 Change-Id: Iabf915acfda5a2a0ff349673172856596e45705d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6711332 Commit-Queue: Paul Irish <[email protected]> Reviewed-by: Paul Irish <[email protected]>
1 parent c546705 commit 10f70d5

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

front_end/models/trace/handlers/SamplesHandler.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,9 @@ export function handleEvent(event: Types.Events.Event): void {
126126
// id and thread id are not really important, so we use the data
127127
// in the fake event. Should multi-thread CPU profiling be supported
128128
// we could use these fields in the event to pass thread info.
129-
const pid = event.pid;
130-
const tid = event.tid;
131-
// Create an arbitrary profile id.
132-
const profileId = '0x1' as Types.Events.ProfileID;
133-
const profileData = getOrCreatePreProcessedData(pid, profileId);
129+
const profileData = getOrCreatePreProcessedData(event.pid, event.id);
134130
profileData.rawProfile = event.args.data.cpuProfile;
135-
profileData.threadId = tid;
131+
profileData.threadId = event.tid;
136132
return;
137133
}
138134

front_end/models/trace/helpers/SamplesIntegrator.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -498,44 +498,32 @@ export class SamplesIntegrator {
498498

499499
static createFakeTraceFromCpuProfile(profile: Protocol.Profiler.Profile, tid: Types.Events.ThreadID):
500500
Types.File.TraceFile {
501-
const traceEvents: Types.Events.Event[] = [];
502-
503501
if (!profile) {
504-
return {traceEvents, metadata: {}};
502+
return {traceEvents: [], metadata: {}};
505503
}
506504
// The |Name.CPU_PROFILE| will let MetaHandler to set |traceIsGeneric| to false
507505
// The start time and duration is important here because we'll use them to determine the traceBounds
508506
// We use the start and end time of the profile (which is longer than all samples), so the Performance
509507
// panel won't truncate this time period.
510-
appendEvent(
511-
Types.Events.Name.CPU_PROFILE, {data: {cpuProfile: profile}}, profile.startTime,
512-
profile.endTime - profile.startTime, Types.Events.Phase.COMPLETE);
508+
const cpuProfileEvent: Types.Events.SyntheticCpuProfile = {
509+
cat: 'disabled-by-default-devtools.timeline',
510+
name: Types.Events.Name.CPU_PROFILE,
511+
ph: Types.Events.Phase.COMPLETE,
512+
pid: Types.Events.ProcessID(1),
513+
tid,
514+
ts: Types.Timing.Micro(profile.startTime),
515+
dur: Types.Timing.Micro(profile.endTime - profile.startTime),
516+
args: {data: {cpuProfile: profile}},
517+
// Create an arbitrary profile id.
518+
id: '0x1' as Types.Events.ProfileID,
519+
};
520+
513521
return {
514-
traceEvents,
522+
traceEvents: [cpuProfileEvent],
515523
metadata: {
516524
dataOrigin: Types.File.DataOrigin.CPU_PROFILE,
517525
}
518526
};
519-
520-
function appendEvent(
521-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
522-
name: string, args: any, ts: number, dur?: number, ph?: Types.Events.Phase, cat?: string): Types.Events.Event {
523-
const event: Types.Events.Event = {
524-
cat: cat || 'disabled-by-default-devtools.timeline',
525-
name,
526-
ph: ph || Types.Events.Phase.COMPLETE,
527-
pid: Types.Events.ProcessID(1),
528-
tid,
529-
ts: Types.Timing.Micro(ts),
530-
args,
531-
};
532-
533-
if (dur) {
534-
event.dur = Types.Timing.Micro(dur);
535-
}
536-
traceEvents.push(event);
537-
return event;
538-
}
539527
}
540528
}
541529

front_end/models/trace/types/TraceEvents.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,13 @@ export interface Sample extends Event {
140140
/**
141141
* A fake trace event created to support CDP.Profiler.Profiles in the
142142
* trace engine.
143+
*
144+
* Do not extend the SyntheticBased interface because this one doesn't have a raw trace event but a raw cpu profile.
145+
* Also we won't manage this event through SyntheticEventsManager.
143146
*/
144-
export interface SyntheticCpuProfile extends Instant, SyntheticBased<Phase.INSTANT> {
147+
export interface SyntheticCpuProfile extends Complete {
145148
name: Name.CPU_PROFILE;
149+
id: ProfileID;
146150
args: Args&{
147151
data: ArgsData & {
148152
cpuProfile: Protocol.Profiler.Profile,

0 commit comments

Comments
 (0)