Introducing vcperf /timetrace for C++ build time analysis - C++ Team Blog (original) (raw)

The following blog post was written by guest author Carlos Fraguas from Mercury Steam Entertainment. He describes how he used the C++ Build Insights SDK to add the new /timetrace option in vcperf, and how he also used it to build custom tools tailored to his team’s needs. You can follow Carlos on Twitter using handle @MetanoKid.


Hello! I’m Carlos Fraguas and I work as a Gameplay Programmer at Mercury Steam Entertainment. Let’s look at how the C++ Build Insights SDK helped me create tools to decrease build times and how I ended up adding a new visualization option into vcperf.

Background

There’s one thing programmers dislike the most: waiting for the project to compile. Well, yes, we’ve all laughed with this XKCD comic:

A webcomic showing two people sword-fighting on office chairs. Somebody from the office says: "Hey! Get back to work!" and they reply "Compiling!"

Source: XKCD.com (https://xkcd.com/303/) License: https://xkcd.com/license.html

But it’s really frustrating just watching a progress bar moving up! Long build times discourage iterations in both your project’s features and architecture (i.e. refactoring is costly), so we could argue that keeping your iteration cycle short is key for your team.

Some time ago I started worrying about slow build times and tried to find some tools that could help me find bottlenecks in our build process. It wasn’t until the C++ Build Insights SDK and vcperf were released that I could start making real and informed progress towards speeding them up!

There was an issue, though: by the time I started investigating, I wasn’t as familiar with MSVC as my Engine Programmer teammates. And that’s where vcperf truly shined: by giving me a visual representation of the build! I could then understand the amount of work that the compiler and linker are doing, and how it’s structured.

However, now that the SDK was available, I wanted to give it a try myself and create some custom reports, tailored for our team and projects. It felt astonishingly easy to set up and get useful info. And yes, it’s as straightforward as Kevin explains in his posts about finding build bottlenecks or profiling metaprograms!

Among those reports, and inspired by Aras Pranckevičius, I set myself to add an alternative visualization output for vcperf.

/timetrace

The new /timetrace option lets you build a flame graph viewable in any Chromium-based browser, like the new Microsoft Edge. These are some of its key features:

A flame graph showing _vcperf_’s build:

A screen capture showing the use of Microsoft Edge to view a JSON trace obtained by using the /timetrace switch with vcperf. The trace describes a build of vcperf itself.

A zoom into one of the files in _vcperf_’s build:

A screen capture showing the use of Microsoft Edge to view a JSON trace obtained by using the /timetrace switch with vcperf. The trace describes a build of vcperf itself, zoomed into the area that shows the time spent compiling the TimeTraceGenerator.cpp file.

A zoom into _vcperf_’s build showing template instantiations:

A screen capture showing the use of Microsoft Edge to view a JSON trace obtained by using the /timetrace switch with vcperf. The trace describes a build of vcperf itself, zoomed into an area that shows time spent doing template instantiations.

To generate these graphs yourself, follow these steps:

This is what /timetrace does under the hood:

How the SDK helped us

Using the C++ Build Insights SDK wasn’t useful just for visualizing our build process. We’ve managed to create a number of small tools to keep analyzing future builds. These were some specific cases where the SDK helped us:

As you can see, the information provided by the SDK helped us in several areas!

Final words

Before we finish, I wanted to thank the team behind the C++ Build Insights SDK and vcperf for these tools, and Kevin Cadieux in particular for all the time and effort put into reviewing /timetrace.

I hope this new feature helps you make more informed decisions when investigating your build times and empowers you to create your own tools. Feel free to clone the vcperf repo, explore /timetrace and tweak it to your needs!

Thanks for reading!

Carlos.

Author

Kevin Cadieux

Engineer working on MSVC.