From 96ce505651901518bc3b6cb6847feac2a6e8dd2b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 6 Nov 2023 14:25:25 +0100 Subject: [PATCH] fix(demo): fix showing the average FPS --- demos/music/lv_demo_music.c | 8 +++++++- src/others/sysmon/lv_sysmon.c | 17 +++++++++++------ src/others/sysmon/lv_sysmon.h | 7 +++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/demos/music/lv_demo_music.c b/demos/music/lv_demo_music.c index 92a1b57a4..f72213e97 100644 --- a/demos/music/lv_demo_music.c +++ b/demos/music/lv_demo_music.c @@ -12,6 +12,7 @@ #include "lv_demo_music_main.h" #include "lv_demo_music_list.h" +#include "../../src/core/lv_global.h" /********************* * DEFINES @@ -103,6 +104,10 @@ static const uint32_t time_list[] = { 2 * 60 + 19, }; +#if LV_USE_PERF_MONITOR || LV_DEMO_MUSIC_AUTO_PLAY + #define sysmon_perf LV_GLOBAL_DEFAULT()->sysmon_perf +#endif + /********************** * MACROS **********************/ @@ -225,7 +230,8 @@ static void auto_step_cb(lv_timer_t * t) lv_obj_t * num = lv_label_create(bg); lv_obj_set_style_text_font(num, font_large, 0); #if LV_USE_PERF_MONITOR - lv_label_set_text_fmt(num, "%" LV_PRIu32, lv_refr_get_fps_avg()); + const lv_sysmon_perf_info_t * info = lv_subject_get_pointer(&sysmon_perf.subject); + lv_label_set_text_fmt(num, "%" LV_PRIu32, info->calculated.cpu_avg_total); #endif lv_obj_align(num, LV_ALIGN_TOP_MID, 0, 120); diff --git a/src/others/sysmon/lv_sysmon.c b/src/others/sysmon/lv_sysmon.c index de9404865..c208e664b 100644 --- a/src/others/sysmon/lv_sysmon.c +++ b/src/others/sysmon/lv_sysmon.c @@ -84,7 +84,6 @@ void _lv_sysmon_builtin_deinit(void) { lv_async_call_cancel(sysmon_backend_init_async_cb, NULL); #if LV_USE_PERF_MONITOR - // lv_subject_deinit(&sysmon_perf->subject); lv_timer_delete(sysmon_perf.timer); #endif } @@ -102,8 +101,6 @@ lv_obj_t * lv_sysmon_create(lv_obj_t * parent) return label; } - - /********************** * STATIC FUNCTIONS **********************/ @@ -147,6 +144,7 @@ static void perf_monitor_disp_event_cb(lv_event_t * e) static void perf_update_timer_cb(lv_timer_t * t) { lv_sysmon_perf_info_t * info = lv_timer_get_user_data(t); + info->calculated.run_cnt++; info->calculated.fps = info->measured.refr_interval_sum ? (1000 * info->measured.refr_cnt / info->measured.refr_interval_sum) : 0; @@ -159,12 +157,19 @@ static void perf_update_timer_cb(lv_timer_t * t) : 0; info->calculated.render_real_avg_time = info->calculated.render_avg_time - info->calculated.flush_avg_time; + info->calculated.cpu_avg_total = ((info->calculated.cpu_avg_total * (info->calculated.run_cnt - 1)) + + info->calculated.cpu) / info->calculated.run_cnt; + info->calculated.fps_avg_total = ((info->calculated.fps_avg_total * (info->calculated.run_cnt - 1)) + + info->calculated.fps) / info->calculated.run_cnt; + lv_subject_set_pointer(&sysmon_perf.subject, info); - uint32_t refr_start = info->measured.refr_start; + lv_sysmon_perf_info_t prev_info = *info; lv_memzero(info, sizeof(lv_sysmon_perf_info_t)); - info->measured.refr_start = refr_start; - + info->measured.refr_start = prev_info.measured.refr_start; + info->calculated.cpu_avg_total = prev_info.calculated.cpu_avg_total; + info->calculated.fps_avg_total = prev_info.calculated.fps_avg_total; + info->calculated.run_cnt = prev_info.calculated.run_cnt; } static void perf_observer_cb(lv_subject_t * subject, lv_observer_t * observer) diff --git a/src/others/sysmon/lv_sysmon.h b/src/others/sysmon/lv_sysmon.h index 0420f8e64..9016ddc16 100644 --- a/src/others/sysmon/lv_sysmon.h +++ b/src/others/sysmon/lv_sysmon.h @@ -23,6 +23,10 @@ extern "C" { #error "lv_sysmon: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) " #endif +#if LV_USE_OBSERVER == 0 +#error "lv_observer: lv_observer is required. Enable it in lv_conf.h (LV_USE_OBSERVER 1) " +#endif + /********************* * DEFINES *********************/ @@ -58,6 +62,9 @@ typedef struct { uint32_t render_avg_time; uint32_t flush_avg_time; uint32_t render_real_avg_time; + uint32_t cpu_avg_total; + uint32_t fps_avg_total; + uint32_t run_cnt; } calculated; } lv_sysmon_perf_info_t;