View Profiling Data within Code

A look at an exciting new feature in Polar Signals Cloud: Source View.

View Profiling Data within Code
August 31, 2023

Today, we're pleased to introduce a new exciting feature in Polar Signals Cloud: Source View.

Using it, you can view your source code with profiling data inlined. We have always talked about "down to the line number", and starting today we can finally truly fulfill that promise! We have already been using the feature for a few weeks and have implemented countless optimizations thanks to it. As far as we are aware, Polar Signals Cloud is the only continuous profiling product on the market offering this.

How it works

Profiling data in Polar Signals Cloud has always contained function names, filenames, and line numbers, so generating statistics containing which line was observed and how often was always possible. Still, the missing piece has been: "How can we show source code and guarantee it's the correct version?"

The function name, filename, and line number metadata are read from what's referred to as debuginfo. Debuginfo are sections in ELF binaries, that in short, map address ranges to metadata. And filenames specified in debuginfo are simply the files that the compiler used to compile the binary. So all we need to do is, on the same machine right after compiling, just look at the debuginfo and produce a source archive that includes all the files referenced in the debuginfo.

We've put that logic into the parca-debuginfo tool, so all it takes is running this command:

$ parca-debuginfo source ./main

It produces an archive called `source.tar.zstd`, which we can then upload, while linking it with the Build ID (that's how Polar Signals Cloud will know which source archive to read). Conveniently, the parca-debuginfo CLI can also read the Build ID from the binary, so we can do everything with this one-liner:

$ parca-debuginfo upload --build-id="$(parca-debuginfo buildid ./main)" --type=sources source.tar.zstd --store-address=grpc.polarsignals.com:443 --bearer-token=token-goes-here

Now we can open the source view from flamegraphs/iciclegraphs in Polar Signals Cloud!

Example fibonacci program showing source code inlined with profiling data.
Example fibonacci program showing source code inlined with profiling data.

Simply hold shift while hovering over the flamegraph/iciclegraph and hit "open".

Try Today!

Polar Signals Cloud is still in preview, so request access today on our landing page.

Discuss:
Sign up for the latest Polar Signals news