Skip to content

Commit 3cd6d57

Browse files
authored
Fix for Issue 109 - PopulateCpuWakeEvents - ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'index') (#110)
-Add some of the waker metadata as default hidden columns
1 parent bf5b380 commit 3cd6d57

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

PerfettoCds/Pipeline/CompositeDataCookers/PerfettoCpuSchedEventCooker.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,22 @@ void PopulateCpuWakeEvents(IDataExtensionRetrieval requiredData, ProcessedEventD
157157
PerfettoThreadEvent wokenThread = tidToThreadMap[wokenTid];
158158
string wokenThreadName = wokenThread.Name;
159159
var wokenPid = wokenThread.Upid;
160-
string wokenProcessName = wokenPid != null ? upidToProcessMap[wokenPid.Value].Name : wake.Args.ElementAt(0).Value.ToString(); // This field name is comms but it is woken process name.
160+
object comm;
161+
wake.Args.TryGetValue("comm", out comm); // This field name is comm but it is woken process name.
162+
string wokenProcessName = wokenPid != null ? upidToProcessMap[wokenPid.Value].Name : (string)comm;
161163

162164
string wakerThreadName = wake.ThreadName;
163165
var wakerTid = wake.Tid;
164166
PerfettoThreadEvent wakerThread = tidToThreadMap[wakerTid];
165167
var wakerPid = wakerThread.Upid;
166168
string wakerProcessName = wakerPid != null ? upidToProcessMap[wakerPid.Value].Name : String.Empty;
167169

170+
object prio;
171+
wake.Args.TryGetValue("prio", out prio);
172+
object success;
173+
wake.Args.TryGetValue("success", out success);
174+
object target_cpu;
175+
wake.Args.TryGetValue("target_cpu", out target_cpu);
168176
PerfettoCpuWakeEvent ev = new PerfettoCpuWakeEvent
169177
(
170178
wokenProcessName: wokenProcessName,
@@ -176,10 +184,10 @@ void PopulateCpuWakeEvents(IDataExtensionRetrieval requiredData, ProcessedEventD
176184
wakerThreadName: wakerThreadName,
177185
wakerTid: wakerTid,
178186
timestamp: wake.StartTimestamp,
179-
success: int.Parse(wake.Args.ElementAt(3).Value.ToString()), // Success is at index 3
187+
success: success == null ? -1 : (int)(long)success,
180188
cpu: wake.Cpu,
181-
targetCpu: int.Parse(wake.Args.ElementAt(4).Value.ToString()), // TargetCpu is at index 4
182-
priority: int.Parse(wake.Args.ElementAt(2).Value.ToString()) // Priority is at index 2
189+
targetCpu: target_cpu == null ? -1 : (int)(long)target_cpu,
190+
priority: prio == null ? -1 : (int)(long)prio
183191
);
184192

185193
this.CpuWakeEvents.AddEvent(ev);

PerfettoCds/Pipeline/Tables/PerfettoCpuSchedTable.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,19 @@ public class PerfettoCpuSchedTable
8484
new UIHints { Width = 70 });
8585

8686
private static readonly ColumnConfiguration WakerPriorityColumn = new ColumnConfiguration(
87-
new ColumnMetadata(new Guid("{E98DFD4E-6931-49E2-A6E5-6CAC538C7A4E}"), "WakerPriority", "Priority of the waker threadd"),
87+
new ColumnMetadata(new Guid("{E98DFD4E-6931-49E2-A6E5-6CAC538C7A4E}"), "WakerPriority", "Priority of the waker thread"),
88+
new UIHints { Width = 70 });
89+
90+
private static readonly ColumnConfiguration WakerPidColumn = new ColumnConfiguration(
91+
new ColumnMetadata(new Guid("{2978F5AD-2C73-462F-8850-5910BCA6F251}"), "WakerPid", "Pid of the waker thread"),
92+
new UIHints { Width = 70 });
93+
94+
private static readonly ColumnConfiguration WakerSuccessColumn = new ColumnConfiguration(
95+
new ColumnMetadata(new Guid("{4F990FD6-9AD0-4952-B52C-3E0A15FA6A85}"), "WakerSuccess", "Success of the waker"),
96+
new UIHints { Width = 70 });
97+
98+
private static readonly ColumnConfiguration WakerTargetCpuColumn = new ColumnConfiguration(
99+
new ColumnMetadata(new Guid("{C6E97388-A240-474A-B0CD-16C66044A55F}"), "WakerTargetCpu", "Target CPU of the waker thread"),
88100
new UIHints { Width = 70 });
89101

90102
private static readonly ColumnConfiguration WakeTimestampColumn = new ColumnConfiguration(
@@ -145,9 +157,12 @@ public static void BuildTable(ITableBuilder tableBuilder, IDataExtensionRetrieva
145157
tableGenerator.AddColumn(WakeEventFoundColumn, baseProjection.Compose(x => x.WakeEvent != null));
146158
tableGenerator.AddColumn(WakerProcessNameColumn, baseProjection.Compose(x => x.WakeEvent?.WakerProcessName ?? String.Empty));
147159
tableGenerator.AddColumn(WakerThreadNameColumn, baseProjection.Compose(x => x.WakeEvent?.WakerThreadName ?? String.Empty));
148-
tableGenerator.AddColumn(WakerTidColumn, baseProjection.Compose(x => x.WakeEvent?.WakerTid ?? -1));
149-
tableGenerator.AddColumn(WakerPriorityColumn, baseProjection.Compose(x => x.WakeEvent?.Priority ?? -1));
160+
tableGenerator.AddColumn(WakerPidColumn, baseProjection.Compose(x => x.WakeEvent?.WakerPid ?? -1));
161+
tableGenerator.AddColumn(WakerTidColumn, baseProjection.Compose(x => x.WakeEvent?.WakerTid));
162+
tableGenerator.AddColumn(WakerPriorityColumn, baseProjection.Compose(x => x.WakeEvent?.Priority));
150163
tableGenerator.AddColumn(WakerCpuColumn, baseProjection.Compose(x => x.WakeEvent != null ? (int)x.WakeEvent.Cpu : -1));
164+
tableGenerator.AddColumn(WakerSuccessColumn, baseProjection.Compose(x => x.WakeEvent?.Success));
165+
tableGenerator.AddColumn(WakerTargetCpuColumn, baseProjection.Compose(x => x.WakeEvent?.TargetCpu));
151166
tableGenerator.AddColumn(WakeTimestampColumn, baseProjection.Compose(x => x.WakeEvent?.Timestamp ?? Timestamp.MinValue));
152167
tableGenerator.AddColumn(SchedulingLatencyColumn, baseProjection.Compose(x => x.SchedulingLatency));
153168
tableGenerator.AddColumn(WaitDurationColumn, baseProjection.Compose(x => x.WaitDuration));

PerfettoUnitTest/PerfettoUnitTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ public void TestAndroidTrace()
133133
Assert.IsTrue(cpuSchedEventData[9581].WakeEvent.WakerTid == 19701);
134134
Assert.IsTrue(cpuSchedEventData[9581].WakeEvent.WakerThreadName == "kworker/u16:13");
135135

136+
Assert.IsTrue(cpuSchedEventData[5802].WakeEvent.WakerProcessName == "TraceLogApiTest");
137+
Assert.IsTrue(cpuSchedEventData[5802].WakeEvent.WakerPid == 1);
138+
Assert.IsTrue(cpuSchedEventData[5802].WakeEvent.Priority == 120);
139+
Assert.IsTrue(cpuSchedEventData[5802].WakeEvent.Success == 1);
140+
Assert.IsTrue(cpuSchedEventData[5802].WakeEvent.TargetCpu == 1);
141+
136142
// Previous scheduling event validation
137143
Assert.IsTrue(cpuSchedEventData[9581].PreviousSchedulingEvent.EndState == "Task Dead");
138144
Assert.IsTrue(cpuSchedEventData[9581].PreviousSchedulingEvent.Tid == cpuSchedEventData[9581].Tid);

0 commit comments

Comments
 (0)