mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
reduce CPU usage of the performance monitor
This commit is contained in:
parent
f25633f60f
commit
ea81e21dd0
@ -175,6 +175,7 @@ void lv_disp_refr_task(lv_task_t * task)
|
|||||||
LV_LOG_TRACE("lv_refr_task: started");
|
LV_LOG_TRACE("lv_refr_task: started");
|
||||||
|
|
||||||
uint32_t start = lv_tick_get();
|
uint32_t start = lv_tick_get();
|
||||||
|
uint32_t elaps = 0;
|
||||||
|
|
||||||
/* Ensure the task does not run again automatically.
|
/* Ensure the task does not run again automatically.
|
||||||
* This is done before refreshing in case refreshing invalidates something else.
|
* This is done before refreshing in case refreshing invalidates something else.
|
||||||
@ -183,10 +184,6 @@ void lv_disp_refr_task(lv_task_t * task)
|
|||||||
|
|
||||||
disp_refr = task->user_data;
|
disp_refr = task->user_data;
|
||||||
|
|
||||||
|
|
||||||
// extern rect_cache_t cache[];
|
|
||||||
// extern uint32_t cp;
|
|
||||||
|
|
||||||
lv_refr_join_area();
|
lv_refr_join_area();
|
||||||
|
|
||||||
lv_refr_areas();
|
lv_refr_areas();
|
||||||
@ -216,7 +213,7 @@ void lv_disp_refr_task(lv_task_t * task)
|
|||||||
if(disp_refr->inv_area_joined[a] == 0) {
|
if(disp_refr->inv_area_joined[a] == 0) {
|
||||||
lv_coord_t y;
|
lv_coord_t y;
|
||||||
uint32_t start_offs =
|
uint32_t start_offs =
|
||||||
(hres * disp_refr->inv_areas[a].y1 + disp_refr->inv_areas[a].x1) * sizeof(lv_color_t);
|
(hres * disp_refr->inv_areas[a].y1 + disp_refr->inv_areas[a].x1) * sizeof(lv_color_t);
|
||||||
uint32_t line_length = lv_area_get_width(&disp_refr->inv_areas[a]) * sizeof(lv_color_t);
|
uint32_t line_length = lv_area_get_width(&disp_refr->inv_areas[a]) * sizeof(lv_color_t);
|
||||||
|
|
||||||
for(y = disp_refr->inv_areas[a].y1; y <= disp_refr->inv_areas[a].y2; y++) {
|
for(y = disp_refr->inv_areas[a].y1; y <= disp_refr->inv_areas[a].y2; y++) {
|
||||||
@ -232,50 +229,55 @@ void lv_disp_refr_task(lv_task_t * task)
|
|||||||
memset(disp_refr->inv_area_joined, 0, sizeof(disp_refr->inv_area_joined));
|
memset(disp_refr->inv_area_joined, 0, sizeof(disp_refr->inv_area_joined));
|
||||||
disp_refr->inv_p = 0;
|
disp_refr->inv_p = 0;
|
||||||
|
|
||||||
uint32_t elaps = lv_tick_elaps(start);
|
elaps = lv_tick_elaps(start);
|
||||||
/*Call monitor cb if present*/
|
/*Call monitor cb if present*/
|
||||||
if(disp_refr->driver.monitor_cb) {
|
if(disp_refr->driver.monitor_cb) {
|
||||||
disp_refr->driver.monitor_cb(&disp_refr->driver, elaps, px_num);
|
disp_refr->driver.monitor_cb(&disp_refr->driver, elaps, px_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LV_USE_PERF_MONITOR && LV_USE_LABEL
|
|
||||||
static lv_obj_t * perf_label = NULL;
|
|
||||||
if(perf_label == NULL) {
|
|
||||||
perf_label = lv_label_create(lv_layer_sys(), NULL);
|
|
||||||
lv_label_set_align(perf_label, LV_LABEL_ALIGN_RIGHT);
|
|
||||||
lv_obj_set_style_local_bg_opa(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER);
|
|
||||||
lv_obj_set_style_local_bg_color(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
|
|
||||||
lv_obj_set_style_local_text_color(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
|
||||||
lv_obj_set_style_local_pad_top(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, 3);
|
|
||||||
lv_obj_set_style_local_pad_bottom(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, 3);
|
|
||||||
lv_obj_set_style_local_pad_left(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, 3);
|
|
||||||
lv_obj_set_style_local_pad_right(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, 3);
|
|
||||||
lv_label_set_text(perf_label, "?");
|
|
||||||
lv_obj_align(perf_label, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t perf_last_time = 0;
|
|
||||||
static uint32_t elaps_max = 1;
|
|
||||||
if(lv_tick_elaps(perf_last_time) < 300) {
|
|
||||||
elaps_max = LV_MATH_MAX(elaps, elaps_max);
|
|
||||||
/*Just refresh the label to always have something to monitor*/
|
|
||||||
lv_label_set_text(perf_label, NULL);
|
|
||||||
} else {
|
|
||||||
perf_last_time = lv_tick_get();
|
|
||||||
uint32_t fps = 1000 / (elaps_max == 0 ? 1 : elaps_max);
|
|
||||||
elaps_max = 1;
|
|
||||||
uint32_t fps_limit = 1000 / disp_refr->refr_task->period;
|
|
||||||
if(fps > fps_limit) fps = fps_limit;
|
|
||||||
|
|
||||||
uint32_t cpu = 100 - lv_task_get_idle();
|
|
||||||
lv_label_set_text_fmt(perf_label, "%d FPS\n%d%% CPU", fps, cpu);
|
|
||||||
lv_obj_align(perf_label, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_mem_buf_free_all();
|
lv_mem_buf_free_all();
|
||||||
|
|
||||||
|
#if LV_USE_PERF_MONITOR && LV_USE_LABEL
|
||||||
|
static lv_obj_t * perf_label = NULL;
|
||||||
|
if(perf_label == NULL) {
|
||||||
|
perf_label = lv_label_create(lv_layer_sys(), NULL);
|
||||||
|
lv_label_set_align(perf_label, LV_LABEL_ALIGN_RIGHT);
|
||||||
|
lv_obj_set_style_local_bg_opa(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER);
|
||||||
|
lv_obj_set_style_local_bg_color(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
|
||||||
|
lv_obj_set_style_local_text_color(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
||||||
|
lv_obj_set_style_local_pad_top(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, 3);
|
||||||
|
lv_obj_set_style_local_pad_bottom(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, 3);
|
||||||
|
lv_obj_set_style_local_pad_left(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, 3);
|
||||||
|
lv_obj_set_style_local_pad_right(perf_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, 3);
|
||||||
|
lv_label_set_text(perf_label, "?");
|
||||||
|
lv_obj_align(perf_label, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t perf_last_time = 0;
|
||||||
|
static uint32_t elaps_max = 1;
|
||||||
|
if(lv_tick_elaps(perf_last_time) < 300) {
|
||||||
|
elaps_max = LV_MATH_MAX(elaps, elaps_max);
|
||||||
|
/*Just refresh 1 px to have something to monitor*/
|
||||||
|
lv_area_t a;
|
||||||
|
a.x1 = lv_disp_get_hor_res(disp_refr) - 1;
|
||||||
|
a.y1 = lv_disp_get_ver_res(disp_refr) - 1;
|
||||||
|
a.x2 = a.x1;
|
||||||
|
a.y2 = a.y1;
|
||||||
|
lv_inv_area(disp_refr, &a);
|
||||||
|
} else {
|
||||||
|
perf_last_time = lv_tick_get();
|
||||||
|
uint32_t fps = 1000 / (elaps_max == 0 ? 1 : elaps_max);
|
||||||
|
elaps_max = 1;
|
||||||
|
uint32_t fps_limit = 1000 / disp_refr->refr_task->period;
|
||||||
|
if(fps > fps_limit) fps = fps_limit;
|
||||||
|
|
||||||
|
uint32_t cpu = 100 - lv_task_get_idle();
|
||||||
|
lv_label_set_text_fmt(perf_label, "%d FPS\n%d%% CPU", fps, cpu);
|
||||||
|
lv_obj_align(perf_label, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
LV_LOG_TRACE("lv_refr_task: ready");
|
LV_LOG_TRACE("lv_refr_task: ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user