Sampling Performance in C++

What is the preferred way to take performance samples (FPS, stat GPU / CPU, etc.) via C++ code?

I could count frames and compute the average frame time to determine FPS, but I’d like to approach this in a very lightweight, granular way. And it seems like there are lots of built-in classes/tools for performance profiling already, if I can just figure out how to tap into their data via C++.