Skip to content

Conversation

@earlephilhower
Copy link
Owner

Apps can now use gprof to analyze performance and runtimes. This requires significant RAM and really only makes sense on devices with PSRAM to store the state.

When the menu item is selected, allocates RAM and tracks function calls and periodically samples the PC to generate a histogram of application usage. Data written out to a gmon.out file, which can then be transferred to a PC using gdb or a SD card.

Apps can now use gprof to analyze performance and runtimes.  This requires
significant RAM and really only makes sense on devices with PSRAM to store
the state.

When the menu item is selected, allocates RAM and tracks function calls and
periodically samples the PC to generate a histogram of application usage.
Data written out to a gmon.out file, which can then be transferred to
a PC using gdb or a SD card.
@earlephilhower
Copy link
Owner Author

Still working out how to make it available to the app and present to the PC, but it generates output like traditional gprof:

Flat profile:

Each sample counts as 0.0001 seconds.
 %   cumulative   self              self     total           
time   seconds   seconds    calls  ms/call  ms/call  name    
45.26      0.33     0.33                             rand
42.44      0.63     0.31  3500020     0.00     0.00  __wrap___getreent
 6.16      0.68     0.04                             srand
 1.26      0.69     0.01                             ____aeabi_fcmpun_veneer
 1.26      0.69     0.01                             ____gnu_mcount_nc_veneer
 0.98      0.70     0.01        2     3.54     3.54  fcn2(unsigned long)
 0.74      0.71     0.01     7195     0.00     0.00  timer_task(long, void*)
 0.61      0.71     0.00        5     0.88     0.88  fcn1(unsigned long)
 0.44      0.71     0.00                             ____aeabi_lmul_veneer
 0.44      0.72     0.00                             __dcd_event_handler_veneer
 0.25      0.72     0.00        1     1.77     1.77  _GLOBAL__sub_I__ZN10PIOProgramC2EPK11pio_program
 0.13      0.72     0.00        1     0.93    12.41  setup
 0.01      0.72     0.00        9     0.01     0.01  __wrap_malloc
 0.01      0.72     0.00                             __ssputs_r
 0.00      0.72     0.00                             strtof
 0.00      0.72     0.00       15     0.00     0.00  littlefs_impl::LittleFSImpl::lfs_flash_read(lfs_config const*, unsigned long, unsigned long, void*, unsigned long)
 0.00      0.72     0.00       10     0.00     0.00  __retarget_lock_acquire_recursive
 0.00      0.72     0.00       10     0.00     0.00  __retarget_lock_release_recursive
 0.00      0.72     0.00       10     0.00     0.00  interrupts
 0.00      0.72     0.00       10     0.00     0.00  noInterrupts
 0.00      0.72     0.00        5     0.00     0.00  CoreMutex::~CoreMutex()
 0.00      0.72     0.00        5     0.00     0.00  tud_descriptor_string_cb
 0.00      0.72     0.00        4     0.00     0.00  CoreMutex::CoreMutex(mutex*, unsigned char)
 0.00      0.72     0.00        3     0.00     0.00  CheckSerialReset()
 0.00      0.72     0.00        3     0.00     0.00  arduino::Print::printf(char const*, ...)
 0.00      0.72     0.00        3     0.00     0.00  SerialUSB::write(unsigned char const*, unsigned int)
 0.00      0.72     0.00        3     0.00     0.00  tud_descriptor_configuration_cb
 0.00      0.72     0.00        2     0.00     0.00  tud_cdc_line_coding_cb
 0.00      0.72     0.00        2     0.00     0.00  tud_descriptor_device_cb
 0.00      0.72     0.00        1     0.00     0.00  _GLOBAL__sub_I__Z18__USBInstallSerialv
 0.00      0.72     0.00        1     0.00     0.02  _GLOBAL__sub_I__ZN13littlefs_impl12LittleFSImpl4openEPKcN2fs8OpenModeENS3_10AccessModeE
 0.00      0.72     0.00        1     0.00     0.00  _GLOBAL__sub_I__ZN8VFSClassC2Ev
 0.00      0.72     0.00        1     0.00     0.00  _GLOBAL__sub_I_rp2040
 0.00      0.72     0.00        1     0.00     0.01  __USBStart()
 0.00      0.72     0.00        1     0.00     0.00  __SetupDescHIDReport()
 0.00      0.72     0.00        1     0.00     0.01  __SetupUSBDescriptor()
 0.00      0.72     0.00        1     0.00     0.00  PIOProgram::prepare(pio_hw_t**, int*, int*, int, int)
 0.00      0.72     0.00        1     0.00     0.00  PIOProgram::PIOProgram(pio_program const*)
 0.00      0.72     0.00        1     0.00     0.00  littlefs_impl::LittleFSImpl::begin()
 0.00      0.72     0.00        1     0.00     0.00  littlefs_impl::LittleFSImpl::_tryMount()
 0.00      0.72     0.00        1     0.00     0.00  fs::FS::begin()
 0.00      0.72     0.00        1     0.00     0.00  fs::FSImpl::setTimeCallback(long long (*)())
 0.00      0.72     0.00        1     0.00     0.02  RP2040::begin()
 0.00      0.72     0.00        1     0.00     0.00  arduino::String::changeBuffer(unsigned int)
 0.00      0.72     0.00        1     0.00     0.00  arduino::String::copy(char const*, unsigned int)
 0.00      0.72     0.00        1     0.00     0.00  arduino::String::reserve(unsigned int)
 0.00      0.72     0.00        1     0.00     0.00  arduino::String::String(char const*)
 0.00      0.72     0.00        1     0.00     0.00  VFSClass::root(fs::FS&)
 0.00      0.72     0.00        1     0.00     0.00  SerialUSB::begin(unsigned long)
 0.00      0.72     0.00        1     0.00     0.00  std::__shared_count<(__gnu_cxx::_Lock_policy)0>::__shared_count(std::__shared_count<(__gnu_cxx::_Lock_policy)0> const&)
 0.00      0.72     0.00        1     0.00     0.00  std::__shared_count<(__gnu_cxx::_Lock_policy)0>::~__shared_count()
 0.00      0.72     0.00        1     0.00     0.00  __wrap_realloc
 0.00      0.72     0.00        1     0.00     0.00  delay
 0.00      0.72     0.00        1     0.00     0.00  initVariant
 0.00      0.72     0.00        1     0.00    12.43  main
 0.00      0.72     0.00        1     0.00     0.00  millis
 0.00      0.72     0.00        1     0.00     0.00  pinMode
 0.00      0.72     0.00        1     0.00     0.00  tud_cdc_line_state_cb

