You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commandline/object-model to inspect a binlog for errors/warnings #376
A typical way in with file logs are used esp. in local/dev-builds goes like this:
$warn=Get-Content msbuild.wrn
$err=Get-Content msbuild.err
if (warn.length -gt0) {
Write-Error"Warnings Found"
}
if (err.length -gt0) {
Write-Error"Errors Found"
}
I'm wondering if there is a simple way to replace file-logs with binary-logs for this type of scenario. Specifically, if there is a simple approach (for e.g., using powershell) to inspect a binary log for these (without replaying the log using msbuild - that would defeat the purpose of replacing file-logs with binary-logs):
You probably want your build to restore the NuGet package, and then write a simple csx file (C# interactive, that you can run via csi.exe), or PowerShell, or a simple console app that reads the binlog, reads all warnings, errors and prints them to the console, potentially using colors or tables.
The only surprise is the time it takes to read a log through Serialization.Read.
When dealing with text logs, testing its size or length is a quick operation. In this case, a simple program that reads and searches a 30MB binary-log for warnings takes about 50 seconds or so to load using Serialization.Read.
Somehow the viewer is able to load the log much faster.
The viewer sets the serverGC mode in app.config, which results in less GC pauses. There’s also a lower level API ReadRecords() that reads the raw records and doesn’t build the tree, it should be faster. Try that? There’s a sample on the website.
Even with server GC and ReadRecords, I'm not doing much better (around 40 secs on netcoreapp3.1, 4 seconds on net472). I'm calling into Replay directly since that and ReadRecordsFromDecompressedStream (which ReadRecords seems to use) seem to have similar complexity anyway, and Replay lets me just do one pass over the binary log to summarize stats.
Hey @stephentoub @danmosemsft Vatsan has found an interesting scenario where reading a binlog takes 4 seconds on .NET Desktop, but 40 seconds on Core 3.1.
The stack that I saw was taking all the time is ReadByte from a GzipStream, it's called millions of times (to read the binlog):
| ZLibNative.ZLibStreamHandle.Inflate Line 300
-- | --
| Inflater.Inflate Line 281
| Inflater.ReadInflateOutput Line 266
| Inflater.ReadOutput Line 122
| Inflater.InflateVerified Line 92
| Inflater.Inflate Line 55
| DeflateStream.ReadByte Line 229
| GZipStream.ReadByte Line 72
| BinaryReader.ReadBoolean Line 236
| BuildEventArgsReader.ReadTargetFinishedEventArgs Line 359
| BuildEventArgsReader.Read Line 71
| BinLogReader.Replay Line 78
| BinLogReader.Replay Line 37
| StructuredLoggerUtil..ctor Line 30
| Program.ProcessBinaryLog Line 29
| Program.Main Line 24
Is this something known? On Desktop Framework I see a similar native inflate stack, but it doesn't cost nearly as much. Would someone be able to take a look? Thanks!
Activity
KirillOsenkov commentedon Jul 9, 2020
Yes, everything the log viewer can do is also available via an API. All you need is StructuredLogger.dll from this NuGet package: https://www.nuget.org/packages/MSBuild.Structuredlogger
Here's an example of reading start/end times and durations of targets:
https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/master/src/Samples/TimesAndDurations/Program.cs
You probably want your build to restore the NuGet package, and then write a simple csx file (C# interactive, that you can run via csi.exe), or PowerShell, or a simple console app that reads the binlog, reads all warnings, errors and prints them to the console, potentially using colors or tables.
More examples are available at:
https://msbuildlog.com/#api
vatsan-madhavan commentedon Jul 11, 2020
I'll have to experiment with it to see how to read errors, warnings etc. I'll reach out again if I encounter problems.
KirillOsenkov commentedon Jul 12, 2020
Yes, try
build.FindChildrenRecursive<Error>andbuild.FindChildrenRecursive<Warning>KirillOsenkov commentedon Jul 12, 2020
you can bucketize them by parent project, sort, filter, etc
vatsan-madhavan commentedon Jul 12, 2020
This is what I ended up figuring out, which seems to work as expected.
The only surprise is the time it takes to read a log through
Serialization.Read.When dealing with text logs, testing its size or length is a quick operation. In this case, a simple program that reads and searches a 30MB binary-log for warnings takes about 50 seconds or so to load using
Serialization.Read.Somehow the viewer is able to load the log much faster.
What can I do to read and query logs faster?
vatsan-madhavan commentedon Jul 12, 2020
Something else I just noticed - .NET Framework is way faster that .NET Core (.NET Core is trimmed, ready-to-run, win-x64)
KirillOsenkov commentedon Jul 12, 2020
The viewer sets the serverGC mode in app.config, which results in less GC pauses. There’s also a lower level API ReadRecords() that reads the raw records and doesn’t build the tree, it should be faster. Try that? There’s a sample on the website.
vatsan-madhavan commentedon Jul 13, 2020
Even with server GC and
ReadRecords, I'm not doing much better (around 40 secs on netcoreapp3.1, 4 seconds on net472). I'm calling intoReplaydirectly since that andReadRecordsFromDecompressedStream(whichReadRecordsseems to use) seem to have similar complexity anyway, andReplaylets me just do one pass over the binary log to summarize stats.Here is what I'm doing - StructuredLoggerUtil.cs
Here is my binlog (personal OneDrive link to zipped file) - https://1drv.ms/u/s!Ah63gfGkKca4lsl2sy71gpkpM9TCog?e=ifgsMj. If you'd rather generate it yourself locally, it's just a binlog generated from https://github.com/vatsan-madhavan/pinvoke/tree/enable-binlog by running
build.ps1 -Restore -Build -BinaryLogKirillOsenkov commentedon Jul 13, 2020
Hey @stephentoub @danmosemsft Vatsan has found an interesting scenario where reading a binlog takes 4 seconds on .NET Desktop, but 40 seconds on Core 3.1.
Repro:
git clone https://github.com/vatsan-madhavan/MSBuildStructuredLogSummarymsbuild /rMSBuildBinLogSummary\bin\Debug\net472\MSBuildBinLogSummary.exe --log-file C:\temp\Vatsan\vatsan.binlog- takes 4 secondsMSBuildBinLogSummary\bin\Debug\netcoreapp3.1\MSBuildBinLogSummary.exe --log-file C:\temp\Vatsan\vatsan.binlog- takes 40 secondsThe stack that I saw was taking all the time is ReadByte from a GzipStream, it's called millions of times (to read the binlog):
Is this something known? On Desktop Framework I see a similar native inflate stack, but it doesn't cost nearly as much. Would someone be able to take a look? Thanks!
danmoseley commentedon Jul 13, 2020
Not something I know of. cc @carlossanlop who own this area. Could you paste this repro into a new issue in dotnet/runtime for us?
KirillOsenkov commentedon Jul 13, 2020
Reported here, thanks!
dotnet/runtime#39233
Wrap the GZipStream in a BufferedStream.
KirillOsenkov commentedon Dec 15, 2020
Fixed the perf issue with this commit: dba8091