Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 18 of 18

Thread: Profiling using gprof on Teensy 4

Threaded View

  1. #1
    Senior Member
    Join Date
    Sep 2013
    Boston, MA

    Profiling using gprof on Teensy 4

    I created a project to partially support gprof-style profiling of applications on Teensy 4. This shows how much time is spent in each function. In theory, this could also work on Teensy 3, but it doesn't have enough memory to do it well so I didn't implement that yet. This is the repository:

    It will only support the histogram feature of gprof. The Teensyduino arm cross-compiler does not support more advanced features (but it could! ...if Paul includes gprof executable and libc_p.a). You will need to make a few changes to the Arduino setup described in the file.


    The profiler samples the current instruction every 1 millisecond. That is at each millisecond it looks to see what function is currently running and keeps a counter of how many times this happens. Over time, this gives an approximate value of how much time each function consumes.

    On desktops, gprof will also keep track of which function calls which, but that is not supported on Teensy 4.

    After a while, a file with the function counters is sent out to the serial port. A python program is listening on the serial port for this and writes out "gmon.out". This file is then cross-referenced by gprof with the original executable to generate a table of execution times.

    For an interesting overview of gprof:

    Output of Tests Example

    Flat profile:
    Each sample counts as 0.001 seconds.
      %   cumulative   self              self     total           
     time   seconds   seconds    calls  Ts/call  Ts/call  name    
     50.00      5.08     5.08                             stall_3()
     33.33      8.46     3.38                             stall_2()
     16.66     10.15     1.69                             stall_1()
      0.01     10.15     0.00                             endpoint0_receive
    Edit: Explained serial port.
    Last edited by ftrias; 08-23-2019 at 03:02 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts