How to automate Profile-Guided Optimization as part of build in Visual C++?

55 Views Asked by At

I want to incorporate PGO into the Visual C++ build steps in an automated fashion.

Specifically, I wish to be able to:

  1. Select a build configuration (let's call it Release (PGO))

  2. Click Build Solution (or Build Project)

  3. Simply wait for Visual Studio to:

    a. Build an instrumented version of my project

    b. Automatically invoke the executable with some command line (e.g. --benchmark) and wait for it to exit

    c. Collected the instrumentation data from that execution

    d. Build a profile-guided-optimized version of my project

  4. Discover the PGO-optimized binary lying in my output directory

Is such a thing possible, and if so, how do I achieve it?

1

There are 1 best solutions below

2
Bowman Zhu-MSFT On BEST ANSWER

For your requirement, please check whether the target section is what you want:

MSBuild targets

And the time of the targets' trigger:

Target build order

You can put the automatic steps in a script, and use exec to run it:

Exec task

Such as:

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="xxx" />
  </Target>