anchao opened a new pull request #5915:
URL: https://github.com/apache/incubator-nuttx/pull/5915


   ## Summary
   
   sched/note: add support of trace section mark
   
   The implementation of this feature is based on android systrace:
   
   https://source.android.com/devices/tech/debug/ftrace
   
   Application developers are more concerned about the performance of
   the specified application section,
   added two APIs to implement performance measurement:
   
   void sched_note_begin(FAR const char *str);
   void sched_note_end(FAR const char *str);
   or
   SCHED_NOTE_BEGIN();  /* defined to sched_note_begin(__FUNCTION__) */
   SCHED_NOTE_END();    /* defined to sched_note_end(__FUNCTION__) */
   
   Signed-off-by: chao.an <anc...@xiaomi.com>
   
   ## Impact
   
   N/A
   
   ## Testing
   
   https://source.android.com/devices/tech/debug/ftrace
   https://github.com/catapult-project/catapult/
   
   
   test code:
   
   ```
   void ccc(void)
   {
     SCHED_NOTE_BEGIN();
     usleep(10);
     SCHED_NOTE_END();
   }
   
   void bbb(void)
   {
     SCHED_NOTE_BEGIN();
     ccc();
     SCHED_NOTE_END();
   }
   
   void aaa(void)
   {
     SCHED_NOTE_BEGIN();
     bbb();
     SCHED_NOTE_END();
   }
   
   int main(int argc, FAR char *argv[])
   {
     while (1)
       {
         SCHED_NOTE_BEGIN();
         aaa();
         SCHED_NOTE_END();
       }
     return 0;
   }
   
   ```
   
   ![Screenshot from 2022-03-30 
22-34-16](https://user-images.githubusercontent.com/758493/160860334-a5006bbe-c506-4d59-b067-74651a863982.png)
   
   
   ## How To Use
   
   https://nuttx.apache.org/docs/latest/guides/tasktraceuser.html
   
   1. enable sched  instrumentation
   
   ```
   CONFIG_DRIVER_NOTERAM=y
   ...
   CONFIG_SCHED_INSTRUMENTATION=y
   CONFIG_SCHED_INSTRUMENTATION_SWITCH=y
   CONFIG_SCHED_INSTRUMENTATION_SYSCALL=y
   CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER=y
   CONFIG_SCHED_INSTRUMENTATION_DUMP=y
   ```
   2. Capture sched note info
   
   ```
   nsh> trace switch +
   nsh> trace syscall +
   nsh> trace start
   nsh> trace dump
   ```
   
   3. convert to systrace
   
   https://source.android.com/devices/tech/debug/ftrace
   
   If you captured your systrace with --no-compress, this is in the html file 
in the section beginning with BEGIN TRACE.
   If not, run html2trace from the [Catapult 
tree](https://github.com/catapult-project/catapult/tree/master/) 
(tracing/bin/html2trace) to uncompress the trace.
   
   ```
   $ git clone g...@github.com:catapult-project/catapult.git
   $ cd catapult/
   $ ./tracing/bin/trace2html trace.txt
   trace.html
   ```
   
[systrace.txt](https://github.com/apache/incubator-nuttx/files/8381565/systrace.txt)
   
   
   4. open the trace html via web browser:
   `$ google-chrome trace.html`


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