-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
Description
Description
dotnet-pgo dump crashes with System.InvalidOperationException: Cannot write a JSON property within an array when the .mibc file contains CallWeights data (caller-callee edge weights from CPU sampling).
Root cause
In Program.cs line 311-317, the dump code opens a JSON array for CallWeights but writes named properties directly inside it without wrapping each entry in a JSON object:
jsonWriter.WriteStartArray("CallWeights");
foreach (var callWeight in data.CallWeights)
{
jsonWriter.WriteString("Method", callWeight.Key.ToString()); // crash: property inside array
jsonWriter.WriteNumber("Weight", callWeight.Value);
}
jsonWriter.WriteEndArray();Fix
Add WriteStartObject() / WriteEndObject() around each array entry:
jsonWriter.WriteStartArray("CallWeights");
foreach (var callWeight in data.CallWeights)
{
jsonWriter.WriteStartObject();
jsonWriter.WriteString("Method", callWeight.Key.ToString());
jsonWriter.WriteNumber("Weight", callWeight.Value);
jsonWriter.WriteEndObject();
}
jsonWriter.WriteEndArray();Repro
Any .mibc file with CallWeights (produced by create-mibc from a trace with SampledProfileTraceData events or supplementary call graph data). The bug hasn't surfaced in practice because most .mibc files don't contain CallWeights.
dotnet-pgo dump -i profile-with-callweights.mibc -o dump.txt
Stack trace:
System.InvalidOperationException: Cannot write a JSON property within an array or as the first JSON token. Current token type is 'StartArray'.
at System.Text.Json.Utf8JsonWriter.OnValidateWritingPropertyFailed()
at Microsoft.Diagnostics.Tools.Pgo.Program.InnerDumpMain() in Program.cs:line 314
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status