|
10 | 10 | using System; |
11 | 11 | using System.Collections.Generic; |
12 | 12 | using System.IO; |
| 13 | +using System.Text; |
13 | 14 | using System.Threading; |
14 | 15 |
|
15 | 16 | namespace Stats |
@@ -91,6 +92,7 @@ public static void ToHtml(TextWriter writer, Microsoft.Diagnostics.Tracing.Analy |
91 | 92 |
|
92 | 93 | public static void ToTxt(string filePath, TraceProcess process, Microsoft.Diagnostics.Tracing.RuntimeLoaderStats runtimeOps, string[] filters, bool tree) |
93 | 94 | { |
| 95 | + bool csv = filePath.EndsWith("csv"); |
94 | 96 | using (var writer = File.CreateText(filePath)) |
95 | 97 | { |
96 | 98 | writer.WriteLine("\"ThreadId \",\"Start time\",\"Inclusive\",\"Exclusive\",\"RuntimeOperation\",\"Process\""); |
@@ -133,25 +135,49 @@ public static void ToTxt(string filePath, TraceProcess process, Microsoft.Diagno |
133 | 135 | if (seenEvents.Contains(eventData.End.EventId)) |
134 | 136 | inclusiveTimeStr = ""; |
135 | 137 |
|
| 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(); |
136 | 141 |
|
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)},\""); |
139 | 142 | int stackDepth = eventData.StackDepth; |
140 | 143 | for (int iStackDepth = 0; iStackDepth < stackDepth; iStackDepth++) |
141 | | - writer.Write(" |"); |
| 144 | + eventName.Append(" |"); |
142 | 145 |
|
143 | 146 | if (seenEvents.Contains(eventData.End.EventId)) |
144 | | - writer.Write(" +"); |
| 147 | + eventName.Append(" +"); |
145 | 148 | else |
146 | | - writer.Write("--"); |
| 149 | + eventName.Append("--"); |
147 | 150 |
|
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)}"); |
150 | 153 | seenEvents.Add(eventData.End.EventId); |
151 | 154 | } |
152 | 155 | } |
153 | 156 | } |
154 | 157 | } |
| 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 | + } |
155 | 181 | } |
156 | 182 |
|
157 | 183 | public static double TotalCPUMSec(Microsoft.Diagnostics.Tracing.Analysis.TraceProcess incompleteStatsProc, Microsoft.Diagnostics.Tracing.RuntimeLoaderStats runtimeOps) |
|
0 commit comments