msbuild-flame-graph
msbuild-flame-graph copied to clipboard
Turns MSBuild executions into flame graphs
MSBuild Flame Graph
Explore MSBuild executions to find why your C++ builds are slow.
This is the flame graph for a default Visual Studio 2015 C++ project:

This graph represents a build from this repository.

I wrote about the steps I took to build the initial version of the tool in this post series.

Features
- Uses MSBuild 15: builds VS2015 and VS2017 C++ projects.
- Processes
/Bt+and/time+MSVC flags:
- Processes
/d1reportTimeMSVC flag (exclusive to VS2017 projects):
- Builds projects into an
Events.jsonfile, converts it intoTrace.jsonin a separate step. - Can theoretically build other MSBuild-based projects, but is only tested on C++ ones.
Getting started
- Install Visual Studio 2017+ Community Edition.
- Install .NET Framework v4.6.2 SDK.
- Clone repository.
- Open solution, build and run.
Codebase overview
Should you want to explore what's in the repository, these are the main parts:
Projects
Builder: contains the UI (built in WPF) to interact with the tool.MSBuildWrapper: defines MSBuild loggers, interacts with MSBuild API and converts MSBuild events to custom abstractions.BuildTimeline: represents timelines and everything it needs, from events to entries.TimelineSerializer: includes a way to convert aTimelineto a Google Chrome's trace. New trace formats can be added.Model: represents data to be used by other projects.
Main flow
- As part of
MSBuildWrapper/Compilation/Compilation.cs, when a build starts every MSBuild event is displayed in the UI and gets stored in memory. - When the build finishes, most events get converted into a custom format (some events and properties are discarded).
- When the build is finished,
Builder/ViewModel/Commands.csstores every custom event in anEvents.jsonfile. - A
Trace.jsonfile can be exported from anEvents.jsonfile viaBuilder/ViewModel/Commands.cs. This is useful to build different timelines (even to different formats) without having to repeat the build.
License
This project is released under GNU GPLv3 license.
I started this project thanks to the information I gathered from the community, so I wanted to give something back. You are encouraged to alter it in any way you want, but please continue making it public so the community can benefit from it.
Acknowledgements
- Thanks to @aras_p for his blog posts investigating build times, this one was the main inspiration for this tool.
- Thanks to Microsoft's dev team for building these API and new tools like vcperf or MSBuild Structured Log Viewer.