Skip to content

Commit a8dfe39

Browse files
authored
Align GenericEvents process & thread display with CPU Scheduling (#49)
* Align GenericEvents process & thread display with CPU Scheduling to make it easier to find the exact thread that is consuming CPU between tables
1 parent 1e2a9a7 commit a8dfe39

File tree

5 files changed

+40
-21
lines changed

5 files changed

+40
-21
lines changed

PerfettoCds/Pipeline/CompositeDataCookers/PerfettoCpuSchedEventCooker.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,24 @@ public void OnDataAvailable(IDataExtensionRetrieval requiredData)
5252
// those respective tables
5353
var joined = from schedSlice in schedSliceData
5454
join thread in threadData on schedSlice.Utid equals thread.Utid
55-
join process in processData on thread.Upid equals process.Upid into pd from process in pd.DefaultIfEmpty()
56-
select new { schedSlice, thread, process };
55+
join threadProcess in processData on thread.Upid equals threadProcess.Upid into pd from threadProcess in pd.DefaultIfEmpty()
56+
select new { schedSlice, thread, threadProcess };
5757

5858
// Create events out of the joined results
5959
foreach (var result in joined)
6060
{
61+
// An event can have a thread+process or just a process
62+
string processName = string.Empty;
63+
string threadName = $"{result.thread.Name} ({result.thread.Tid})";
64+
if (result.threadProcess != null)
65+
{
66+
processName = $"{result.threadProcess.Name} ({result.threadProcess.Pid})";
67+
}
68+
6169
PerfettoCpuSchedEvent ev = new PerfettoCpuSchedEvent
6270
(
63-
result.process?.Name,
64-
result.thread.Name,
71+
processName,
72+
threadName,
6573
new TimestampDelta(result.schedSlice.Duration),
6674
new Timestamp(result.schedSlice.RelativeTimestamp),
6775
new Timestamp(result.schedSlice.RelativeTimestamp + result.schedSlice.Duration),

PerfettoCds/Pipeline/CompositeDataCookers/PerfettoFtraceEventCooker.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public void OnDataAvailable(IDataExtensionRetrieval requiredData)
6464
// Thread and process info is contained in their respective tables
6565
var joined = from raw in rawData
6666
join thread in threadData on raw.Utid equals thread.Utid
67-
join process in processData on thread.Upid equals process.Upid into pd from process in pd.DefaultIfEmpty()
67+
join threadProcess in processData on thread.Upid equals threadProcess.Upid into pd from threadProcess in pd.DefaultIfEmpty()
6868
join arg in argsData on raw.ArgSetId equals arg.ArgSetId into args
69-
select new { raw, args, thread, process };
69+
select new { raw, args, thread, threadProcess };
7070

7171
// Create events out of the joined results
7272
foreach (var result in joined)
@@ -102,11 +102,19 @@ join arg in argsData on raw.ArgSetId equals arg.ArgSetId into args
102102
}
103103
}
104104

105+
// An event can have a thread+process or just a process
106+
string processName = string.Empty;
107+
string threadName = $"{result.thread.Name} ({result.thread.Tid})";
108+
if (result.threadProcess != null)
109+
{
110+
processName = $"{result.threadProcess.Name} ({result.threadProcess.Pid})";
111+
}
112+
105113
PerfettoFtraceEvent ev = new PerfettoFtraceEvent
106114
(
107115
new Timestamp(result.raw.RelativeTimestamp),
108-
result.process?.Name,
109-
result.thread.Name,
116+
processName,
117+
threadName,
110118
result.raw.Cpu,
111119
result.raw.Name,
112120
values,

PerfettoCds/Pipeline/CompositeDataCookers/PerfettoGenericEventCooker.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,19 @@ join processTrack in processTrackData on slice.TrackId equals processTrack.Id in
227227

228228
string processName = string.Empty;
229229
string threadName = string.Empty;
230+
if (result.thread != null)
231+
{
232+
threadName = $"{result.thread.Name} ({result.thread.Tid})";
233+
}
230234

231235
// An event can have a thread+process or just a process
232236
if (result.threadProcess != null)
233237
{
234-
processName = $"{result.threadProcess.Name} {result.threadProcess.Pid}";
235-
threadName = $"{result.thread.Name} {result.thread.Tid}";
238+
processName = $"{result.threadProcess.Name} ({result.threadProcess.Pid})";
236239
}
237-
if (result.process != null)
240+
else if (result.process != null)
238241
{
239-
processName = $"{result.process.Name} {result.process.Pid}";
242+
processName = $"{result.process.Name} ({result.process.Pid})";
240243
}
241244

242245
int parentTreeDepthLevel = 0;

PerfettoCds/Pipeline/Tables/PerfettoCpuSchedTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static void BuildTable(ITableBuilder tableBuilder, IDataExtensionRetrieva
101101

102102
// We want to exclude the idle thread ('swapper' on Android/Linux) from the display because it messes up CPU usage and clutters
103103
// the scheduler view
104-
const string swapperIdleFilter = "[Thread]:=\"swapper\"";
104+
const string swapperIdleFilter = "[Thread]:=\"swapper (0)\"";
105105

106106
var cpuSchedConfig = new TableConfiguration("CPU Scheduling")
107107
{

PerfettoUnitTest/PerfettoUnitTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,28 @@ public void TestAndroidTrace()
6666
nameof(PerfettoGenericEventCooker.GenericEvents)));
6767
Assert.IsTrue(genericEventData.Count == 1);
6868
Assert.IsTrue(genericEventData[0].EventName == "Hello Trace");
69-
Assert.IsTrue(genericEventData[0].Thread == "TraceLogApiTest 20855");
70-
Assert.IsTrue(genericEventData[0].Process == "TraceLogApiTest 20855");
69+
Assert.IsTrue(genericEventData[0].Thread == "TraceLogApiTest (20855)");
70+
Assert.IsTrue(genericEventData[0].Process == "TraceLogApiTest (20855)");
7171

7272
var cpuSchedEventData = RuntimeExecutionResults.QueryOutput<ProcessedEventData<PerfettoCpuSchedEvent>>(
7373
new DataOutputPath(
7474
PerfettoPluginConstants.CpuSchedEventCookerPath,
7575
nameof(PerfettoCpuSchedEventCooker.CpuSchedEvents)));
7676
Assert.IsTrue(cpuSchedEventData.Count == 15267);
77-
Assert.IsTrue(cpuSchedEventData[0].ThreadName == "kworker/u17:9");
77+
Assert.IsTrue(cpuSchedEventData[0].ThreadName == "kworker/u17:9 (834)");
7878
Assert.IsTrue(cpuSchedEventData[1].EndState == "Task Dead");
7979
Assert.IsTrue(cpuSchedEventData[0].ProcessName == string.Empty);
8080

8181
Assert.IsTrue(cpuSchedEventData[5801].EndState == "Runnable");
82-
Assert.IsTrue(cpuSchedEventData[5801].ThreadName == "TraceLogApiTest");
83-
Assert.IsTrue(cpuSchedEventData[5801].ProcessName == "TraceLogApiTest");
82+
Assert.IsTrue(cpuSchedEventData[5801].ThreadName == "TraceLogApiTest (20855)");
83+
Assert.IsTrue(cpuSchedEventData[5801].ProcessName == "TraceLogApiTest (20855)");
8484

8585
var ftraceEventData = RuntimeExecutionResults.QueryOutput<ProcessedEventData<PerfettoFtraceEvent>>(
8686
new DataOutputPath(
8787
PerfettoPluginConstants.FtraceEventCookerPath,
8888
nameof(PerfettoFtraceEventCooker.FtraceEvents)));
8989
Assert.IsTrue(ftraceEventData.Count == 35877);
90-
Assert.IsTrue(ftraceEventData[0].ThreadName == "swapper");
90+
Assert.IsTrue(ftraceEventData[0].ThreadName == "swapper (0)");
9191
Assert.IsTrue(ftraceEventData[1].Cpu == 3);
9292

9393
var cpuFreqEventData = RuntimeExecutionResults.QueryOutput<ProcessedEventData<PerfettoCpuFrequencyEvent>>(
@@ -132,14 +132,14 @@ public void TestChromeTrace()
132132
nameof(PerfettoGenericEventCooker.GenericEvents)));
133133
Assert.IsTrue(genericEventData.Count == 147906);
134134
Assert.IsTrue(genericEventData[1].EventName == "PipelineReporter");
135-
Assert.IsTrue(genericEventData[1].Process == "Renderer 27768");
135+
Assert.IsTrue(genericEventData[1].Process == "Renderer (27768)");
136136
Assert.IsTrue(genericEventData[1].ParentId == null);
137137
Assert.IsTrue(genericEventData[1].ParentTreeDepthLevel == 0);
138138
Assert.IsTrue(genericEventData[1].ParentEventNameTree[0] == "[Root]");
139139
Assert.IsTrue(genericEventData[1].ParentEventNameTree[1] == "PipelineReporter");
140140

141141
Assert.IsTrue(genericEventData[2].EventName == "BeginImplFrameToSendBeginMainFrame");
142-
Assert.IsTrue(genericEventData[2].Process == "Renderer 27768");
142+
Assert.IsTrue(genericEventData[2].Process == "Renderer (27768)");
143143
Assert.IsTrue(genericEventData[2].ParentId == 1);
144144
Assert.IsTrue(genericEventData[2].ParentTreeDepthLevel == 1);
145145
Assert.IsTrue(genericEventData[2].ParentEventNameTree[1] == "PipelineReporter");

0 commit comments

Comments
 (0)