Show CPU usage and FPS count

Has anyone used “#define LV_USE_PERF_MONITOR 1” in micropython?
In my project, both FPS and CPU are displayed, but they don’t change when I click buttons or switch tabs. They both show 33FPS 0%CPU.

Hi @Meekdai

Please provide more information about what you are running, on which platform, which display driver, how you configured the event loop, etc.

It sounds like you are not using the event loop correctly. The event loop should be calling lv.tick_inc which is essential for time measurement.


Hi @amirgon
I use STM32F412VGT6 with ST7789 build myself, and it works well(button/spinbox,etc).
I call lv.tick_inc as follows:

from lv_utils import event_loop
event_loop = event_loop(asynchronous=True)

LVGL tick_inc step by self.delay = 1000 // freq

I found that busy_time in the source code is always 0, the reason may be that the update of tick_inc is too slow.

I can confirm that today by default FPS and CPU don’t seem reliable on lv_micropython.
I’m also getting “33FPS 0%CPU” on both unix port and ESP32 port, regardless of what happens on screen.

This is probably because both “task_handler” and “tick_inc” are triggered from the same timer callback on lv_utils. This is a single threaded application with a single timer interrupt, so in cases of performance bottlenecks timer update is delayed in exactly the same amount of microseconds as task_handler.

To get better measurements we should use an independant timer for accurate and reliable time readings.

You can do that by defining LV_TICK_CUSTOM to 1:

Here is my configuration for ESP32, for example:

#define LV_TICK_CUSTOM 1
    int64_t esp_timer_get_time(void);
    #define LV_TICK_CUSTOM_INCLUDE "stddef.h"         /*Header for the system time function*/
    #define LV_TICK_CUSTOM_SYS_TIME_EXPR (esp_timer_get_time() / 1000)    /*Expression evaluating to current system time in ms*/
#endif   /*LV_TICK_CUSTOM*/

(you should also remove calls to tick_inc in, because it is no longer available once LV_TICK_CUSTOM is enabled)

With this change I’m getting reliable readings for FPS and CPU on ESP32!

FPS is also bound by LV_DISP_DEF_REFR_PERIOD (but can also be configured by the display driver).
The default value of 30 for LV_DISP_DEF_REFR_PERIOD limits maximum FPS to 33 FPS. Setting lower values can provide higher FPS at the expense of CPU utilization.

Hi @amirgon
Following your way, I modified the code and I now successfully see the FPS and CPU working correctly.The following code is the modification I made on STM32.

#define LV_TICK_CUSTOM 1
    #define LV_TICK_CUSTOM_INCLUDE "stm32f4xx_hal.h"         /*Header for the system time function*/
    #define LV_TICK_CUSTOM_SYS_TIME_EXPR (HAL_GetTick())    /*Expression evaluating to current system time in ms*/
#endif   /*LV_TICK_CUSTOM*/