fix(demo): fix showing the average FPS

This commit is contained in:
Gabor Kiss-Vamosi
2023-11-06 14:25:25 +01:00
parent e3380a8fe8
commit 96ce505651
3 changed files with 25 additions and 7 deletions

View File

@@ -12,6 +12,7 @@
#include "lv_demo_music_main.h" #include "lv_demo_music_main.h"
#include "lv_demo_music_list.h" #include "lv_demo_music_list.h"
#include "../../src/core/lv_global.h"
/********************* /*********************
* DEFINES * DEFINES
@@ -103,6 +104,10 @@ static const uint32_t time_list[] = {
2 * 60 + 19, 2 * 60 + 19,
}; };
#if LV_USE_PERF_MONITOR || LV_DEMO_MUSIC_AUTO_PLAY
#define sysmon_perf LV_GLOBAL_DEFAULT()->sysmon_perf
#endif
/********************** /**********************
* MACROS * MACROS
**********************/ **********************/
@@ -225,7 +230,8 @@ static void auto_step_cb(lv_timer_t * t)
lv_obj_t * num = lv_label_create(bg); lv_obj_t * num = lv_label_create(bg);
lv_obj_set_style_text_font(num, font_large, 0); lv_obj_set_style_text_font(num, font_large, 0);
#if LV_USE_PERF_MONITOR #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 #endif
lv_obj_align(num, LV_ALIGN_TOP_MID, 0, 120); lv_obj_align(num, LV_ALIGN_TOP_MID, 0, 120);

View File

@@ -84,7 +84,6 @@ void _lv_sysmon_builtin_deinit(void)
{ {
lv_async_call_cancel(sysmon_backend_init_async_cb, NULL); lv_async_call_cancel(sysmon_backend_init_async_cb, NULL);
#if LV_USE_PERF_MONITOR #if LV_USE_PERF_MONITOR
// lv_subject_deinit(&sysmon_perf->subject);
lv_timer_delete(sysmon_perf.timer); lv_timer_delete(sysmon_perf.timer);
#endif #endif
} }
@@ -102,8 +101,6 @@ lv_obj_t * lv_sysmon_create(lv_obj_t * parent)
return label; return label;
} }
/********************** /**********************
* STATIC FUNCTIONS * 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) static void perf_update_timer_cb(lv_timer_t * t)
{ {
lv_sysmon_perf_info_t * info = lv_timer_get_user_data(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->calculated.fps = info->measured.refr_interval_sum ? (1000 * info->measured.refr_cnt /
info->measured.refr_interval_sum) : 0; info->measured.refr_interval_sum) : 0;
@@ -159,12 +157,19 @@ static void perf_update_timer_cb(lv_timer_t * t)
: 0; : 0;
info->calculated.render_real_avg_time = info->calculated.render_avg_time - info->calculated.flush_avg_time; 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); 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)); 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) static void perf_observer_cb(lv_subject_t * subject, lv_observer_t * observer)

View File

@@ -23,6 +23,10 @@ extern "C" {
#error "lv_sysmon: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) " #error "lv_sysmon: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) "
#endif #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 * DEFINES
*********************/ *********************/
@@ -58,6 +62,9 @@ typedef struct {
uint32_t render_avg_time; uint32_t render_avg_time;
uint32_t flush_avg_time; uint32_t flush_avg_time;
uint32_t render_real_avg_time; uint32_t render_real_avg_time;
uint32_t cpu_avg_total;
uint32_t fps_avg_total;
uint32_t run_cnt;
} calculated; } calculated;
} lv_sysmon_perf_info_t; } lv_sysmon_perf_info_t;