From fa5388a38b89e5f0f04c124c77af76456ff46cd2 Mon Sep 17 00:00:00 2001 From: _VIFEXTech Date: Thu, 18 May 2023 19:02:17 +0800 Subject: [PATCH] fix(profiler): fixed inability to disable and add new measurement points (#4224) Signed-off-by: FASTSHIFT Signed-off-by: pengyiqiang --- Kconfig | 2 +- docs/porting/profiler.rst | 8 ++++---- lv_conf_template.h | 15 ++++++++++---- src/core/lv_indev.c | 7 +++++++ src/core/lv_refr.c | 2 ++ src/lv_conf_internal.h | 43 +++++++++++++++++++++++---------------- src/misc/lv_profiler.h | 5 +++++ 7 files changed, 55 insertions(+), 27 deletions(-) diff --git a/Kconfig b/Kconfig index e6a951672..d020cd4c5 100644 --- a/Kconfig +++ b/Kconfig @@ -1010,7 +1010,7 @@ menu "LVGL configuration" default n config LV_USE_PROFILER - bool "Run-time performance profiler." + bool "Runtime performance profiler." config LV_PROFILER_INCLUDE string "Header to include for the profiler" depends on LV_USE_PROFILER diff --git a/docs/porting/profiler.rst b/docs/porting/profiler.rst index 9f36bee92..a02dedfae 100644 --- a/docs/porting/profiler.rst +++ b/docs/porting/profiler.rst @@ -14,9 +14,9 @@ Porting To enable profiler, set :c:macro:`LV_USE_PROFILER` in ``lv_conf.h`` and configure the following options: -- :c:macro:`LV_PROFILER_INCLUDE`: Provides a header file for the performance measurement function. -- :c:macro:`LV_PROFILER_BEGIN`: Performance measurement start point function. -- :c:macro:`LV_PROFILER_END`: Performance measurement end point function. +- :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. Example ******* @@ -30,7 +30,7 @@ Configure ``lv_conf.h``: #define LV_USE_PROFILER 1 #define LV_PROFILER_INCLUDE "lvgl/src/hal/lv_hal_tick.h" #define LV_PROFILER_BEGIN uint32_t profiler_start = lv_tick_get() - #define LV_PROFILER_END LV_LOG_USER("cost %" LV_PRIu32 "ms", lv_tick_elaps(profiler_start)) + #define LV_PROFILER_END LV_LOG_USER("cost %dms", (int)lv_tick_elaps(profiler_start)) Users can add the measured functions themselves: diff --git a/lv_conf_template.h b/lv_conf_template.h index e1401d369..7b959a24e 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -700,11 +700,18 @@ /*1: Enable system monitor component*/ #define LV_USE_SYSMON 0 -/*1: Enable the run-time performance profiler*/ +/*1: Enable the runtime performance profiler*/ #define LV_USE_PROFILER 0 -#define LV_PROFILER_INCLUDE -#define LV_PROFILER_BEGIN -#define LV_PROFILER_END +#if LV_USE_PROFILER + /*Header to include for the profiler*/ + #define LV_PROFILER_INCLUDE + + /*Profiler start point function*/ + #define LV_PROFILER_BEGIN + + /*Profiler end point function*/ + #define LV_PROFILER_END +#endif /*1: Enable Monkey test*/ #define LV_USE_MONKEY 0 diff --git a/src/core/lv_indev.c b/src/core/lv_indev.c index 98d0f8704..0582542c4 100644 --- a/src/core/lv_indev.c +++ b/src/core/lv_indev.c @@ -19,6 +19,7 @@ #include "../misc/lv_timer.h" #include "../misc/lv_math.h" #include "../misc/lv_gc.h" +#include "../misc/lv_profiler.h" /********************* * DEFINES @@ -135,6 +136,7 @@ lv_indev_t * lv_indev_get_next(lv_indev_t * indev) void _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data) { + LV_PROFILER_BEGIN; lv_memzero(data, sizeof(lv_indev_data_t)); /* For touchpad sometimes users don't set the last pressed coordinate on release. @@ -159,6 +161,7 @@ void _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data) else { LV_LOG_WARN("indev_read_cb is not registered"); } + LV_PROFILER_END; } void lv_indev_read_timer_cb(lv_timer_t * timer) @@ -177,6 +180,9 @@ void lv_indev_read_timer_cb(lv_timer_t * timer) if(indev_act->disabled || indev_act->disp->prev_scr != NULL) return; /*Input disabled or screen animation active*/ + + LV_PROFILER_BEGIN; + bool continue_reading; do { /*Read the data*/ @@ -218,6 +224,7 @@ void lv_indev_read_timer_cb(lv_timer_t * timer) indev_obj_act = NULL; INDEV_TRACE("finished"); + LV_PROFILER_END; } void lv_indev_enable(lv_indev_t * indev, bool en) diff --git a/src/core/lv_refr.c b/src/core/lv_refr.c index 958e3d621..ac68dab8a 100644 --- a/src/core/lv_refr.c +++ b/src/core/lv_refr.c @@ -1074,6 +1074,7 @@ static void draw_buf_flush(lv_disp_t * disp) static void call_flush_cb(lv_disp_t * disp, const lv_area_t * area, lv_color_t * color_p) { + LV_PROFILER_BEGIN; REFR_TRACE("Calling flush_cb on (%d;%d)(%d;%d) area with %p image pointer", (int)area->x1, (int)area->y1, (int)area->x2, (int)area->y2, (void *)color_p); @@ -1088,4 +1089,5 @@ static void call_flush_cb(lv_disp_t * disp, const lv_area_t * area, lv_color_t * if(disp->draw_ctx->buffer_convert) disp->draw_ctx->buffer_convert(disp->draw_ctx); disp->flush_cb(disp, &offset_area, color_p); + LV_PROFILER_END; } diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index bb3c0da98..6cf20cb5d 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -2346,7 +2346,7 @@ #endif #endif -/*1: Enable the run-time performance profiler*/ +/*1: Enable the runtime performance profiler*/ #ifndef LV_USE_PROFILER #ifdef CONFIG_LV_USE_PROFILER #define LV_USE_PROFILER CONFIG_LV_USE_PROFILER @@ -2354,25 +2354,32 @@ #define LV_USE_PROFILER 0 #endif #endif -#ifndef LV_PROFILER_INCLUDE - #ifdef CONFIG_LV_PROFILER_INCLUDE - #define LV_PROFILER_INCLUDE CONFIG_LV_PROFILER_INCLUDE - #else - #define LV_PROFILER_INCLUDE +#if LV_USE_PROFILER + /*Header to include for the profiler*/ + #ifndef LV_PROFILER_INCLUDE + #ifdef CONFIG_LV_PROFILER_INCLUDE + #define LV_PROFILER_INCLUDE CONFIG_LV_PROFILER_INCLUDE + #else + #define LV_PROFILER_INCLUDE + #endif #endif -#endif -#ifndef LV_PROFILER_BEGIN - #ifdef CONFIG_LV_PROFILER_BEGIN - #define LV_PROFILER_BEGIN CONFIG_LV_PROFILER_BEGIN - #else - #define LV_PROFILER_BEGIN + + /*Profiler start point function*/ + #ifndef LV_PROFILER_BEGIN + #ifdef CONFIG_LV_PROFILER_BEGIN + #define LV_PROFILER_BEGIN CONFIG_LV_PROFILER_BEGIN + #else + #define LV_PROFILER_BEGIN + #endif #endif -#endif -#ifndef LV_PROFILER_END - #ifdef CONFIG_LV_PROFILER_END - #define LV_PROFILER_END CONFIG_LV_PROFILER_END - #else - #define LV_PROFILER_END + + /*Profiler end point function*/ + #ifndef LV_PROFILER_END + #ifdef CONFIG_LV_PROFILER_END + #define LV_PROFILER_END CONFIG_LV_PROFILER_END + #else + #define LV_PROFILER_END + #endif #endif #endif diff --git a/src/misc/lv_profiler.h b/src/misc/lv_profiler.h index 683d51eb6..9537586e8 100644 --- a/src/misc/lv_profiler.h +++ b/src/misc/lv_profiler.h @@ -36,6 +36,11 @@ extern "C" { * MACROS **********************/ +#else + +#define LV_PROFILER_BEGIN +#define LV_PROFILER_END + #endif /*LV_USE_PROFILER*/ #ifdef __cplusplus