C++ builds should always be faster. In Visual Studio 2019 16.2, we’ve shown our commitment to this ideal by speeding up the linker significantly. Today, we are thrilled to announce a new collection of tools that will give you the power to make improvements of your own. If you’ve ever had time for breakfast while building C++, then you may have asked yourself: what is the compiler doing? C++ Build Insights is our latest take at answering this daunting question and many others. By combining new tools with tried-and-tested Event Tracing for Windows (ETW), we’re making timing information for our C++ toolchain more accessible than ever before. Use it to make decisions tailored to your build scenarios and improve your build times.
Getting started
C++ Build Insights makes use of vcperf, a tool that allows you to capture a trace of your build and to view it in the Windows Performance Analyzer (WPA). The latest version of vcperf is available in Visual Studio 2019, but WPA must be obtained separately.
1. Follow these steps to obtain and configure vcperf and WPA:
- Download and install the latest Visual Studio 2019.
- Obtain WPA by downloading and installing the latest Windows ADK.
- Copy the perf_msvcbuildinsights.dll file from your Visual Studio 2019’s MSVC installation directory to your newly installed WPA directory. This file is the C++ Build Insights WPA add-in, which must be available to WPA for correctly displaying the C++ Build Insights events.
- MSVC’s installation directory is typically:
C:\Program Files (x86)\Microsoft Visual Studio\2019\{Edition}\VC\Tools\MSVC\{Version}\bin\Hostx64\x64
. - WPA’s installation directory is typically:
C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit
.
- MSVC’s installation directory is typically:
- Open the perfcore.ini file in your WPA installation directory and add an entry for the perf_msvcbuildinsights.dll file. This tells WPA to load the C++ Build Insights add-in on startup.
You can also obtain the latest vcperf and WPA add-in by cloning and building the vcperf GitHub repository. Feel free to use your built copy in conjunction with Visual Studio 2019!
2. Follow these steps to collect a trace of your build:
- Open an elevated x64 Native Tools Command Prompt for VS 2019.
- Obtain a trace of your build:
- Run the following command:
vcperf /start MySessionName
. - Build your C++ project from anywhere, even from within Visual Studio (vcperf collects events system-wide).
- Run the following command:
vcperf /stop MySessionName outputFile.etl
. This command will stop the trace, analyze all events, and save everything in the outputFile.etl trace file.
- Run the following command:
- Open the trace you just collected in WPA.
At the crux of the matter with the Build Explorer
Central to understanding a build is having an overview of what happened through time. The Build Explorer is a core element of C++ Build Insights that we designed for this purpose. Drag it from the Graph Explorer panel on the left onto the main analysis window in WPA. Use it to diagnose parallelism issues, detect bottlenecks, and determine if your build is dominated by parsing, code generation, or linking.
A thousand scoffs for the thousand cuts: aggregated statistics
The most insidious of build time problems are the ones that strike you little by little until the damage is so large that you wonder what hit you. A common example is the repetitive parsing of the same header file due to its inclusion in many translation units. Each inclusion may not have a large impact by itself but may have devastating effects on build times when combined with others. C++ Build Insights provides aggregated statistics to assist you in warding off such threats. An example of this capability is illustrated below, where file parsing statistics are aggregated over an entire build to determine the most time-consuming headers. To view this information for your build, choose the Files view from the Graph Explorer panel on the left in WPA. Drag it to the analysis window.
What information can you get?
With C++ Build Insights, expect to be able to obtain the following information for all your compiler and linker invocations.
Tell us what you think!
Download your copy of the latest Visual Studio 2019, and get started with C++ Build Insights today! For a complete set of documentation, see the Get started with C++ Build Insights page.
In this article, we shared two features with you, but there is much more to come! Stay tuned for more blog posts detailing specific ways in which you can use C++ Build Insights to improve your builds.
We look forward to hearing from you on how you used vcperf and WPA to understand and optimize your builds. Are there any other pieces of information you would like to be able to get from C++ Build Insights? Tell us what you think in the comments below. You can also get in touch with us at visualcpp@microsoft.com, or on Twitter @VisualC.
Hello, World.
I don't see Build Explorer. Under Graph Explorer, I see System Activity/Images, Generic Events, Regions, Threads, and Computation/CPU/DPC/Flame/etc..
I am not using "Preview", I am using Professional, so I had to splice together various blog posts.
I have this file C:\Users\..me..\Documents\Visual Studio 2019\..my proj..\Projects\packages\Microsoft.Cpp.BuildInsights.1.0.0\wpa\x64\perf_msvcbuildinsights.dll
I added perf_msvcbuildinsights.dll to C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\perfcore.ini
I vcperf /start MySessionName
Then rebuilt my proj...
Then I vcperf /stopnoanalyze MySessionName outputTraceFile.etl (because https://docs.microsoft.com/en-us/cpp/build-insights/reference/sdk/overview?view=vs-2019: "Important...
Hello ITISAGLN,
Sorry for the confusion about the /stopnoanalyze command. This command is only used to analyze traces programmatically via the SDK. You should use the regular /stop command if you are going to view a trace in WPA, even if the perf_msvcbuildinsights.dll file comes from the NuGet package.
I hope this helps! Please let me know if you are still having problems.
Thanks, Kevin. I was originally using /stop. Build Explorer didn’t show so I went looking for answers and apparently landed on wrong one (/stopnoanalyze command). I just repeated your steps 1-3 and there is no Build Explorer; Only Graph Explorer (subcategories are System Activity and Configuration). Any idea on what I should try next to see Build Explorer?
This could be caused by the following:
1. Using an unsupported toolset. Events are only present in Visual Studio 2017 version 15.7 and above. The build that you are tracing must be using at least this toolset.
2. The WPA add-in was not installed correctly. Try opening WPA and click on Window -> Select Tables. Search for the Diagnostics category and you should see 4 C++ Build Insights views listed there. Do you see that? If...
This tool looks like exactly what C++-ers need. Nice job. My first discovery for my project is a sad one and reveal architectural issues. The number one included file is a god-class. I knew it did too much but did not know it’d be #1 by as much as it is…I’m going to break it down. Thanks for this tool and I’ll keep using it!
You’re welcome! Please let us know if you have any feedback or feature suggestions.
It’s now working. I had perf_msvcbuildinsights.dll in wrong location (some where under C:\ProgramData\…)
Thank you.
Great! Thanks for letting us know! Please feel free to share any other feedback about the tool.
I am on Version 16.5.5.
My WPA does not have Window/Tables; only New Analysis View, New Comp. Analysis View, Duplicate View, Rename View, Close View, Close All Views, Diagnostic Console, Details, Analysis Assistant, My Presets, Go Back to Analysis.
I see and clicked "Diagnostic Console":
Error: Could not load add-in: perf_msvcbuildinsights.dll. Exception: ..
WUT?
It's here: I copied C:\Users\..me..\Documents\Visual Studio 2019\..my proj..\Projects\packages\Microsoft.Cpp.BuildInsights.1.0.0\wpa\x64\perf_msvcbuildinsights.dll -> C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit
I'll try reinstalling WPA...
Thanks!
Looks very useful and would like to try it. unfortunately, I can't start the tracing.
Microsoft (R) Visual C++ (R) Performance Analyzer 1.2.19101801
Starting tracing session MySession...
Failed to start trace.
A trace that is currently being collected on your system is preventing vcperf from starting a new one. This can occur if you forgot to stop a vcperf trace prior to running the start command, or if processes other than vcperf have started...
Hi Tim,
Collection can also be prevented if something on your system is currently collecting a kernel trace. A kernel trace would show up in your ‘tracelog -l’ as NT Kernel Logger. You can stop this one by running the ‘xperf -stop’ command, though I would first try to understand why a kernel trace is being collected to begin with.
Please let me know if you need more help with this.
Thanks,
Kevin
When the WPA with this feature will get out of testing? I don’t want to become an insider to use it…
Hi Nikolay,
The vcperf GitHub repository has instructions on how to obtain the C++ Build Insights WPA add-in without enrolling in the Windows Insider program.
I followed the instructions and mytrace.etl does not contain any information about the build.
Hi Vaclav,
When this happens it's typically due to one of the following reasons:
1. The wrong version of WPA is used. Make sure you download the one from the ADK preview which contains the C++ Build Insights plugin. You can download it here: https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewADK
2. The C++ Build Insights views are disabled in WPA. To enable them, select Windows --> Select Tables, and check all C++ Build Insights views under the Diagnostics category. Restart WPA.
3....
“…will work with any build system…”: I was going to ask whether this means it will work with older versions of Visual Studio. We are using VS2017 and aren’t likely to upgrade soon.
So I tried it and it does work 🙂 Great!
How can it work if the cl ETW event emitters aren’t there? Or have they existed all along? Do you get a reduced trace only showing the process invocations?
Hi Toni,
Rob has discovered something that is not yet announced: vcperf is backward compatible down to VS 2017. The reason is that VS 2017 contains most of the ETW events required to get a reasonable trace. I will touch more on that in a later blog post, as well as make several other announcements.
Very useful; we’ve already achieved a 10% improvement in compilation time for one of our largest C++ projects.
What was the cause?
It was header parsing. We missed a number of opportunities for forward declare classes.
That’s great news! Thanks for your comment, and please let us know if you have any other feedback now or in the future.
Hi. This looks interesting. However I have problems capturing information for my project.
When I stop my tracing session I get the following error:
“Failed to stop trace. Events were dropped during the trace. Please try recollecting the trace.”
I believe this happens when one project that has custom build steps to download and build boost is being built.
Is there some public issue tracker where I can report this?
Hi Peter,
You can report issues on Developer Community. If you do end up opening an issue, submitting a raw trace would help us with the diagnosis. A raw trace can be captured by using /stopnoanalyze instead of /stop when stopping the trace.
Is there an easy way you can disable the custom step that builds Boost to see if anything changes? If not, you could try the following:
1. Add the /nocpusampling switch to your vcperf start...
Hi,
The link to the ADK install (https://www.microsoft.com/software-download/windowsinsiderpreviewADK) seems to direct to a page that doesn’t exist for me. https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewADK does work.
Hi David,
The https://www.microsoft.com/software-download/windowsinsiderpreviewADK link should automatically redirect to the appropriate URL based on your locale/language, i.e. in this case https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewADK. Is this redirect not happening for you, or are you getting an error page?
Hi Eli,
I’m having the same issue as Peter. It redirects to https://www.microsoft.com/nl-nl/software-download/windowsinsiderpreviewADK which does not exist
For me it redirects to https://www.microsoft.com/sv-se/software-download/windowsinsiderpreviewADK which does not exist.
I just get the generic “We are sorry, the page you requested cannot be found.
The URL may be misspelled or the page you’re looking for is no longer available.”
What's needed for faster builds is a way to compile any number of translation units with the *assumption* of a fixed set of preprocessor definitions, because
then a header (with the exception of designated ones such as ) needs only be compiled in the first translation unit it's encountered.
There is already machinery for this in Visual C++'s support for a single precompiled header.
When I've mentioned this before the answer's always been, let's wait for modules.
That's not...
This should be possible with C++20 Modules where you can transform a #include directive into a import directive. By doing this, the header will be compiled once (per module?) instead of being copy/paste into the source TU.
Hi. Is there a plan to have a full integration of the analyzer within Visual Studio?
Hi Tony,
It’s been talked about but this is not something being worked on at the moment. If you are interested in seeing this integrated into VS, I would recommend you use the suggestion feature on Developer Community, as described here:
https://docs.microsoft.com/en-us/visualstudio/ide/suggest-a-feature?view=vs-2019
Hi, thanks for the reply. I guess it has be done this way in order to ship more this feature quicker (which is fine).
Here is my suggestion: https://developercommunity.visualstudio.com/idea/810960/have-full-integration-of-build-insights-within-vis.html