mirror of
https://github.com/lvgl/lvgl.git
synced 2026-06-01 00:51:49 +08:00
feat(sysmon): add API to start or stop sysmon and dump FPS info (#8533)
Arduino Lint / lint (push) Has been cancelled
Build Examples with C++ Compiler / build-examples (push) Has been cancelled
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_VG_LITE - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_VG_LITE - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_VG_LITE - gcc - Windows (push) Has been cancelled
C/C++ CI / Build ESP IDF ESP32S3 (push) Has been cancelled
C/C++ CI / Run tests with 32bit build (push) Has been cancelled
C/C++ CI / Run tests with 64bit build (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Build docs / build-and-deploy (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Check Makefile / Build using Makefile (push) Has been cancelled
Check Makefile for UEFI / Build using Makefile for UEFI (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/benchmark_results_comment/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/filter_docker_logs/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/serialize_results/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 32b - lv_conf_perf32b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 64b - lv_conf_perf64b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Save PR Number (push) Has been cancelled
Hardware Performance Test / Hardware Performance Benchmark (push) Has been cancelled
Hardware Performance Test / HW Benchmark - Save PR Number (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_32B - Ubuntu (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_64B - Ubuntu (push) Has been cancelled
Port repo release update / run-release-branch-updater (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled
Arduino Lint / lint (push) Has been cancelled
Build Examples with C++ Compiler / build-examples (push) Has been cancelled
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_VG_LITE - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_VG_LITE - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_VG_LITE - gcc - Windows (push) Has been cancelled
C/C++ CI / Build ESP IDF ESP32S3 (push) Has been cancelled
C/C++ CI / Run tests with 32bit build (push) Has been cancelled
C/C++ CI / Run tests with 64bit build (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Build docs / build-and-deploy (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Check Makefile / Build using Makefile (push) Has been cancelled
Check Makefile for UEFI / Build using Makefile for UEFI (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/benchmark_results_comment/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/filter_docker_logs/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/serialize_results/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 32b - lv_conf_perf32b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 64b - lv_conf_perf64b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Save PR Number (push) Has been cancelled
Hardware Performance Test / Hardware Performance Benchmark (push) Has been cancelled
Hardware Performance Test / HW Benchmark - Save PR Number (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_32B - Ubuntu (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_64B - Ubuntu (push) Has been cancelled
Port repo release update / run-release-branch-updater (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled
Signed-off-by: wangxuedong <wangxuedong@xiaomi.com> Signed-off-by: wxd <xaowang96@gmail.com>
This commit is contained in:
@@ -18,5 +18,6 @@ Auxiliary Modules
|
|||||||
obj_property
|
obj_property
|
||||||
observer/index
|
observer/index
|
||||||
snapshot
|
snapshot
|
||||||
|
sysmon
|
||||||
test
|
test
|
||||||
translation
|
translation
|
||||||
|
|||||||
@@ -0,0 +1,139 @@
|
|||||||
|
.. _sysmon:
|
||||||
|
|
||||||
|
=======================
|
||||||
|
System Monitor (sysmon)
|
||||||
|
=======================
|
||||||
|
|
||||||
|
The System Monitor module provides real-time monitoring of system performance
|
||||||
|
metrics directly on your display. It supports both performance monitoring
|
||||||
|
(CPU usage and FPS) and memory monitoring (used memory and fragmentation).
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
************
|
||||||
|
- Requires ``LV_USE_LABEL = 1`` in lv_conf.h
|
||||||
|
- Requires ``LV_USE_OBSERVER = 1`` in lv_conf.h
|
||||||
|
- Requires ``LV_USE_SYSMON = 1`` in lv_conf.h
|
||||||
|
|
||||||
|
.. _sysmon_usage:
|
||||||
|
|
||||||
|
Usage
|
||||||
|
*****
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
--------------
|
||||||
|
Enable in ``lv_conf.h``:
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
/* Main sysmon enable */
|
||||||
|
#define LV_USE_SYSMON 1
|
||||||
|
|
||||||
|
/* Performance monitor (CPU% and FPS) */
|
||||||
|
#define LV_USE_PERF_MONITOR 1
|
||||||
|
|
||||||
|
/* Memory monitor (used + fragmentation) */
|
||||||
|
#define LV_USE_MEM_MONITOR 1
|
||||||
|
|
||||||
|
/* Optional: refresh period in ms */
|
||||||
|
#define LV_SYSMON_REFR_PERIOD_DEF 300
|
||||||
|
|
||||||
|
/* Optional: log to console instead of screen */
|
||||||
|
#define LV_USE_PERF_MONITOR_LOG_MODE 0
|
||||||
|
|
||||||
|
Creating Monitors
|
||||||
|
-----------------
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
/* Create generic monitor */
|
||||||
|
lv_obj_t * sysmon = lv_sysmon_create(lv_display_get_default());
|
||||||
|
|
||||||
|
/* Create performance monitor */
|
||||||
|
lv_sysmon_show_performance(NULL); /* NULL = default display */
|
||||||
|
|
||||||
|
/* Create memory monitor */
|
||||||
|
lv_sysmon_show_memory(NULL);
|
||||||
|
|
||||||
|
Performance Monitor
|
||||||
|
-------------------
|
||||||
|
Tracks:
|
||||||
|
- FPS (Frames Per Second)
|
||||||
|
- CPU usage (%)
|
||||||
|
- Render time (ms)
|
||||||
|
- Flush time (ms)
|
||||||
|
- Self CPU usage (%) if enabled
|
||||||
|
|
||||||
|
Display format:
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
32 FPS, 45% CPU
|
||||||
|
8 ms
|
||||||
|
|
||||||
|
Where:
|
||||||
|
- Line 1: FPS, Total CPU%
|
||||||
|
- Line 2: Total time (Render | Flush)
|
||||||
|
|
||||||
|
Pause and Resume
|
||||||
|
****************
|
||||||
|
|
||||||
|
:cpp:expr:`lv_sysmon_performance_pause(disp)` pauses the perf monitor.
|
||||||
|
|
||||||
|
:cpp:expr:`lv_sysmon_performance_resume(disp)` resumes the perf monitor.
|
||||||
|
|
||||||
|
Memory Monitor
|
||||||
|
--------------
|
||||||
|
Displays:
|
||||||
|
- Current memory usage (kB and %)
|
||||||
|
- Peak memory usage (kB)
|
||||||
|
- Fragmentation (%)
|
||||||
|
|
||||||
|
Display format:
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
24.8 kB (76%)
|
||||||
|
32.4 kB max, 18% frag.
|
||||||
|
|
||||||
|
Positioning
|
||||||
|
-----------
|
||||||
|
Configure positions in lv_conf.h:
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
/* Top-right corner */
|
||||||
|
#define LV_USE_PERF_MONITOR_POS LV_ALIGN_TOP_RIGHT
|
||||||
|
|
||||||
|
/* Bottom-right corner */
|
||||||
|
#define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT
|
||||||
|
|
||||||
|
|
||||||
|
Implementation Details
|
||||||
|
**********************
|
||||||
|
|
||||||
|
Initialization
|
||||||
|
--------------
|
||||||
|
Maintains:
|
||||||
|
- Global memory monitor (``sysmon_mem``)
|
||||||
|
- Per-display performance structures
|
||||||
|
|
||||||
|
Performance Measurement
|
||||||
|
-----------------------
|
||||||
|
Event-based collection:
|
||||||
|
|
||||||
|
+----------------------+--------------------------------+
|
||||||
|
| Event | Measurement |
|
||||||
|
+======================+================================+
|
||||||
|
| LV_EVENT_REFR_START | Refresh interval start |
|
||||||
|
+----------------------+--------------------------------+
|
||||||
|
| LV_EVENT_REFR_READY | Record refresh duration |
|
||||||
|
+----------------------+--------------------------------+
|
||||||
|
| LV_EVENT_RENDER_START| Render time start |
|
||||||
|
+----------------------+--------------------------------+
|
||||||
|
| LV_EVENT_RENDER_READY| Record render duration |
|
||||||
|
+----------------------+--------------------------------+
|
||||||
|
| LV_EVENT_FLUSH_* | Measure flush operations |
|
||||||
|
+----------------------+--------------------------------+
|
||||||
|
|
||||||
|
Timers
|
||||||
|
------
|
||||||
|
- Performance: ``perf_update_timer_cb``
|
||||||
|
- Memory: ``mem_update_timer_cb``
|
||||||
|
- Default period: 300ms (``LV_SYSMON_REFR_PERIOD_DEF``)
|
||||||
@@ -41,6 +41,8 @@
|
|||||||
static void perf_update_timer_cb(lv_timer_t * t);
|
static void perf_update_timer_cb(lv_timer_t * t);
|
||||||
static void perf_observer_cb(lv_observer_t * observer, lv_subject_t * subject);
|
static void perf_observer_cb(lv_observer_t * observer, lv_subject_t * subject);
|
||||||
static void perf_monitor_disp_event_cb(lv_event_t * e);
|
static void perf_monitor_disp_event_cb(lv_event_t * e);
|
||||||
|
static void perf_dump_info(lv_display_t * disp);
|
||||||
|
static void perf_control(lv_display_t * disp, bool start);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LV_USE_MEM_MONITOR
|
#if LV_USE_MEM_MONITOR
|
||||||
@@ -137,6 +139,26 @@ void lv_sysmon_hide_performance(lv_display_t * disp)
|
|||||||
lv_obj_add_flag(disp->perf_label, LV_OBJ_FLAG_HIDDEN);
|
lv_obj_add_flag(disp->perf_label, LV_OBJ_FLAG_HIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lv_sysmon_performance_dump(lv_display_t * disp)
|
||||||
|
{
|
||||||
|
if(disp == NULL) disp = lv_display_get_default();
|
||||||
|
if(disp == NULL) {
|
||||||
|
LV_LOG_WARN("There is no default display");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
perf_dump_info(disp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lv_sysmon_performance_resume(lv_display_t * disp)
|
||||||
|
{
|
||||||
|
perf_control(disp, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lv_sysmon_performance_pause(lv_display_t * disp)
|
||||||
|
{
|
||||||
|
perf_control(disp, false);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LV_USE_MEM_MONITOR
|
#if LV_USE_MEM_MONITOR
|
||||||
@@ -233,13 +255,10 @@ static void perf_monitor_disp_event_cb(lv_event_t * e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void perf_update_timer_cb(lv_timer_t * t)
|
static void perf_dump_info(lv_display_t * disp)
|
||||||
{
|
{
|
||||||
lv_display_t * disp = lv_timer_get_user_data(t);
|
|
||||||
|
|
||||||
uint32_t LV_SYSMON_GET_IDLE(void);
|
uint32_t LV_SYSMON_GET_IDLE(void);
|
||||||
|
|
||||||
|
|
||||||
lv_sysmon_perf_info_t * info = &disp->perf_sysmon_info;
|
lv_sysmon_perf_info_t * info = &disp->perf_sysmon_info;
|
||||||
info->calculated.run_cnt++;
|
info->calculated.run_cnt++;
|
||||||
|
|
||||||
@@ -287,6 +306,13 @@ static void perf_update_timer_cb(lv_timer_t * t)
|
|||||||
info->measured.last_report_timestamp = lv_tick_get();
|
info->measured.last_report_timestamp = lv_tick_get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void perf_update_timer_cb(lv_timer_t * t)
|
||||||
|
{
|
||||||
|
lv_display_t * disp = lv_timer_get_user_data(t);
|
||||||
|
|
||||||
|
perf_dump_info(disp);
|
||||||
|
}
|
||||||
|
|
||||||
static void perf_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
static void perf_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||||
{
|
{
|
||||||
const lv_sysmon_perf_info_t * perf = lv_subject_get_pointer(subject);
|
const lv_sysmon_perf_info_t * perf = lv_subject_get_pointer(subject);
|
||||||
@@ -324,6 +350,24 @@ static void perf_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
|||||||
#endif /*LV_USE_PERF_MONITOR_LOG_MODE*/
|
#endif /*LV_USE_PERF_MONITOR_LOG_MODE*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void perf_control(lv_display_t * disp, bool start)
|
||||||
|
{
|
||||||
|
if(disp == NULL) disp = lv_display_get_default();
|
||||||
|
if(disp == NULL) {
|
||||||
|
LV_LOG_WARN("There is no default display");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(disp->perf_sysmon_backend.timer == NULL) return;
|
||||||
|
|
||||||
|
if(start) {
|
||||||
|
lv_timer_resume(disp->perf_sysmon_backend.timer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lv_timer_pause(disp->perf_sysmon_backend.timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LV_USE_MEM_MONITOR
|
#if LV_USE_MEM_MONITOR
|
||||||
|
|||||||
@@ -60,6 +60,28 @@ void lv_sysmon_show_performance(lv_display_t * disp);
|
|||||||
*/
|
*/
|
||||||
void lv_sysmon_hide_performance(lv_display_t * disp);
|
void lv_sysmon_hide_performance(lv_display_t * disp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dump the FPS data recorded between the last and current dump call.
|
||||||
|
* @param disp target display, NULL: use the default
|
||||||
|
*/
|
||||||
|
void lv_sysmon_performance_dump(lv_display_t * disp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resume the system performance monitor.
|
||||||
|
* @param disp target display, NULL: use the default
|
||||||
|
*/
|
||||||
|
void lv_sysmon_performance_resume(lv_display_t * disp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pause the system performance monitor.
|
||||||
|
*
|
||||||
|
* @param disp target display, NULL: use the default
|
||||||
|
* @note When the sysmon is stopped you can use `lv_sysmon_dump_performance` to
|
||||||
|
* get performance information. See `lv_sysmon_dump_performance` for more information.
|
||||||
|
*/
|
||||||
|
void lv_sysmon_performance_pause(lv_display_t * disp);
|
||||||
|
|
||||||
|
|
||||||
#endif /*LV_USE_PERF_MONITOR*/
|
#endif /*LV_USE_PERF_MONITOR*/
|
||||||
|
|
||||||
#if LV_USE_MEM_MONITOR
|
#if LV_USE_MEM_MONITOR
|
||||||
|
|||||||
Reference in New Issue
Block a user