@@ -70,20 +70,46 @@ private void Close(MeasureScope scope)
70
70
/// <inheritdoc />
71
71
public string GetResult ( )
72
72
{
73
+ int paddingLength = GetPaddingLength ( ) ;
74
+
73
75
var builder = new StringBuilder ( ) ;
76
+ WriteResult ( builder , paddingLength ) ;
77
+
78
+ return builder . ToString ( ) ;
79
+ }
80
+
81
+ private int GetPaddingLength ( )
82
+ {
83
+ int maxLength = 0 ;
74
84
75
85
foreach ( MeasureScope scope in _completedScopes )
76
86
{
77
- scope . WriteResult ( builder , 0 ) ;
87
+ int nextLength = scope . GetPaddingLength ( ) ;
88
+ maxLength = Math . Max ( maxLength , nextLength ) ;
78
89
}
79
90
80
91
if ( _activeScopeStack . Any ( ) )
81
92
{
82
93
MeasureScope scope = _activeScopeStack . Peek ( ) ;
83
- scope . WriteResult ( builder , 0 ) ;
94
+ int nextLength = scope . GetPaddingLength ( ) ;
95
+ maxLength = Math . Max ( maxLength , nextLength ) ;
84
96
}
85
97
86
- return builder . ToString ( ) ;
98
+ return maxLength + 3 ;
99
+ }
100
+
101
+ private void WriteResult ( StringBuilder builder , int paddingLength )
102
+ {
103
+ foreach ( MeasureScope scope in _completedScopes )
104
+ {
105
+ scope . WriteResult ( builder , 0 , paddingLength ) ;
106
+ }
107
+
108
+ if ( _activeScopeStack . Any ( ) )
109
+ {
110
+ MeasureScope scope = _activeScopeStack . Peek ( ) ;
111
+ scope . WriteResult ( builder , 0 , paddingLength ) ;
112
+ }
87
113
}
88
114
89
115
public void Dispose ( )
@@ -132,6 +158,25 @@ public MeasureScope SpawnChild(CascadingCodeTimer owner, string name, bool exclu
132
158
return childScope ;
133
159
}
134
160
161
+ public int GetPaddingLength ( )
162
+ {
163
+ return GetPaddingLength ( 0 ) ;
164
+ }
165
+
166
+ private int GetPaddingLength ( int indent )
167
+ {
168
+ int selfLength = indent * 2 + Name . Length ;
169
+ int maxChildrenLength = 0 ;
170
+
171
+ foreach ( MeasureScope child in _children )
172
+ {
173
+ int nextLength = child . GetPaddingLength ( indent + 1 ) ;
174
+ maxChildrenLength = Math . Max ( nextLength , maxChildrenLength ) ;
175
+ }
176
+
177
+ return Math . Max ( selfLength , maxChildrenLength ) ;
178
+ }
179
+
135
180
private TimeSpan GetElapsedInSelf ( )
136
181
{
137
182
return GetElapsedInTotal ( ) - GetElapsedInChildren ( ) ;
@@ -175,26 +220,26 @@ private TimeSpan GetSkippedInChildren()
175
220
return skippedInChildren ;
176
221
}
177
222
178
- public void WriteResult ( StringBuilder builder , int indent )
223
+ public void WriteResult ( StringBuilder builder , int indent , int paddingLength )
179
224
{
180
225
TimeSpan timeElapsedGlobal = GetElapsedInTotal ( ) - GetSkippedInTotal ( ) ;
181
- WriteResult ( builder , indent , timeElapsedGlobal ) ;
226
+ WriteResult ( builder , indent , timeElapsedGlobal , paddingLength ) ;
182
227
}
183
228
184
- private void WriteResult ( StringBuilder builder , int indent , TimeSpan timeElapsedGlobal )
229
+ private void WriteResult ( StringBuilder builder , int indent , TimeSpan timeElapsedGlobal , int paddingLength )
185
230
{
186
231
TimeSpan timeElapsedInSelf = GetElapsedInSelf ( ) ;
187
232
double scaleElapsedInSelf = timeElapsedGlobal != TimeSpan . Zero ? timeElapsedInSelf / timeElapsedGlobal : 0 ;
188
233
189
234
WriteIndent ( builder , indent ) ;
190
235
builder . Append ( Name ) ;
191
- builder . Append ( ": " ) ;
192
- builder . Append ( timeElapsedInSelf . ToString ( "G ", CultureInfo . InvariantCulture ) ) ;
236
+ WritePadding ( builder , indent , paddingLength ) ;
237
+ builder . AppendFormat ( CultureInfo . InvariantCulture , "{0,19:G} ", timeElapsedInSelf ) ;
193
238
194
239
if ( ! _excludeInRelativeCost )
195
240
{
196
- builder . Append ( " - " ) ;
197
- builder . Append ( scaleElapsedInSelf . ToString ( "P ", CultureInfo . InvariantCulture ) ) ;
241
+ builder . Append ( " ... " ) ;
242
+ builder . AppendFormat ( CultureInfo . InvariantCulture , "{0,7:#0.00%} ", scaleElapsedInSelf ) ;
198
243
}
199
244
200
245
if ( _stoppedAt == null )
@@ -206,7 +251,7 @@ private void WriteResult(StringBuilder builder, int indent, TimeSpan timeElapsed
206
251
207
252
foreach ( MeasureScope child in _children )
208
253
{
209
- child . WriteResult ( builder , indent + 1 , timeElapsedGlobal ) ;
254
+ child . WriteResult ( builder , indent + 1 , timeElapsedGlobal , paddingLength ) ;
210
255
}
211
256
}
212
257
@@ -215,6 +260,14 @@ private static void WriteIndent(StringBuilder builder, int indent)
215
260
builder . Append ( new string ( ' ' , indent * 2 ) ) ;
216
261
}
217
262
263
+ private void WritePadding ( StringBuilder builder , int indent , int paddingLength )
264
+ {
265
+ string padding = new string ( '.' , paddingLength - Name . Length - indent * 2 ) ;
266
+ builder . Append ( ' ' ) ;
267
+ builder . Append ( padding ) ;
268
+ builder . Append ( ' ' ) ;
269
+ }
270
+
218
271
public void Dispose ( )
219
272
{
220
273
if ( _stoppedAt == null )
0 commit comments