-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #997 from dotnet/mu-20240211-improvements-data-acq…
…uisition-build-timings-measurements Manual updates 20241003 improvements data acquisition build timings measurements (20240211)
- Loading branch information
Showing
3 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#addin nuget:?package=ZString&version=2.6.0 | ||
#addin nuget:?package=ZString&version=2.6.0 | ||
|
||
using Cysharp.Text; | ||
|
||
System.Diagnostics.Stopwatch stopwatch; | ||
List<(DateTime timestamp, string task, TimeSpan duration)> TimingDataStopwatch; | ||
List<(DateTime timestamp, string task, TimeSpan duration)> TimingDataCake; | ||
|
||
Setup | ||
( | ||
context => | ||
{ | ||
// Executed BEFORE the first task. | ||
stopwatch = new System.Diagnostics.Stopwatch(); | ||
TimingDataStopwatch = new List<(DateTime timestamp, string task, TimeSpan duration)>(); | ||
TimingDataCake = new List<(DateTime timestamp, string task, TimeSpan duration)>(); | ||
return; | ||
} | ||
); | ||
|
||
Teardown | ||
( | ||
context => | ||
{ | ||
// Executed AFTER the last task. | ||
using(var sb1 = ZString.CreateStringBuilder()) | ||
using(var sb2 = ZString.CreateStringBuilder()) | ||
{ | ||
string line_1_1 = ZString.Format | ||
( | ||
"{0,25},{1,20},{2,40},{3,25}", | ||
"#TimingDataStopwatch", | ||
"data.timestamp", | ||
"data.task", | ||
"data.duration" | ||
); | ||
sb1.AppendLine(line_1_1); | ||
foreach(var data in TimingDataStopwatch) | ||
{ | ||
string line = ZString.Format | ||
( | ||
"{0,25},{1,20},{2,40},{3,25}", | ||
"#TimingDataStopwatch", | ||
data.timestamp.ToString("yyyyMMdd-HHmmss.FF"), | ||
data.task, | ||
data.duration | ||
); | ||
Information(line); | ||
sb1.AppendLine(line); | ||
} | ||
string line_2_1 = ZString.Format | ||
( | ||
"{0,25},{1,20},{2,40},{3,25}", | ||
"#TimingDataCake", | ||
"data.timestamp", | ||
"data.task", | ||
"data.duration" | ||
); | ||
sb2.AppendLine(line_2_1); | ||
foreach(var data in TimingDataCake) | ||
{ | ||
string line = ZString.Format | ||
( | ||
"{0,25},{1,20},{2,40},{3,25}", | ||
"#TimingDataCake", | ||
data.timestamp.ToString("yyyyMMdd-HHmmss.FF"), | ||
data.task, | ||
data.duration | ||
); | ||
Information(line); | ||
sb2.AppendLine(line); | ||
} | ||
EnsureDirectoryExists("./output/timing-data/"); | ||
string timestamp = DateTime.Now.ToString("yyyyMMdd-HHmmss"); | ||
string filename = context.GetCallerInfo().SourceFilePath.GetFilename().ToString(); | ||
System.IO.File.WriteAllText | ||
( | ||
$"./output/timing-data/{filename}.stopwatch.{timestamp}.csv", | ||
sb1.ToString() | ||
); | ||
System.IO.File.WriteAllText | ||
( | ||
$"./output/timing-data/{filename}.cake-timer.{timestamp}.csv", | ||
sb2.ToString() | ||
); | ||
EnsureDirectoryExists($"./data/timings/{timestamp}"); | ||
System.IO.File.WriteAllText | ||
( | ||
$"./data/timings/{timestamp}/{filename}.stopwatch.csv", | ||
sb1.ToString() | ||
); | ||
System.IO.File.WriteAllText | ||
( | ||
$"./data/timings/{timestamp}/{filename}.cake-timer.csv", | ||
sb2.ToString() | ||
); | ||
} | ||
return; | ||
} | ||
); | ||
|
||
TaskSetup | ||
( | ||
context => | ||
{ | ||
// Executed BEFORE the each task. | ||
stopwatch.Start(); | ||
return; | ||
} | ||
); | ||
|
||
TaskTeardown | ||
( | ||
context => | ||
{ | ||
stopwatch.Stop(); | ||
TimingDataStopwatch.Add( (DateTime.Now, context.Task.Name, stopwatch.Elapsed) ); | ||
TimingDataCake.Add( (DateTime.Now, context.Task.Name, context.Duration) ); | ||
} | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters