KirillOsenkov / MSBuildStructuredLog

A logger for MSBuild that records a structured representation of executed targets, tasks, property and item values.
MIT License
1.44k stars 190 forks source link

How does one correlate the Detailed Build Summary with the nodes reported by the BinaryLog.ReadBuild API? #542

Closed MarkKharitonov closed 2 years ago

MarkKharitonov commented 2 years ago

The Detailed Build Summary mentions request Ids, but where are they in the nodes returned by BinaryLog.ReadBuild ?

KirillOsenkov commented 2 years ago

Here's the source for the logic that prints the detailed build summary: https://source.dot.net/#Microsoft.Build/BackEnd/Components/Scheduler/Scheduler.cs,061984faccbfdfc1

Here's the place that prints the build request configuration id: https://github.com/dotnet/msbuild/blob/513f59ce49ffd8adc333dabf70501ad68630348d/src/Build/BackEnd/Components/Scheduler/Scheduler.cs#L2483

The binlog contains serialized BuildEventArgs objects that have a BuildEventContext on them. Here's where the BuildEventContext is read, and some information is assigned to the tree node objects: https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/ddea3ae1d287ad199cc08b2d7465ba12af57ebfd/src/StructuredLogger/Construction/Construction.cs#L219

A BuildEventContext is this: https://source.dot.net/#Microsoft.Build.Framework/BuildEventContext.cs,01f25628a97774d4

I don't know if there's any correlation between BuildRequest.ConfigurationId and args.BuildEventContext, if there is one at all.

MarkKharitonov commented 2 years ago

Hi, Kirill. My question is not about the low level build events, but about the high level nodes returned by the BinaryLog.ReadBuild API - the Project and Target and Task objects.

Is there any correlation between them and the request Id? I am trying to figure out if I can use them to analyze the detailed build summary.

KirillOsenkov commented 2 years ago

That's how I understood your original question. When I say "tree node objects" I meant Project, Target and Task.

The short answer is it's either hard or impossible to find a correlation that you're looking for, or I don't know how to do it.

However my advice is throw away the detailed build summary and write your own logic from scratch - you'll be better off and have more flexibility. The Project, Target and Task objects inherit from TimedNode, which has the start and end times (and the duration of course). You can use the topology of the tree together with the timing info to reconstruct whatever graph you want. You can also use the NodeId property to split the graph by build process nodes (MSBuild.exe processes in a multi-process build).

KirillOsenkov commented 2 years ago

Start simple - look at how searching for $task $time returns you a flat list of tasks sorted by duration descending. Or look at how the Timeline view assigns projects, targets and tasks to nodes (each node is a vertical column, so a single process build would be just one column, vs. 8-core build would be 8 columns).

MarkKharitonov commented 2 years ago

I see. It just seems wasteful to ignore the detailed build summary having read why they added it. Thanks for the input.