feat(nuttx_profiler): support trace to file (#8674)

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng
2025-08-16 04:09:14 +08:00
committed by GitHub
parent 5b63483236
commit 807d847123
7 changed files with 89 additions and 0 deletions
+11
View File
@@ -2056,6 +2056,17 @@ menu "LVGL configuration"
help
Set the step size of the mouse movement in pixels.
config LV_USE_NUTTX_TRACE_FILE
bool "Use NuttX trace file"
depends on LV_USE_NUTTX
depends on LV_USE_PROFILER_BUILTIN
default n
config LV_NUTTX_TRACE_FILE_PATH
depends on LV_USE_NUTTX_TRACE_FILE
string "NuttX trace file path"
default "/data/lvgl-trace.log"
config LV_USE_LINUX_DRM
bool "Use Linux DRM device"
default n
+7
View File
@@ -1271,6 +1271,13 @@
/** Mouse movement step (pixels) */
#define LV_USE_NUTTX_MOUSE_MOVE_STEP 1
/*NuttX trace file and its path*/
#define LV_USE_NUTTX_TRACE_FILE 0
#if LV_USE_NUTTX_TRACE_FILE
#define LV_NUTTX_TRACE_FILE_PATH "/data/lvgl-trace.log"
#endif
#endif
/** Driver for /dev/dri/card */
+10
View File
@@ -111,6 +111,10 @@ void lv_nuttx_dsc_init(lv_nuttx_dsc_t * dsc)
#if LV_USE_NUTTX_MOUSE
dsc->mouse_path = "/dev/mouse0";
#endif
#if LV_USE_NUTTX_TRACE_FILE
dsc->trace_path = LV_NUTTX_TRACE_FILE_PATH;
#endif
}
void lv_nuttx_init(const lv_nuttx_dsc_t * dsc, lv_nuttx_result_t * result)
@@ -131,6 +135,9 @@ void lv_nuttx_init(const lv_nuttx_dsc_t * dsc, lv_nuttx_result_t * result)
#if LV_USE_PROFILER && LV_USE_PROFILER_BUILTIN
lv_nuttx_profiler_init();
#if LV_USE_NUTTX_TRACE_FILE
lv_nuttx_profiler_set_file(dsc->trace_path);
#endif
#endif
if(result) {
@@ -254,6 +261,9 @@ void lv_nuttx_deinit(lv_nuttx_result_t * result)
lv_nuttx_cache_deinit();
lv_nuttx_image_cache_deinit();
#if LV_USE_PROFILER && LV_USE_PROFILER_BUILTIN
lv_nuttx_profiler_deinit();
#endif
lv_free(nuttx_ctx_p);
nuttx_ctx_p = NULL;
}
+2
View File
@@ -36,6 +36,7 @@ typedef struct {
const char * input_path;
const char * utouch_path;
const char * mouse_path;
const char * trace_path;
} lv_nuttx_dsc_t;
typedef struct {
@@ -47,6 +48,7 @@ typedef struct {
typedef struct _lv_nuttx_ctx_t {
void * image_cache;
int trace_fd;
} lv_nuttx_ctx_t;
/**********************
+38
View File
@@ -13,12 +13,15 @@
#if LV_USE_NUTTX && LV_USE_PROFILER && LV_USE_PROFILER_BUILTIN
#include <nuttx/arch.h>
#include <fcntl.h>
#include <stdio.h>
/*********************
* DEFINES
*********************/
#define trace_fd (LV_GLOBAL_DEFAULT()->nuttx_ctx->trace_fd)
#define TICK_TO_NSEC(tick) ((tick) * 1000 / cpu_freq)
/**********************
@@ -55,6 +58,10 @@ void lv_nuttx_profiler_init(void)
}
LV_LOG_USER("CPU frequency: %" LV_PRIu32 " MHz", cpu_freq);
#if LV_USE_NUTTX_TRACE_FILE
trace_fd = -1;
#endif
lv_profiler_builtin_config_t config;
lv_profiler_builtin_config_init(&config);
config.tick_per_sec = 1000000000; /* 1 sec = 1000000000 nsec */
@@ -63,6 +70,31 @@ void lv_nuttx_profiler_init(void)
lv_profiler_builtin_init(&config);
}
void lv_nuttx_profiler_set_file(const char * file)
{
#if LV_USE_NUTTX_TRACE_FILE
if(trace_fd >= 0) {
close(trace_fd);
}
trace_fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if(trace_fd < 0) {
LV_LOG_ERROR("Failed to open trace file %s, error: %d", file, errno);
}
#endif
}
void lv_nuttx_profiler_deinit(void)
{
lv_profiler_builtin_uninit();
#if LV_USE_NUTTX_TRACE_FILE
if(trace_fd >= 0) {
close(trace_fd);
}
trace_fd = -1;
#endif
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -90,6 +122,12 @@ static uint64_t tick_get_cb(void)
static void flush_cb(const char * buf)
{
#if LV_USE_NUTTX_TRACE_FILE
if(trace_fd >= 0) {
write(trace_fd, buf, strlen(buf));
return;
}
#endif
printf("%s", buf);
}
+2
View File
@@ -27,6 +27,8 @@ extern "C" {
**********************/
void lv_nuttx_profiler_init(void);
void lv_nuttx_profiler_set_file(const char * file);
void lv_nuttx_profiler_deinit(void);
/**********************
* MACROS
+19
View File
@@ -4116,6 +4116,25 @@
#define LV_USE_NUTTX_MOUSE_MOVE_STEP 1
#endif
#endif
/*NuttX trace file and its path*/
#ifndef LV_USE_NUTTX_TRACE_FILE
#ifdef CONFIG_LV_USE_NUTTX_TRACE_FILE
#define LV_USE_NUTTX_TRACE_FILE CONFIG_LV_USE_NUTTX_TRACE_FILE
#else
#define LV_USE_NUTTX_TRACE_FILE 0
#endif
#endif
#if LV_USE_NUTTX_TRACE_FILE
#ifndef LV_NUTTX_TRACE_FILE_PATH
#ifdef CONFIG_LV_NUTTX_TRACE_FILE_PATH
#define LV_NUTTX_TRACE_FILE_PATH CONFIG_LV_NUTTX_TRACE_FILE_PATH
#else
#define LV_NUTTX_TRACE_FILE_PATH "/data/lvgl-trace.log"
#endif
#endif
#endif
#endif
/** Driver for /dev/dri/card */