Can gprof be used somehow with a ARM Cortex-M devices?

Asked by Ilya Dmitrichenko

I can see that this toolchain ships a `arm-none-eabi-gprof` binary. I understand that I'll need to pass `-pg` flag to GCC, but one would usually use a `gmon.out` file as input to gprof... How would it work on a bare-metal target?

Question information

English Edit question
GNU Arm Embedded Toolchain Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Ilya Dmitrichenko (errordeveloper) said :

Ok, I can see that `__gnu_mcount_nc` would have to be defined... Has anyone done this for a microcontroller? But the main question still is what to do with gmon.out?

I found this in CS manual [1]:
 "Arrange for the data to be saved to a file named gmon.out when the program exits (via atexit). Refer to the gprof profiler manual for more information."


So looking at the `gprof.pdf` provided with latest version of this toolchain, I see the following:

"The profiling library also includes a function (mcleanup) which is typ- ically registered using atexit() to be called as the program exits, and is responsible for writing the file ‘gmon.out’. Profiling is turned off, various headers are output, and the histogram is written, followed by the call-graph arcs and the basic-block counts."

But it still doesn't quite explain to me how would I handle it on a bare-metal sort of platform...

Revision history for this message
Joey Ye (jinyun-ye) said :

We never tried gprof on bare-metal. You probably need to implement your IO function like _write/_read to facilitate the output.

Revision history for this message
Tamas Kleiber (kleiber-tamas) said :

With a semihosting enabled GDB server, like Segger's J-Link GDB Server gmon.out can be redirected to the PC's file system. Afterwards you can analyze the results using gprof or a visualization tool. This way you do not have to implement anything fancy. There is a semihosting specific minimal example distributed together with the compiler.

Revision history for this message
Erich Styger (erich-styger) said :

I can confirm that I have gprof working now with the GNU ARM Embedded (launchpad) tools on a Freescale Kinetis (Cortex-M4F) board. I'm using Eclipse wiwith a bare-metal application. I'm using a similar approach like with gcove (see, but for gprof I had to implement my own glue code.
I hope I can write up an article and have the sources published shortly.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :

Hi Erich,

Thanks for the feedback. When the article will be written feel free to share the link here, others might be interested.

Best regards.

Revision history for this message
Erich Styger (erich-styger) said :

Hi Thomas,
yes, I will post a link as a comment here. This is how it looks:
But of course you can use the non-Eclipse gprof tool too. I'm using a Segger J-Link interface with Semihosting to get the file written to the host PC, then I can use it with GNU gprof.

Best regards,

Revision history for this message
Erich Styger (erich-styger) said :

I have posted an article here:
It explains the necessary files, settings and data structure to perform gprof profiling with the gcc ARM Embedded toolchain. I'm sucessfully using that approach with the 4.8-2014-q3 and 4.9-2015-q2 toolchain and libraries.
It works for both Eclipse and command line mode.

The article points as well to the sources, available on GitHub:

I hope this is useful for everyone who wants to use gprof for an embedded ARM target.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :

Hi Erich,

Thank you very much.

Best regards.

Revision history for this message
Jean Carlos (negrotico19) said :

Hello Erich,

Your article really help me a lot.
It is really worthy


Can you help with this problem?

Provide an answer of your own, or ask Ilya Dmitrichenko for more information if necessary.

To post a message you must log in.