and

granularity: each sample hit covers 16 byte(s) for 0.01% of 0.72 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]     87.7    0.33    0.31                 rand [1]
                0.31    0.00 3500000/3500020     __wrap___getreent [2]
-----------------------------------------------
                0.00    0.00       1/3500020     realloc [31]
                0.00    0.00       3/3500020     vsnprintf [30]
                0.00    0.00       7/3500020     srand [3]
                0.00    0.00       9/3500020     malloc [29]
                0.31    0.00 3500000/3500020     rand [1]
[2]     42.4    0.31    0.00 3500020         __wrap___getreent [2]
-----------------------------------------------
                                                 <spontaneous>
[3]      6.2    0.04    0.00                 srand [3]
                0.00    0.00       1/9           __wrap_malloc [17]
                0.00    0.00       7/3500020     __wrap___getreent [2]
-----------------------------------------------
                0.00    0.01       1/1           platform_entry [5]
[4]      1.7    0.00    0.01       1         main [4]
                0.00    0.01       1/1           setup [6]
                0.00    0.00       1/1           RP2040::begin() [22]
                0.00    0.00       1/1           __USBStart() [24]
                0.00    0.00       1/1           initVariant [39]
                0.00    0.00       1/1           SerialUSB::begin(unsigned long) [488]
                0.00    0.00       1/1           millis [40]
-----------------------------------------------
                                                 <spontaneous>
[5]      1.7    0.00    0.01                 platform_entry [5]
                0.00    0.01       1/1           main [4]

@earlephilhower earlephilhower marked this pull request as ready for review December 5, 2024 04:57
@earlephilhower earlephilhower merged commit 0061d3f into master Dec 6, 2024
25 of 26 checks passed
@earlephilhower earlephilhower deleted the profile branch December 6, 2024 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants