Skip to content

Commit a97d89b

Browse files
authored
Don't create idle process groups without CPU usage (#142)
Check whether CPU data was recorded and, if not, do not attempt to sort processes and threads into "idle" groups. For android-graphics/sokatoa#1560 Signed-off-by: Christian W. Damus <[email protected]>
1 parent 09c00b6 commit a97d89b

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

ui/src/controller/track_decider.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ class TrackDecider {
201201
children: [],
202202
};
203203

204+
private hasCpuUsage = true;
205+
204206
// Set of |upid| from the |process| table recording
205207
// processes that are idle (< 0.1% CPU)
206208
private idleUpids = new Set<number>();
@@ -1736,7 +1738,10 @@ class TrackDecider {
17361738
// Don't need the Idle Threads group in a process that is idle
17371739
// because all of its threads would redundantly be in that group.
17381740
// And don't create a group for just one idle thread.
1739-
const idle = upid === null ? undefined : this.idleUtids.get(upid);
1741+
// And finally, idle has no meaning without CPU usage information
1742+
const idle = !this.hasCpuUsage || upid === null ?
1743+
undefined :
1744+
this.idleUtids.get(upid);
17401745
const isIdleProcess = upid !== null && this.idleUpids.has(upid);
17411746
return idle !== undefined && !isIdleProcess &&
17421747
(idle.has(utid) && idle.size > 1) ?
@@ -1862,8 +1867,11 @@ class TrackDecider {
18621867
// Map of process upid to its track group descriptor
18631868
const processTrackGroups = new Map<string, AddTrackGroupArgs>();
18641869

1865-
// Map of idle process upid to its track group for descriptor
1866-
const idleProcessTrackGroups = new Map<string, AddTrackGroupArgs>();
1870+
// Map of idle process upid to its track group for descriptor. But if we
1871+
// didn't capture CPU information then this concept has no meaning
1872+
const idleProcessTrackGroups = this.hasCpuUsage ?
1873+
new Map<string, AddTrackGroupArgs>() :
1874+
undefined;
18671875

18681876
// We want to create groups of tracks in a specific order.
18691877
// The tracks should be grouped:
@@ -2003,10 +2011,12 @@ class TrackDecider {
20032011
chromeProcessLabels: STR,
20042012
});
20052013

2006-
const idleProcessesGroupId = this.lazyTrackGroup('Idle Processes (< 0.1%)',
2007-
{collapsed: true,
2008-
description: 'CPU usage of an idle process accounts for less than 0.1% of the total trace duration.',
2009-
lazyParentGroup: this.processesGroup});
2014+
const idleProcessesGroupId = idleProcessTrackGroups ?
2015+
this.lazyTrackGroup('Idle Processes (< 0.1%)',
2016+
{collapsed: true,
2017+
description: 'CPU usage of an idle process accounts for less than 0.1% of the total trace duration.',
2018+
lazyParentGroup: this.processesGroup}) :
2019+
undefined;
20102020

20112021
// An "idle process" is measured against the duration of the trace.
20122022
// The threshold is 0.1%, or one one-thousandth, of the trace time.
@@ -2092,13 +2102,13 @@ class TrackDecider {
20922102
// many expanded process tracks for some perf traces, leading to
20932103
// jankyness.
20942104
collapsed: !hasHeapProfiles,
2095-
parentGroup: !idleProcess ?
2105+
parentGroup: !idleProcess || !idleProcessesGroupId ?
20962106
this.processesGroup() :
20972107
idleProcessesGroupId(),
20982108
};
20992109
this.trackGroupsToAdd.push(trackGroup);
21002110
processTrackGroups.set(pUuid, trackGroup);
2101-
if (idleProcess) {
2111+
if (idleProcess && idleProcessTrackGroups) {
21022112
idleProcessTrackGroups.set(pUuid, trackGroup);
21032113
}
21042114
}
@@ -2122,7 +2132,7 @@ class TrackDecider {
21222132

21232133
const totalProcessCount = threadsPerProcess.numRows();
21242134
const shownProcessCount = processTrackGroups.size;
2125-
const idleProcessCount = idleProcessTrackGroups.size;
2135+
const idleProcessCount = idleProcessTrackGroups?.size ?? 0;
21262136
const nullProcessCount = totalProcessCount - shownProcessCount;
21272137

21282138
if (shownProcessCount > 0) {
@@ -2139,7 +2149,7 @@ class TrackDecider {
21392149
}
21402150
}
21412151
}
2142-
if (idleProcessCount > 0) {
2152+
if (idleProcessCount > 0 && idleProcessesGroupId) {
21432153
// There are idle processes actually showing tracks
21442154
const idleProcessesGroup = this.getTrackGroup(idleProcessesGroupId());
21452155
if (idleProcessesGroup) {
@@ -2511,6 +2521,9 @@ class TrackDecider {
25112521
async decideTracks(filterTracks = false): Promise<DeferredAction[]> {
25122522
await this.defineMaxLayoutDepthSqlFunction();
25132523

2524+
const cpus = await this.engine.getCpus();
2525+
this.hasCpuUsage = cpus.length > 0;
2526+
25142527
// Add first the global tracks that don't require per-process track groups.
25152528
await this.addCpuSchedulingTracks();
25162529
await this.addFtraceTrack(

0 commit comments

Comments
 (0)