Skip to content

Commit ae92616

Browse files
committed
Cleanup Csv output so that jitted functions reliably are displayed
1 parent 0c9a16c commit ae92616

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

src/PerfView/RuntimeLoaderStats.cs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System;
1111
using System.Collections.Generic;
1212
using System.IO;
13+
using System.Text;
1314
using System.Threading;
1415

1516
namespace Stats
@@ -91,6 +92,7 @@ public static void ToHtml(TextWriter writer, Microsoft.Diagnostics.Tracing.Analy
9192

9293
public static void ToTxt(string filePath, TraceProcess process, Microsoft.Diagnostics.Tracing.RuntimeLoaderStats runtimeOps, string[] filters, bool tree)
9394
{
95+
bool csv = filePath.EndsWith("csv");
9496
using (var writer = File.CreateText(filePath))
9597
{
9698
writer.WriteLine("\"ThreadId \",\"Start time\",\"Inclusive\",\"Exclusive\",\"RuntimeOperation\",\"Process\"");
@@ -133,25 +135,49 @@ public static void ToTxt(string filePath, TraceProcess process, Microsoft.Diagno
133135
if (seenEvents.Contains(eventData.End.EventId))
134136
inclusiveTimeStr = "";
135137

138+
writer.Write($"{PadIfNotCsv(threadId.ToString(), 12)},{PadIfNotCsv(startTime.ToString("F3"), 12)},{PadIfNotCsv(inclusiveTimeStr, 11)},{PadIfNotCsv(exclusiveTime.ToString("F3"), 11)},");
139+
140+
StringBuilder eventName = new StringBuilder();
136141

137-
// writer.Write($"\"{threadId.ToString().PadLeft(12)}\",\"{startTime.ToString("F3").PadLeft(12)}\",\"{inclusiveTimeStr.PadLeft(9)}\",\"{exclusiveTime.ToString("F3").PadLeft(9)}\",\"");
138-
writer.Write($"{threadId.ToString().PadLeft(12)},{startTime.ToString("F3").PadLeft(12)},{inclusiveTimeStr.PadLeft(9)},{exclusiveTime.ToString("F3").PadLeft(9)},\"");
139142
int stackDepth = eventData.StackDepth;
140143
for (int iStackDepth = 0; iStackDepth < stackDepth; iStackDepth++)
141-
writer.Write(" |");
144+
eventName.Append(" |");
142145

143146
if (seenEvents.Contains(eventData.End.EventId))
144-
writer.Write(" +");
147+
eventName.Append(" +");
145148
else
146-
writer.Write("--");
149+
eventName.Append("--");
147150

148-
writer.Write(eventData.Name, false);
149-
writer.WriteLine("\",\"" + process.Name + "\"");
151+
eventName.Append(eventData.Name);
152+
writer.WriteLine($"{QuoteIfCsv(eventName.ToString())},{QuoteIfCsv(process.Name)}");
150153
seenEvents.Add(eventData.End.EventId);
151154
}
152155
}
153156
}
154157
}
158+
159+
return;
160+
161+
string PadIfNotCsv(string str, int pad)
162+
{
163+
if (!csv)
164+
{
165+
return str.PadLeft(pad);
166+
}
167+
return str;
168+
}
169+
170+
string QuoteIfCsv(string str)
171+
{
172+
if (csv)
173+
{
174+
return $"\"'{str}\"";
175+
}
176+
else
177+
{
178+
return str;
179+
}
180+
}
155181
}
156182

157183
public static double TotalCPUMSec(Microsoft.Diagnostics.Tracing.Analysis.TraceProcess incompleteStatsProc, Microsoft.Diagnostics.Tracing.RuntimeLoaderStats runtimeOps)

0 commit comments

Comments
 (0)