Who is this for?

Developers looking to optimize C++ performance based on runtime behavior.

What will you learn?

Upon completion of this Learning Path, you will be able to:

  • Microbenchmark a function using Google Benchmark.
  • Apply profile-guided optimization to build performance-tuned binaries.

Prerequisites

Before starting, you will need the following:

  • Basic C++ understanding
  • Access to an Arm-based Linux machine, such as an AWS Graviton-based instance or an Arm AGI CPU platform

Summary

AI-assisted

This summary was drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.

Close
?
You’ll apply profile-guided optimization (PGO) to a C++ microbenchmark on an Arm-based Linux system with Google Benchmark. You’ll build an instrumented binary with -fprofile-generate, run it to create .gcda files, and recompile with -fprofile-use. You’ll compare benchmark timings before and after PGO, inspect the generated artifacts, and integrate PGO into either a Makefile or a continuous integration Github Actions workflow.

Frequently asked questions

AI-assisted

These FAQs were drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.

Close
?
Which compiler flags do I use to collect and then apply profile data?
Build the instrumented binary with -fprofile-generate, run it to collect runtime data, then rebuild with -fprofile-use. This two-step cycle enables the compiler to use the collected profile during optimization.
What files should appear after I run the instrumented binary?
The run generates profile data files with a .gcda extension in the same directory. Use these files as inputs for the subsequent -fprofile-use build.
How do I know Google Benchmark is working for the example?
Google Benchmark runs managed iterations and reports timing results for the benchmarked function. You should see timing output you can compare across the non-PGO and PGO builds.
What should I check if the optimized build doesn’t seem to use PGO?
Verify that you ran the instrumented binary and that .gcda files exist in the build directory. Then confirm that the recompile used -fprofile-use in the same location where the the run generated the profile files.
Where should I apply PGO when adding it to a Makefile or GitHub Actions workflow?
Use PGO for performance-critical code that runtime behavior strongly influences. Avoid applying it broadly to early-stage code or highly variable workloads because the extra build steps add time and may not yield stable benefits.
Next