mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
feat(freertos): add functions to better measure the CPU usage (#6619)
This commit is contained in:
parent
b78a4de898
commit
f8e0932316
@ -222,6 +222,14 @@ typedef struct lv_global_t {
|
|||||||
lv_mutex_t lv_general_mutex;
|
lv_mutex_t lv_general_mutex;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LV_USE_OS == LV_OS_FREERTOS
|
||||||
|
uint32_t freertos_idle_time_sum;
|
||||||
|
uint32_t freertos_non_idle_time_sum;
|
||||||
|
uint32_t freertos_task_switch_timestamp;
|
||||||
|
bool freertos_idle_task_running;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void * user_data;
|
void * user_data;
|
||||||
} lv_global_t;
|
} lv_global_t;
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include "lv_os.h"
|
#include "lv_os.h"
|
||||||
|
|
||||||
#if LV_USE_OS == LV_OS_FREERTOS
|
#if LV_USE_OS == LV_OS_FREERTOS
|
||||||
|
|
||||||
#if (ESP_PLATFORM)
|
#if (ESP_PLATFORM)
|
||||||
@ -22,7 +21,10 @@
|
|||||||
#include "atomic.h"
|
#include "atomic.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "../tick/lv_tick.h"
|
||||||
#include "../misc/lv_log.h"
|
#include "../misc/lv_log.h"
|
||||||
|
#include "../core/lv_global.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
@ -32,6 +34,8 @@
|
|||||||
#define pcTASK_NAME "lvglDraw"
|
#define pcTASK_NAME "lvglDraw"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define globals LV_GLOBAL_DEFAULT()
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
**********************/
|
**********************/
|
||||||
@ -348,6 +352,38 @@ lv_result_t lv_thread_sync_signal_isr(lv_thread_sync_t * pxCond)
|
|||||||
return LV_RESULT_OK;
|
return LV_RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void lv_freertos_task_switch_in(const char * name)
|
||||||
|
{
|
||||||
|
if(lv_strcmp(name, "IDLE")) globals->freertos_idle_task_running = false;
|
||||||
|
else globals->freertos_idle_task_running = true;
|
||||||
|
|
||||||
|
globals->freertos_task_switch_timestamp = lv_tick_get();
|
||||||
|
}
|
||||||
|
|
||||||
|
void lv_freertos_task_switch_out(void)
|
||||||
|
{
|
||||||
|
uint32_t elaps = lv_tick_elaps(globals->freertos_task_switch_timestamp);
|
||||||
|
if(globals->freertos_idle_task_running) globals->freertos_idle_time_sum += elaps;
|
||||||
|
else globals->freertos_non_idle_time_sum += elaps;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t lv_os_get_idle_percent(void)
|
||||||
|
{
|
||||||
|
if(globals->freertos_non_idle_time_sum + globals->freertos_idle_time_sum == 0) {
|
||||||
|
LV_LOG_WARN("Not enough time elapsed to provide idle percentage");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t pct = (globals->freertos_idle_time_sum * 100) / (globals->freertos_idle_time_sum +
|
||||||
|
globals->freertos_non_idle_time_sum);
|
||||||
|
|
||||||
|
globals->freertos_non_idle_time_sum = 0;
|
||||||
|
globals->freertos_idle_time_sum = 0;
|
||||||
|
|
||||||
|
return pct;
|
||||||
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
@ -77,6 +77,29 @@ typedef struct {
|
|||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set it for `traceTASK_SWITCHED_IN()` as
|
||||||
|
* `lv_freertos_task_switch_in(pxCurrentTCB->pcTaskName)`
|
||||||
|
* to save the start time stamp of a task
|
||||||
|
* @param name the name of the which is switched in
|
||||||
|
*/
|
||||||
|
void lv_freertos_task_switch_in(const char * name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set it for `traceTASK_SWITCHED_OUT()` as
|
||||||
|
* `lv_freertos_task_switch_out()`
|
||||||
|
* to save finish time stamp of a task
|
||||||
|
*/
|
||||||
|
void lv_freertos_task_switch_out(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set it for `LV_SYSMON_GET_IDLE` to show the CPU usage
|
||||||
|
* as reported based the usage of FreeRTOS's idle task
|
||||||
|
* If it's important when a GPU is used.
|
||||||
|
* @return the idle percentage since the last call
|
||||||
|
*/
|
||||||
|
uint32_t lv_os_get_idle_percent(void);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
**********************/
|
**********************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user