demo(benchmark): rework benchmark
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,12 @@ extern "C" {
|
||||
*********************/
|
||||
#include "../lv_demos.h"
|
||||
|
||||
#if LV_USE_DEMO_BENCHMARK
|
||||
|
||||
#if LV_USE_PERF_MONITOR == 0
|
||||
#error "lv_demo_benchmark: LV_USE_PERF_MONITOR is required. Enable it in lv_conf.h (LV_USE_PERF_MONITOR 1)"
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
@@ -22,39 +28,22 @@ extern "C" {
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef enum {
|
||||
/**Render the scenes and show them on the display.
|
||||
* Measure rendering time but it might contain extra time when LVGL waits for the driver.
|
||||
* Run each scenes for a few seconds so the performance can be seen by eye too.
|
||||
* As only the rendering time is measured and converted to FPS, really high values (e.g. 1000 FPS)
|
||||
* are possible.*/
|
||||
LV_DEMO_BENCHMARK_MODE_RENDER_AND_DRIVER,
|
||||
|
||||
/**Similar to RENDER_AND_DRIVER but instead of measuring the rendering time only measure the real FPS of the system.
|
||||
* E.g. even if a scene was rendered in 1 ms, but the screen is redrawn only in every 100 ms, the result will be 10 FPS.*/
|
||||
LV_DEMO_BENCHMARK_MODE_REAL,
|
||||
|
||||
/**Temporarily display the `flush_cb` so the pure rendering time will be measured.
|
||||
* The display is not updated during the benchmark, only at the end when the summary table is shown.
|
||||
* Render a given number of frames from each scene and calculate the FPS from them.*/
|
||||
LV_DEMO_BENCHMARK_MODE_RENDER_ONLY,
|
||||
} lv_demo_benchmark_mode_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/** Run all test scenes in the LVGL benchmark with a given mode
|
||||
*/
|
||||
void lv_demo_benchmark(lv_demo_benchmark_mode_t mode);
|
||||
|
||||
/** Run a specific test scene in the LVGL benchmark with a given mode
|
||||
*/
|
||||
void lv_demo_benchmark_run_scene(lv_demo_benchmark_mode_t mode, uint16_t scene_no);
|
||||
void lv_demo_benchmark(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*LV_USE_DEMO_BENCHMARK*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
typedef void (*demo_method_cb)(void);
|
||||
#if LV_USE_DEMO_BENCHMARK
|
||||
typedef void (*demo_method_benchmark_cb)(lv_demo_benchmark_mode_t);
|
||||
typedef void (*demo_method_benchmark_scene_cb)(lv_demo_benchmark_mode_t, uint16_t);
|
||||
// typedef void (*demo_method_benchmark_cb)(lv_demo_benchmark_mode_t);
|
||||
// typedef void (*demo_method_benchmark_scene_cb)(lv_demo_benchmark_mode_t, uint16_t);
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
@@ -34,8 +34,8 @@ typedef struct {
|
||||
union {
|
||||
demo_method_cb entry_cb;
|
||||
#if LV_USE_DEMO_BENCHMARK
|
||||
demo_method_benchmark_cb entry_benchmark_cb;
|
||||
demo_method_benchmark_scene_cb entry_benchmark_scene_cb;
|
||||
// demo_method_benchmark_cb entry_benchmark_cb;
|
||||
// demo_method_benchmark_scene_cb entry_benchmark_scene_cb;
|
||||
#endif
|
||||
};
|
||||
int arg_count : 8;
|
||||
@@ -89,10 +89,10 @@ static const demo_entry_info_t demos_entry_info[] = {
|
||||
{ "scroll", .entry_cb = lv_demo_scroll },
|
||||
#endif
|
||||
|
||||
#if LV_USE_DEMO_BENCHMARK
|
||||
{ DEMO_BENCHMARK_NAME, .entry_benchmark_cb = lv_demo_benchmark, 1 },
|
||||
{ DEMO_BENCHMARK_SCENE_NAME, .entry_benchmark_scene_cb = lv_demo_benchmark_run_scene, 2 },
|
||||
#endif
|
||||
//#if LV_USE_DEMO_BENCHMARK
|
||||
// { DEMO_BENCHMARK_NAME, .entry_benchmark_cb = lv_demo_benchmark, 1 },
|
||||
// { DEMO_BENCHMARK_SCENE_NAME, .entry_benchmark_scene_cb = lv_demo_benchmark_run_scene, 2 },
|
||||
//#endif
|
||||
{ "", .entry_cb = NULL }
|
||||
};
|
||||
|
||||
@@ -138,16 +138,16 @@ bool lv_demos_create(char * info[], int size)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#if LV_USE_DEMO_BENCHMARK
|
||||
else if(demo_is_benchmark(entry_info) && entry_info->entry_benchmark_cb) {
|
||||
entry_info->entry_benchmark_cb((lv_demo_benchmark_mode_t)atoi(info[1]));
|
||||
return true;
|
||||
}
|
||||
else if(demo_is_benchmark_scene(entry_info) && entry_info->entry_benchmark_scene_cb) {
|
||||
entry_info->entry_benchmark_scene_cb((lv_demo_benchmark_mode_t)atoi(info[1]), (uint16_t)atoi(info[2]));
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
//#if LV_USE_DEMO_BENCHMARK
|
||||
// else if(demo_is_benchmark(entry_info) && entry_info->entry_benchmark_cb) {
|
||||
// entry_info->entry_benchmark_cb((lv_demo_benchmark_mode_t)atoi(info[1]));
|
||||
// return true;
|
||||
// }
|
||||
// else if(demo_is_benchmark_scene(entry_info) && entry_info->entry_benchmark_scene_cb) {
|
||||
// entry_info->entry_benchmark_scene_cb((lv_demo_benchmark_mode_t)atoi(info[1]), (uint16_t)atoi(info[2]));
|
||||
// return true;
|
||||
// }
|
||||
//#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ static card_info_t card_info[] = {
|
||||
CARD_INFO_SET(&img_multilang_avatar_13, "Jamal Brown", "Photographer and amateur astronomer 📸"),
|
||||
CARD_INFO_SET(&img_multilang_avatar_15, "Pavel Svoboda", "Hudebník a návštěvník koncertů"),
|
||||
CARD_INFO_SET(&img_multilang_avatar_16, "Elin Lindqvist", "Språkinlärare och kulturentusiast "),
|
||||
CARD_INFO_SET(&img_multilang_avatar_17, "William Carter", "DIY enthusiast and home improvement guru "),
|
||||
CARD_INFO_SET(&img_multilang_avatar_17, "William Carter", "DIY enthusiast and home improvement guru"),
|
||||
CARD_INFO_SET(&img_multilang_avatar_22, "Ava Williams", "Artist and creative visionary 🎨"),
|
||||
CARD_INFO_SET(NULL, NULL, NULL),
|
||||
};
|
||||
|
||||
@@ -48,10 +48,13 @@ static void calendar_event_cb(lv_event_t * e);
|
||||
static void slider_event_cb(lv_event_t * e);
|
||||
static void chart_event_cb(lv_event_t * e);
|
||||
static void shop_chart_event_cb(lv_event_t * e);
|
||||
static void scale2_event_cb(lv_event_t * e);
|
||||
static void scale1_indic1_anim_cb(void * var, int32_t v);
|
||||
static void scale2_timer_cb(lv_timer_t * timer);
|
||||
static void scale3_anim_cb(void * var, int32_t v);
|
||||
static void scroll_anim_y_cb(void * var, int32_t v);
|
||||
static void scroll_anim_y_cb(void * var, int32_t v);
|
||||
static void delete_timer_event_cb(lv_event_t * e);
|
||||
static void slideshow_anim_ready_cb(lv_anim_t * a_old);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -195,6 +198,28 @@ void lv_demo_widgets(void)
|
||||
color_changer_create(tv);
|
||||
}
|
||||
|
||||
|
||||
void lv_demo_widgets_start_slideshow(void)
|
||||
{
|
||||
lv_obj_update_layout(tv);
|
||||
|
||||
lv_obj_t * cont = lv_tabview_get_content(tv);
|
||||
|
||||
lv_obj_t * tab = lv_obj_get_child(cont, 0);
|
||||
|
||||
int32_t v = lv_obj_get_scroll_bottom(tab);
|
||||
uint32_t t = lv_anim_speed_to_time(lv_display_get_dpi(NULL), 0, v);
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_exec_cb(&a, scroll_anim_y_cb);
|
||||
lv_anim_set_time(&a, t);
|
||||
lv_anim_set_playback_time(&a, t);
|
||||
lv_anim_set_values(&a, 0, v);
|
||||
lv_anim_set_var(&a, tab);
|
||||
lv_anim_set_ready_cb(&a, slideshow_anim_ready_cb);
|
||||
lv_anim_start(&a);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@@ -740,7 +765,7 @@ static void analytics_create(lv_obj_t * parent)
|
||||
lv_obj_center(arc);
|
||||
|
||||
lv_timer_t * scale2_timer = lv_timer_create(scale2_timer_cb, 100, scale2);
|
||||
lv_obj_add_event(scale2, scale2_event_cb, LV_EVENT_DELETE, scale2_timer);
|
||||
lv_obj_add_event(scale2, delete_timer_event_cb, LV_EVENT_DELETE, scale2_timer);
|
||||
|
||||
/*Scale 3*/
|
||||
lv_scale_set_range(scale3, 10, 60);
|
||||
@@ -1535,15 +1560,6 @@ static void scale1_indic1_anim_cb(void * var, int32_t v)
|
||||
lv_label_set_text_fmt(label, "Revenue: %"LV_PRId32" %%", v);
|
||||
}
|
||||
|
||||
static void scale2_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
if(code == LV_EVENT_DELETE) {
|
||||
lv_timer_t * scale2_timer = lv_event_get_user_data(e);
|
||||
if(scale2_timer) lv_timer_delete(scale2_timer);
|
||||
}
|
||||
}
|
||||
|
||||
static void scale2_timer_cb(lv_timer_t * timer)
|
||||
{
|
||||
LV_UNUSED(timer);
|
||||
@@ -1613,4 +1629,46 @@ static void scale3_anim_cb(void * var, int32_t v)
|
||||
lv_label_set_text_fmt(label, "%"LV_PRId32, v);
|
||||
}
|
||||
|
||||
static void scroll_anim_y_cb(void * var, int32_t v)
|
||||
{
|
||||
lv_obj_scroll_to_y(var, v, LV_ANIM_OFF);
|
||||
}
|
||||
|
||||
static void delete_timer_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
if(code == LV_EVENT_DELETE) {
|
||||
lv_timer_t * t = lv_event_get_user_data(e);
|
||||
if(t) lv_timer_delete(t);
|
||||
}
|
||||
}
|
||||
|
||||
static void slideshow_anim_ready_cb(lv_anim_t * a_old)
|
||||
{
|
||||
LV_UNUSED(a_old);
|
||||
|
||||
lv_obj_t * cont = lv_tabview_get_content(tv);
|
||||
uint32_t tab_id = lv_tabview_get_tab_act(tv);
|
||||
tab_id += 1;
|
||||
if(tab_id > 2) tab_id = 0;
|
||||
lv_tabview_set_act(tv, tab_id, LV_ANIM_ON);
|
||||
|
||||
lv_obj_t * tab = lv_obj_get_child(cont, tab_id);
|
||||
lv_obj_scroll_to_y(tab, 0, LV_ANIM_OFF);
|
||||
lv_obj_update_layout(tv);
|
||||
|
||||
int32_t v = lv_obj_get_scroll_bottom(tab);
|
||||
uint32_t t = lv_anim_speed_to_time(lv_display_get_dpi(NULL), 0, v);
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_exec_cb(&a, scroll_anim_y_cb);
|
||||
lv_anim_set_time(&a, t);
|
||||
lv_anim_set_playback_time(&a, t);
|
||||
lv_anim_set_values(&a, 0, v);
|
||||
lv_anim_set_var(&a, tab);
|
||||
lv_anim_set_ready_cb(&a, slideshow_anim_ready_cb);
|
||||
lv_anim_start(&a);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,6 +27,7 @@ extern "C" {
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_demo_widgets(void);
|
||||
void lv_demo_widgets_start_slideshow(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
@@ -31,6 +31,7 @@ extern "C" {
|
||||
#include "../misc/lv_profiler_builtin.h"
|
||||
#include "../misc/lv_style.h"
|
||||
#include "../misc/lv_timer.h"
|
||||
#include "../others/sysmon/lv_sysmon.h"
|
||||
#include "../stdlib/builtin/lv_tlsf.h"
|
||||
|
||||
#if LV_USE_FONT_COMPRESSED
|
||||
@@ -175,7 +176,11 @@ typedef struct _lv_global_t {
|
||||
#endif
|
||||
|
||||
#if LV_USE_SYSMON && LV_USE_PERF_MONITOR
|
||||
void * sysmon_perf_info;
|
||||
lv_sysmon_backend_data_t sysmon_perf;
|
||||
#endif
|
||||
|
||||
#if LV_USE_SYSMON && LV_USE_MEM_MONITOR
|
||||
lv_sysmon_backend_data_t sysmon_mem;
|
||||
#endif
|
||||
|
||||
#if LV_USE_IME_PINYIN != 0
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
#if LV_USE_SYSMON
|
||||
|
||||
#include "../../core/lv_global.h"
|
||||
#include "../../misc/lv_async.h"
|
||||
#include "../../stdlib/lv_string.h"
|
||||
#include "../../widgets/label/lv_label.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -20,54 +23,38 @@
|
||||
|
||||
#define SYSMON_REFR_PERIOD_DEF 300 /* ms */
|
||||
|
||||
#define perf_info LV_GLOBAL_DEFAULT()->sysmon_perf_info
|
||||
#if LV_USE_PERF_MONITOR
|
||||
#define sysmon_perf LV_GLOBAL_DEFAULT()->sysmon_perf
|
||||
#endif
|
||||
|
||||
#if LV_USE_MEM_MONITOR
|
||||
#define sysmon_mem LV_GLOBAL_DEFAULT()->sysmon_mem
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef struct {
|
||||
uint32_t refr_start;
|
||||
uint32_t refr_interval_sum;
|
||||
uint32_t refr_elaps_sum;
|
||||
uint32_t refr_cnt;
|
||||
uint32_t render_start;
|
||||
uint32_t render_elaps_sum;
|
||||
uint32_t render_cnt;
|
||||
uint32_t flush_start;
|
||||
uint32_t flush_elaps_sum;
|
||||
uint32_t flush_cnt;
|
||||
} perf_info_t;
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_sysmon_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
|
||||
static void lv_sysmon_event(const lv_obj_class_t * class_p, lv_event_t * e);
|
||||
static void lv_sysmon_timer_cb(lv_timer_t * timer);
|
||||
static void sysmon_async_cb(void * user_data);
|
||||
|
||||
static void sysmon_backend_init_async_cb(void * user_data);
|
||||
|
||||
#if LV_USE_PERF_MONITOR
|
||||
static void perf_monitor_init(void);
|
||||
static void perf_update_timer_cb(lv_timer_t * t);
|
||||
static void perf_observer_cb(lv_subject_t * subject, lv_observer_t * observer);
|
||||
#endif
|
||||
|
||||
#if LV_USE_MEM_MONITOR && LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN
|
||||
static void mem_monitor_init(void);
|
||||
#if LV_USE_MEM_MONITOR
|
||||
static void mem_update_timer_cb(lv_timer_t * t);
|
||||
static void mem_observer_cb(lv_subject_t * subject, lv_observer_t * observer);
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
const lv_obj_class_t lv_sysmon_class = {
|
||||
.base_class = &lv_label_class,
|
||||
.constructor_cb = lv_sysmon_constructor,
|
||||
.width_def = LV_SIZE_CONTENT,
|
||||
.height_def = LV_SIZE_CONTENT,
|
||||
.event_cb = lv_sysmon_event,
|
||||
.instance_size = sizeof(lv_sysmon_t),
|
||||
.name = "sysmon",
|
||||
};
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
@@ -76,200 +63,184 @@ const lv_obj_class_t lv_sysmon_class = {
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
lv_obj_t * lv_sysmon_create(lv_obj_t * parent)
|
||||
{
|
||||
LV_LOG_INFO("begin");
|
||||
lv_obj_t * obj = lv_obj_class_create_obj(MY_CLASS, parent);
|
||||
lv_obj_class_init_obj(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
void lv_sysmon_set_refr_period(lv_obj_t * obj, uint32_t period)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_sysmon_t * sysmon = (lv_sysmon_t *)obj;
|
||||
lv_timer_set_period(sysmon->timer, period);
|
||||
}
|
||||
|
||||
void _lv_sysmon_builtin_init(void)
|
||||
{
|
||||
lv_async_call(sysmon_async_cb, NULL);
|
||||
#if LV_USE_PERF_MONITOR
|
||||
static lv_sysmon_perf_info_t perf_info;
|
||||
lv_subject_init_pointer(&sysmon_perf.subject, &perf_info);
|
||||
sysmon_perf.timer = lv_timer_create(perf_update_timer_cb, SYSMON_REFR_PERIOD_DEF, &perf_info);
|
||||
#endif
|
||||
|
||||
#if LV_USE_MEM_MONITOR
|
||||
static lv_mem_monitor_t mem_info;
|
||||
lv_subject_init_pointer(&sysmon_mem.subject, &mem_info);
|
||||
sysmon_perf.timer = lv_timer_create(mem_update_timer_cb, SYSMON_REFR_PERIOD_DEF, &mem_info);
|
||||
#endif
|
||||
|
||||
lv_async_call(sysmon_backend_init_async_cb, NULL);
|
||||
}
|
||||
|
||||
void _lv_sysmon_builtin_deinit(void)
|
||||
{
|
||||
lv_async_call_cancel(sysmon_async_cb, NULL);
|
||||
lv_async_call_cancel(sysmon_backend_init_async_cb, NULL);
|
||||
#if LV_USE_PERF_MONITOR
|
||||
if(perf_info) {
|
||||
lv_free(perf_info);
|
||||
}
|
||||
// lv_subject_deinit(&sysmon_perf->subject);
|
||||
lv_timer_delete(sysmon_perf.timer);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
lv_obj_t * lv_sysmon_create(lv_obj_t * parent)
|
||||
{
|
||||
LV_LOG_INFO("begin");
|
||||
lv_obj_t * label = lv_label_create(parent);
|
||||
lv_obj_set_style_bg_opa(label, LV_OPA_50, 0);
|
||||
lv_obj_set_style_bg_color(label, lv_color_black(), 0);
|
||||
lv_obj_set_style_text_color(label, lv_color_white(), 0);
|
||||
lv_obj_set_style_pad_all(label, 3, 0);
|
||||
lv_label_set_text(label, "?");
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static void lv_sysmon_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
{
|
||||
LV_UNUSED(class_p);
|
||||
lv_sysmon_t * sysmon = (lv_sysmon_t *)obj;
|
||||
sysmon->timer = lv_timer_create(lv_sysmon_timer_cb, SYSMON_REFR_PERIOD_DEF, obj);
|
||||
lv_obj_set_style_bg_opa(obj, LV_OPA_50, 0);
|
||||
lv_obj_set_style_bg_color(obj, lv_color_black(), 0);
|
||||
lv_obj_set_style_text_color(obj, lv_color_white(), 0);
|
||||
lv_obj_set_style_pad_all(obj, 3, 0);
|
||||
lv_label_set_text(obj, "?");
|
||||
}
|
||||
|
||||
static void lv_sysmon_timer_cb(lv_timer_t * timer)
|
||||
{
|
||||
lv_obj_t * obj = lv_timer_get_user_data(timer);
|
||||
lv_obj_send_event(obj, LV_EVENT_REFRESH, NULL);
|
||||
}
|
||||
|
||||
static void lv_sysmon_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
{
|
||||
LV_UNUSED(class_p);
|
||||
lv_obj_event_base(MY_CLASS, e);
|
||||
}
|
||||
|
||||
#if LV_USE_PERF_MONITOR
|
||||
|
||||
static void perf_monitor_disp_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * sysmon = lv_event_get_user_data(e);
|
||||
perf_info_t * info = lv_obj_get_user_data(sysmon);
|
||||
lv_sysmon_perf_info_t * info = (lv_sysmon_perf_info_t *)lv_subject_get_pointer(&sysmon_perf.subject);
|
||||
|
||||
switch(code) {
|
||||
case LV_EVENT_REFR_START:
|
||||
info->refr_interval_sum += lv_tick_elaps(info->refr_start);
|
||||
info->refr_start = lv_tick_get();
|
||||
info->measured.refr_interval_sum += lv_tick_elaps(info->measured.refr_start);
|
||||
info->measured.refr_start = lv_tick_get();
|
||||
break;
|
||||
case LV_EVENT_REFR_FINISH:
|
||||
info->refr_elaps_sum += lv_tick_elaps(info->refr_start);
|
||||
info->refr_cnt++;
|
||||
info->measured.refr_elaps_sum += lv_tick_elaps(info->measured.refr_start);
|
||||
info->measured.refr_cnt++;
|
||||
break;
|
||||
case LV_EVENT_RENDER_START:
|
||||
info->render_start = lv_tick_get();
|
||||
info->measured.render_start = lv_tick_get();
|
||||
break;
|
||||
case LV_EVENT_RENDER_READY:
|
||||
info->render_elaps_sum += lv_tick_elaps(info->render_start);
|
||||
info->render_cnt++;
|
||||
info->measured.render_elaps_sum += lv_tick_elaps(info->measured.render_start);
|
||||
info->measured.render_cnt++;
|
||||
break;
|
||||
case LV_EVENT_FLUSH_START:
|
||||
info->flush_start = lv_tick_get();
|
||||
info->measured.flush_start = lv_tick_get();
|
||||
break;
|
||||
case LV_EVENT_FLUSH_FINISH:
|
||||
info->flush_elaps_sum += lv_tick_elaps(info->flush_start);
|
||||
info->flush_cnt++;
|
||||
info->measured.flush_elaps_sum += lv_tick_elaps(info->measured.flush_start);
|
||||
info->measured.flush_cnt++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void perf_monitor_event_cb(lv_event_t * e)
|
||||
static void perf_update_timer_cb(lv_timer_t * t)
|
||||
{
|
||||
lv_obj_t * sysmon = lv_event_get_current_target_obj(e);
|
||||
perf_info_t * info = lv_obj_get_user_data(sysmon);
|
||||
lv_sysmon_perf_info_t * info = lv_timer_get_user_data(t);
|
||||
|
||||
uint32_t fps = info->refr_interval_sum ? (1000 * info->refr_cnt / info->refr_interval_sum) : 0;
|
||||
uint32_t cpu = 100 - lv_timer_get_idle();
|
||||
uint32_t refr_avg_time = info->refr_cnt ? (info->refr_elaps_sum / info->refr_cnt) : 0;
|
||||
uint32_t render_avg_time = info->render_cnt ? (info->render_elaps_sum / info->render_cnt) : 0;
|
||||
uint32_t flush_avg_time = info->flush_cnt ? (info->flush_elaps_sum / info->flush_cnt) : 0;
|
||||
uint32_t render_real_avg_time = render_avg_time - flush_avg_time;
|
||||
info->calculated.fps = info->measured.refr_interval_sum ? (1000 * info->measured.refr_cnt /
|
||||
info->measured.refr_interval_sum) : 0;
|
||||
info->calculated.cpu = 100 - lv_timer_get_idle();
|
||||
info->calculated.refr_avg_time = info->measured.refr_cnt ? (info->measured.refr_elaps_sum / info->measured.refr_cnt) :
|
||||
0;
|
||||
info->calculated.render_avg_time = info->measured.render_cnt ? (info->measured.render_elaps_sum /
|
||||
info->measured.render_cnt) : 0;
|
||||
info->calculated.flush_avg_time = info->measured.flush_cnt ? (info->measured.flush_elaps_sum / info->measured.flush_cnt)
|
||||
: 0;
|
||||
info->calculated.render_real_avg_time = info->calculated.render_avg_time - info->calculated.flush_avg_time;
|
||||
|
||||
lv_subject_set_pointer(&sysmon_perf.subject, info);
|
||||
|
||||
uint32_t refr_start = info->measured.refr_start;
|
||||
lv_memzero(info, sizeof(lv_sysmon_perf_info_t));
|
||||
info->measured.refr_start = refr_start;
|
||||
|
||||
}
|
||||
|
||||
static void perf_observer_cb(lv_subject_t * subject, lv_observer_t * observer)
|
||||
{
|
||||
lv_obj_t * label = lv_observer_get_target(observer);
|
||||
const lv_sysmon_perf_info_t * perf = lv_subject_get_pointer(subject);
|
||||
|
||||
#if LV_USE_PERF_MONITOR_LOG_MODE
|
||||
/*Avoid warning*/
|
||||
LV_UNUSED(fps);
|
||||
LV_UNUSED(cpu);
|
||||
LV_UNUSED(refr_avg_time);
|
||||
LV_UNUSED(render_real_avg_time);
|
||||
LV_UNUSED(flush_avg_time);
|
||||
|
||||
LV_LOG("sysmon: "
|
||||
"%" LV_PRIu32 " FPS (refr_cnt: %" LV_PRIu32 " | redraw_cnt: %" LV_PRIu32 " | flush_cnt: %" LV_PRIu32 "), "
|
||||
"refr %" LV_PRIu32 "ms (render %" LV_PRIu32 "ms | flush %" LV_PRIu32 "ms), "
|
||||
"CPU %" LV_PRIu32 "%%\n",
|
||||
fps, info->refr_cnt, info->render_cnt, info->flush_cnt,
|
||||
refr_avg_time, render_real_avg_time, flush_avg_time,
|
||||
cpu);
|
||||
perf->calculated.fps, perf->measured.refr_cnt, perf->measured.render_cnt, perf->measured.flush_cnt,
|
||||
perf->calculated.refr_avg_time, perf->calculated.render_real_avg_time, perf->calculated.flush_avg_time,
|
||||
perf->calculated.cpu);
|
||||
#else
|
||||
lv_label_set_text_fmt(
|
||||
sysmon,
|
||||
label,
|
||||
"%" LV_PRIu32" FPS, %" LV_PRIu32 "%% CPU\n"
|
||||
"%" LV_PRIu32" ms (%" LV_PRIu32" | %" LV_PRIu32")",
|
||||
fps, cpu,
|
||||
refr_avg_time, render_real_avg_time, flush_avg_time
|
||||
perf->calculated.fps, perf->calculated.cpu,
|
||||
perf->calculated.refr_avg_time, perf->calculated.render_real_avg_time, perf->calculated.flush_avg_time
|
||||
);
|
||||
#endif /*LV_USE_PERF_MONITOR_LOG_MODE*/
|
||||
|
||||
/*Save the refresh start time of the next period*/
|
||||
uint32_t refr_start = info->refr_start;
|
||||
|
||||
/*Reset the counters*/
|
||||
lv_memzero(info, sizeof(perf_info_t));
|
||||
|
||||
/*Restore the refresh start time*/
|
||||
info->refr_start = refr_start;
|
||||
}
|
||||
|
||||
static void perf_monitor_init(void)
|
||||
{
|
||||
lv_display_t * disp = lv_display_get_default();
|
||||
|
||||
lv_obj_t * sysmon = lv_sysmon_create(lv_layer_sys());
|
||||
lv_obj_align(sysmon, LV_USE_PERF_MONITOR_POS, 0, 0);
|
||||
lv_obj_set_style_text_align(sysmon, LV_TEXT_ALIGN_RIGHT, 0);
|
||||
|
||||
perf_info_t * info = perf_info = lv_malloc(sizeof(perf_info_t));
|
||||
LV_ASSERT_MALLOC(info);
|
||||
|
||||
lv_obj_set_user_data(sysmon, info);
|
||||
lv_obj_add_event(sysmon, perf_monitor_event_cb, LV_EVENT_REFRESH, NULL);
|
||||
lv_display_add_event(disp, perf_monitor_disp_event_cb, LV_EVENT_ALL, sysmon);
|
||||
|
||||
#if LV_USE_PERF_MONITOR_LOG_MODE
|
||||
/*Reduce rendering performance consumption*/
|
||||
lv_obj_add_flag(sysmon, LV_OBJ_FLAG_HIDDEN);
|
||||
#endif
|
||||
|
||||
#if LV_USE_MEM_MONITOR
|
||||
|
||||
static void mem_update_timer_cb(lv_timer_t * t)
|
||||
{
|
||||
lv_mem_monitor_t * mem_mon = lv_timer_get_user_data(t);
|
||||
lv_mem_monitor(mem_mon);
|
||||
lv_subject_set_pointer(&sysmon_mem.subject, mem_mon);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LV_USE_MEM_MONITOR && LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN
|
||||
static void mem_monitor_event_cb(lv_event_t * e)
|
||||
static void mem_observer_cb(lv_subject_t * subject, lv_observer_t * observer)
|
||||
{
|
||||
lv_obj_t * sysmon = lv_event_get_current_target_obj(e);
|
||||
lv_mem_monitor_t mon;
|
||||
lv_mem_monitor(&mon);
|
||||
uint32_t used_size = mon.total_size - mon.free_size;;
|
||||
lv_obj_t * label = lv_observer_get_target(observer);
|
||||
const lv_mem_monitor_t * mon = lv_subject_get_pointer(subject);
|
||||
|
||||
uint32_t used_size = mon->total_size - mon->free_size;;
|
||||
uint32_t used_kb = used_size / 1024;
|
||||
uint32_t used_kb_tenth = (used_size - (used_kb * 1024)) / 102;
|
||||
lv_label_set_text_fmt(sysmon,
|
||||
lv_label_set_text_fmt(label,
|
||||
"%"LV_PRIu32 ".%"LV_PRIu32 " kB, %d%%\n"
|
||||
"%d%% frag.",
|
||||
used_kb, used_kb_tenth, mon.used_pct,
|
||||
mon.frag_pct);
|
||||
used_kb, used_kb_tenth, mon->used_pct,
|
||||
mon->frag_pct);
|
||||
}
|
||||
|
||||
static void mem_monitor_init(void)
|
||||
{
|
||||
lv_obj_t * sysmon = lv_sysmon_create(lv_layer_sys());
|
||||
lv_obj_add_event(sysmon, mem_monitor_event_cb, LV_EVENT_REFRESH, NULL);
|
||||
lv_obj_align(sysmon, LV_USE_MEM_MONITOR_POS, 0, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void sysmon_async_cb(void * user_data)
|
||||
static void sysmon_backend_init_async_cb(void * user_data)
|
||||
{
|
||||
LV_UNUSED(user_data);
|
||||
|
||||
#if LV_USE_PERF_MONITOR
|
||||
perf_monitor_init();
|
||||
lv_display_add_event(lv_display_get_default(), perf_monitor_disp_event_cb, LV_EVENT_ALL, NULL);
|
||||
|
||||
#if !LV_USE_PERF_MONITOR_LOG_MODE
|
||||
lv_obj_t * obj1 = lv_sysmon_create(lv_layer_sys());
|
||||
lv_obj_align(obj1, LV_USE_PERF_MONITOR_POS, 0, 0);
|
||||
lv_subject_add_observer_obj(&sysmon_perf.subject, perf_observer_cb, obj1, NULL);
|
||||
#endif
|
||||
#if LV_USE_MEM_MONITOR && LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN
|
||||
mem_monitor_init();
|
||||
|
||||
#endif
|
||||
|
||||
#if LV_USE_MEM_MONITOR
|
||||
lv_obj_t * obj2 = lv_sysmon_create(lv_layer_sys());
|
||||
lv_obj_align(obj2, LV_USE_MEM_MONITOR_POS, 0, 0);
|
||||
lv_subject_add_observer_obj(&sysmon_mem.subject, mem_observer_cb, obj2, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif /*LV_USE_SYSMON*/
|
||||
|
||||
@@ -14,7 +14,8 @@ extern "C" {
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
#include "../../../lvgl.h"
|
||||
#include "../../misc/lv_timer.h"
|
||||
#include "../../others/observer/lv_observer.h"
|
||||
|
||||
#if LV_USE_SYSMON
|
||||
|
||||
@@ -29,12 +30,38 @@ extern "C" {
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef struct {
|
||||
lv_label_t label;
|
||||
lv_timer_t * timer;
|
||||
} lv_sysmon_t;
|
||||
|
||||
extern const lv_obj_class_t lv_sysmon_class;
|
||||
typedef struct {
|
||||
lv_subject_t subject;
|
||||
lv_timer_t * timer;
|
||||
} lv_sysmon_backend_data_t;
|
||||
|
||||
#if LV_USE_PERF_MONITOR
|
||||
typedef struct {
|
||||
struct {
|
||||
uint32_t refr_start;
|
||||
uint32_t refr_interval_sum;
|
||||
uint32_t refr_elaps_sum;
|
||||
uint32_t refr_cnt;
|
||||
uint32_t render_start;
|
||||
uint32_t render_elaps_sum;
|
||||
uint32_t render_cnt;
|
||||
uint32_t flush_start;
|
||||
uint32_t flush_elaps_sum;
|
||||
uint32_t flush_cnt;
|
||||
} measured;
|
||||
|
||||
struct {
|
||||
uint32_t fps;
|
||||
uint32_t cpu;
|
||||
uint32_t refr_avg_time;
|
||||
uint32_t render_avg_time;
|
||||
uint32_t flush_avg_time;
|
||||
uint32_t render_real_avg_time;
|
||||
} calculated;
|
||||
|
||||
} lv_sysmon_perf_info_t;
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
|
||||
Reference in New Issue
Block a user