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

Asked by Ilya Dmitrichenko on 2014-05-28

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

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
2014-05-28
Last reply:
2015-08-23

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."

[1]: http://doc.ironwoodlabs.com/arm-arm-none-eabi/html/getting-started/arm-mcount.html

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...

Joey Ye (jinyun-ye) said : #2

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

Tamas Kleiber (kleiber-tamas) said : #3

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.

Erich Styger (erich-styger) said : #4

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 http://mcuoneclipse.com/2015/05/31/code-coverage-with-gcov-launchpad-tools-and-eclipse-kinetis-design-studio-v3-0-0/), 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.

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.

Erich Styger (erich-styger) said : #6

Hi Thomas,
yes, I will post a link as a comment here. This is how it looks:
http://mcuoneclipse.com/2015/08/11/sneak-preview-profiling-bare-metal-microcontroller-applications-with-gnu-gprof/
:-)
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,
Erich

Erich Styger (erich-styger) said : #7

Greetings,
I have posted an article here:
http://mcuoneclipse.com/2015/08/23/tutorial-using-gnu-profiling-gprof-with-arm-cortex-m/
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:
https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/KDS/FRDM-K64F120M/FRDM-K64F_Profiling

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

Hi Erich,

Thank you very much.

Best regards.

Jean Carlos (negrotico19) said : #9

Hello Erich,

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

Thanks.

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.