Gary-Hobson commented on issue #16740:
URL: https://github.com/apache/nuttx/issues/16740#issuecomment-3095870990

   There is no data in the result, which may be because the function was not 
executed or the execution time was too short, resulting in the timer not 
sampling any valid data (or the timer was not triggered at all, which is almost 
impossible)
   
   Two memory blocks are required in gprof, one for recording the timer 
sampling data and the other for the function call relationship data. Their 
resolutions are modified by HISTFRACTION and HASHFRACTION respectively 
(although it is possible, it is not recommended and may lead to incorrect 
results)
   
   It is recommended to test in QEMU first to check if the operation steps are 
correct (or execute the provided demo in RP2040 to see if the output results 
are correct)
   
   Below are the steps and results of changing HISTFRACTION to 16 in the qemu 
environment. 
   
   ```
   ./tools/configure.sh nuttx/boards/arm/qemu/qemu-armv7a/configs/nsh 
   make -j32
   ```
   
   Configuration changes:
   ```
   +CONFIG_FS_TMPFS=y
   +CONFIG_PROFILE_MINI=y
   +CONFIG_SYSTEM_GPROF=y
   ```
   
   nsh command:
   ```
   cd /tmp
   gprof start
   hello
   gprof stop
   gprof dump /tmp/gprof.out
   hexdump /tmp/gprof.out
   ```
   
   demo:
   ```c
   
   void my_delay(int s)
   {
     struct timespec delay = {
       .tv_sec = s,
     };
     struct timespec now, except;
     clock_systime_timespec(&now);
     clock_timespec_add(&now, &delay, &except);
     while (clock_timespec_compare(&now, &except) < 0)
       {
         clock_systime_timespec(&now);
       }
   }
   
   void foo(void)
   {
     syslog(0, "foo() called\n");
     my_delay(1);
   }
   
   int main(int argc, FAR char *argv[])
   {
     foo();
     printf("Hello, World!!\n");
     return 0;
   }
   
   ```
   
   file diff:
   ```
   diff --git a/libs/libbuiltin/libgcc/profile.c 
b/libs/libbuiltin/libgcc/profile.c
   index ad8b37a2bb6..2277860aa6d 100644
   --- a/libs/libbuiltin/libgcc/profile.c
   +++ b/libs/libbuiltin/libgcc/profile.c
   @@ -50,7 +50,7 @@
    
    /* Fraction of text space to allocate for histogram counters here, 1/2 */
    
   -#define HISTFRACTION    2
   +#define HISTFRACTION    16
    
   ```
   
   Output:
   ```shell
   # HISTFRACTION = 16
   arm-none-eabi-gprof nuttx/nuttx gmon.out -b
   Flat profile:
   
   Each sample counts as 0.001 seconds.
     %   cumulative   self              self     total           
    time   seconds   seconds    calls  Ts/call  Ts/call  name    
    **37.04      0.75     0.75                             arm_timer_interrupt
    30.93      1.38     0.63                             up_timer_initialize
    12.37      1.63     0.25                             up_idle
    12.35      1.88     0.25                             arm_timer_get_freq**
     6.19      2.00     0.13                             up_allocate_heap
     1.09      2.02     0.02                             up_ndelay
     0.05      2.02     0.00                             lib_rdflush_unlocked
   
   granularity: each sample hit covers 32 byte(s) for 0.05% of 2.02 seconds
   
   ====================================
   # HISTFRACTION = 2
   arm-none-eabi-gprof nuttx/nuttx gmon.out -b
   Flat profile:
   
   Each sample counts as 0.001 seconds.
     %   cumulative   self              self     total           
    time   seconds   seconds    calls  Ts/call  Ts/call  name    
    49.48      1.00     1.00                             up_idle
    49.38      2.00     1.00                             arm_timer_get_freq
     1.09      2.02     0.02                             up_ndelay
     0.05      2.02     0.00                             nxsched_waitpid
   
   granularity: each sample hit covers 4 byte(s) for 0.05% of 2.02 seconds
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to