From 605379ab3cb8fe5983f463ad5297cb0cef75e773 Mon Sep 17 00:00:00 2001 From: _VIFEXTech Date: Fri, 27 Oct 2023 17:38:08 +0800 Subject: [PATCH] feat(profiler): add custom tag support (#4710) Signed-off-by: pengyiqiang Signed-off-by: FASTSHIFT Co-authored-by: pengyiqiang --- docs/overview/profiler.rst | 23 ++++++++++++++++++++--- lv_conf_template.h | 10 ++++++++-- src/core/lv_refr.c | 2 ++ src/lv_conf_internal.h | 22 ++++++++++++++++++++-- src/misc/lv_profiler.h | 2 ++ src/misc/lv_profiler_builtin.h | 6 ++++-- 6 files changed, 56 insertions(+), 9 deletions(-) diff --git a/docs/overview/profiler.rst b/docs/overview/profiler.rst index 4f043d923..2385de9c7 100644 --- a/docs/overview/profiler.rst +++ b/docs/overview/profiler.rst @@ -144,13 +144,24 @@ Users can add their own measured functions: .. code:: c - void my_function(void) + void my_function_1(void) { LV_PROFILER_BEGIN; do_something(); LV_PROFILER_END; } + void my_function_2(void) + { + LV_PROFILER_BEGIN_TAG("do_something_1"); + do_something_1(); + LV_PROFILER_END_TAG("do_something_1"); + + LV_PROFILER_BEGIN_TAG("do_something_2"); + do_something_2(); + LV_PROFILER_END_TAG("do_something_2"); + } + Custom profiler implementation ****************************** @@ -159,14 +170,19 @@ If you wish to use a profiler method provided by your operating system, you can - :c:macro:`LV_PROFILER_INCLUDE`: Provides a header file for the profiler function. - :c:macro:`LV_PROFILER_BEGIN`: Profiler start point function. - :c:macro:`LV_PROFILER_END`: Profiler end point function. +- :c:macro:`LV_PROFILER_BEGIN_TAG`: Profiler start point function with custom tag. +- :c:macro:`LV_PROFILER_END_TAG`: Profiler end point function with custom tag. + Taking `NuttX `_ RTOS as an example: .. code:: c #define LV_PROFILER_INCLUDE "nuttx/sched_note.h" - #define LV_PROFILER_BEGIN sched_note_begin(NOTE_TAG_ALWAYS) - #define LV_PROFILER_END sched_note_end(NOTE_TAG_ALWAYS) + #define LV_PROFILER_BEGIN sched_note_begin(NOTE_TAG_ALWAYS) + #define LV_PROFILER_END sched_note_end(NOTE_TAG_ALWAYS) + #define LV_PROFILER_BEGIN_TAG(str) sched_note_beginex(NOTE_TAG_ALWAYS, str) + #define LV_PROFILER_END_TAG(str) sched_note_endex(NOTE_TAG_ALWAYS, str) FAQ *** @@ -179,6 +195,7 @@ Please check the completeness of the logs. If the logs are incomplete, it may be 1. Serial port reception errors caused by a high baud rate. You need to reduce the baud rate. 2. Data corruption caused by other thread logs inserted during the printing of trace logs. You need to disable the log output of other threads or refer to the configuration above to use a separate log output interface. 3. Cross-thread calling of :c:macro:`LV_PROFILER_BEGIN/END`.The built-in LVGL profiler is designed for single-threaded use, so calling it from multiple threads can lead to thread safety issues. If you need to use it in a multi-threaded environment, you can use profiler interfaces provided by your operating system that ensure thread safety. +4. Make sure that the string passed in by c:macro:`LV_PROFILER_BEGIN_TAG/END_TAG` is not a local variable on the stack or a string in shared memory, because currently only the string address is recorded and the content is not copied. Function execution time displayed as 0s in Perfetto ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/lv_conf_template.h b/lv_conf_template.h index 90f76e216..34608a702 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -681,10 +681,16 @@ #define LV_PROFILER_INCLUDE "lvgl/src/misc/lv_profiler_builtin.h" /*Profiler start point function*/ - #define LV_PROFILER_BEGIN LV_PROFILER_BUILTIN_BEGIN + #define LV_PROFILER_BEGIN LV_PROFILER_BUILTIN_BEGIN /*Profiler end point function*/ - #define LV_PROFILER_END LV_PROFILER_BUILTIN_END + #define LV_PROFILER_END LV_PROFILER_BUILTIN_END + + /*Profiler start point function with custom tag*/ + #define LV_PROFILER_BEGIN_TAG LV_PROFILER_BUILTIN_BEGIN_TAG + + /*Profiler end point function with custom tag*/ + #define LV_PROFILER_END_TAG LV_PROFILER_BUILTIN_END_TAG #endif /*1: Enable Monkey test*/ diff --git a/src/core/lv_refr.c b/src/core/lv_refr.c index dbbc7af0a..f6abf960a 100644 --- a/src/core/lv_refr.c +++ b/src/core/lv_refr.c @@ -353,12 +353,14 @@ void _lv_display_refr_timer(lv_timer_t * tmr) lv_display_send_event(disp_refr, LV_EVENT_REFR_START, NULL); /*Refresh the screen's layout if required*/ + LV_PROFILER_BEGIN_TAG("layout"); lv_obj_update_layout(disp_refr->act_scr); if(disp_refr->prev_scr) lv_obj_update_layout(disp_refr->prev_scr); lv_obj_update_layout(disp_refr->bottom_layer); lv_obj_update_layout(disp_refr->top_layer); lv_obj_update_layout(disp_refr->sys_layer); + LV_PROFILER_END_TAG("layout"); /*Do nothing if there is no active screen*/ if(disp_refr->act_scr == NULL) { diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index b096512c8..57243f775 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -2233,7 +2233,7 @@ #ifdef CONFIG_LV_PROFILER_BEGIN #define LV_PROFILER_BEGIN CONFIG_LV_PROFILER_BEGIN #else - #define LV_PROFILER_BEGIN LV_PROFILER_BUILTIN_BEGIN + #define LV_PROFILER_BEGIN LV_PROFILER_BUILTIN_BEGIN #endif #endif @@ -2242,7 +2242,25 @@ #ifdef CONFIG_LV_PROFILER_END #define LV_PROFILER_END CONFIG_LV_PROFILER_END #else - #define LV_PROFILER_END LV_PROFILER_BUILTIN_END + #define LV_PROFILER_END LV_PROFILER_BUILTIN_END + #endif + #endif + + /*Profiler start point function with custom tag*/ + #ifndef LV_PROFILER_BEGIN_TAG + #ifdef CONFIG_LV_PROFILER_BEGIN_TAG + #define LV_PROFILER_BEGIN_TAG CONFIG_LV_PROFILER_BEGIN_TAG + #else + #define LV_PROFILER_BEGIN_TAG LV_PROFILER_BUILTIN_BEGIN_TAG + #endif + #endif + + /*Profiler end point function with custom tag*/ + #ifndef LV_PROFILER_END_TAG + #ifdef CONFIG_LV_PROFILER_END_TAG + #define LV_PROFILER_END_TAG CONFIG_LV_PROFILER_END_TAG + #else + #define LV_PROFILER_END_TAG LV_PROFILER_BUILTIN_END_TAG #endif #endif #endif diff --git a/src/misc/lv_profiler.h b/src/misc/lv_profiler.h index 9537586e8..47d5bd243 100644 --- a/src/misc/lv_profiler.h +++ b/src/misc/lv_profiler.h @@ -40,6 +40,8 @@ extern "C" { #define LV_PROFILER_BEGIN #define LV_PROFILER_END +#define LV_PROFILER_BEGIN_TAG(tag) LV_UNUSED(tag) +#define LV_PROFILER_END_TAG(tag) LV_UNUSED(tag) #endif /*LV_USE_PROFILER*/ diff --git a/src/misc/lv_profiler_builtin.h b/src/misc/lv_profiler_builtin.h index 66fe3472d..d70d37d93 100644 --- a/src/misc/lv_profiler_builtin.h +++ b/src/misc/lv_profiler_builtin.h @@ -26,8 +26,10 @@ extern "C" { * DEFINES *********************/ -#define LV_PROFILER_BUILTIN_BEGIN lv_profiler_builtin_write(__func__, 'B') -#define LV_PROFILER_BUILTIN_END lv_profiler_builtin_write(__func__, 'E') +#define LV_PROFILER_BUILTIN_BEGIN_TAG(tag) lv_profiler_builtin_write((tag), 'B') +#define LV_PROFILER_BUILTIN_END_TAG(tag) lv_profiler_builtin_write((tag), 'E') +#define LV_PROFILER_BUILTIN_BEGIN LV_PROFILER_BUILTIN_BEGIN_TAG(__func__) +#define LV_PROFILER_BUILTIN_END LV_PROFILER_BUILTIN_END_TAG(__func__) /********************** * TYPEDEFS