Is there any C# framework or code to parse *blg Perfomance Counter log files?
Asked Answered
T

3

6

The task is not to gather Performance counters data in my .NET app, but open already prepared binary log files (*.blg)?

I know that MS SQL Profiler (.NET app) can parse binary logs.

Type answered 9/12, 2010 at 9:8 Comment(0)
S
8

From what I can find it seems that the .blg file format is proprietary and the spec is not openly published. That said I don't think you will be able to find a framework or library that does raw parsing of this format. Writing a library to parse this format without the spec is not without risk since assumptions will likely have to be made... even if you were to reverse engineer the binary format there is always the chance that you miss certain rules in your parser implementation causing potential problems down the road.

That said, I can think of 2 other options for parsing binary log files for use within a .NET application.

  1. PowerShell's Import-Counter cmdlet could be used to import counter data from a blg file resulting in objects for each counter sample in the source. The resulting output can be used in a number of ways. The simplest example I can think of would be to convert your source to CSV format for further processing:

    C:\PS> $data = import-counter .\exampledata.blg
    C:\PS> $data | export-counter -path .\output.csv -FileFormat csv

  2. relog is another option. This is a command line utility that ships with most major versions of the Windows OS. Again, the approach here would be to convert the blg file into CSV format for easy parsing. Example:

    relog -f csv inputfile.blg -o outputFile.csv

Given the options above you should be able to go from there. It would be quite easy run powershell or relog from a C# program using Process.Start()

Starling answered 9/12, 2010 at 11:33 Comment(0)
N
5

Tx (LINQ to Logs and Traces) is a C# library that can parse blg files.

And that is the usage:

var playback = new Playback();

playback.AddPerfCounterTraces(@"C:\bin\Release\Net40\BasicPerfCounters.blg");

playback
    .GetObservable<PerformanceSample>()
    .Dump();

playback.Run();

You can also find examples how to use it in Tx samples for LINQpad:

Tx's LINQpad samples

Nyberg answered 29/9, 2015 at 3:56 Comment(2)
Thank you for the tip, I will try it out.T(hn)x.Wexler
The Linqpad samples must be manually downloaded in LINQPad 5 clicking the button Download/import samples at the button of the Samples pane.Wexler
G
2

Microsoft has opened PowerShell source code, so now we can also find how to implement our own readers on top pdh.dll.

https://github.com/PowerShell/PowerShell/tree/master/src/Microsoft.PowerShell.Commands.Diagnostics

Guileful answered 20/2, 2020 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.