fix(profiler_builtin): fix uint32_t storage nanosecond time overflow (#7818)

Signed-off-by: chenjinglin <chenjinglin@xiaomi.com>
This commit is contained in:
Ackerman
2025-02-26 11:57:17 +08:00
committed by GitHub
parent 5764574c9c
commit ec15a45a93
3 changed files with 20 additions and 5 deletions

View File

@@ -72,7 +72,7 @@ static uint64_t tick_get_cb(void)
static uint32_t prev_tick = 0;
static uint64_t cur_tick_ns = 0;
uint32_t act_time = up_perf_gettime();
uint32_t elaps;
uint64_t elaps;
/*If there is no overflow in sys_time simple subtract*/
if(act_time >= prev_tick) {

View File

@@ -241,12 +241,12 @@ static void flush_no_lock(void)
uint32_t tick_per_sec = profiler_ctx->config.tick_per_sec;
while(cur < profiler_ctx->cur_index) {
lv_profiler_builtin_item_t * item = &profiler_ctx->item_arr[cur++];
uint32_t sec = item->tick / tick_per_sec;
uint32_t nsec = (item->tick % tick_per_sec) * (LV_PROFILER_TICK_PER_SEC_MAX / tick_per_sec);
uint64_t sec = item->tick / tick_per_sec;
uint64_t nsec = (item->tick % tick_per_sec) * (LV_PROFILER_TICK_PER_SEC_MAX / tick_per_sec);
#if LV_USE_OS
lv_snprintf(buf, sizeof(buf),
" LVGL-%d [%d] %" LV_PRIu32 ".%09" LV_PRIu32 ": tracing_mark_write: %c|1|%s\n",
" LVGL-%d [%d] %" LV_PRIu64 ".%09" LV_PRIu64 ": tracing_mark_write: %c|1|%s\n",
item->tid,
item->cpu,
sec,
@@ -255,7 +255,7 @@ static void flush_no_lock(void)
item->func);
#else
lv_snprintf(buf, sizeof(buf),
" LVGL-1 [0] %" LV_PRIu32 ".%09" LV_PRIu32 ": tracing_mark_write: %c|1|%s\n",
" LVGL-1 [0] %" LV_PRIu64 ".%09" LV_PRIu64 ": tracing_mark_write: %c|1|%s\n",
sec,
nsec,
item->tag,

View File

@@ -14,11 +14,21 @@
#define LV_PRIu32 PRIu32
#define LV_PRIx32 PRIx32
#define LV_PRIX32 PRIX32
#define LV_PRId64 PRId64
#define LV_PRIu64 PRIu64
#define LV_PRIx64 PRIx64
#define LV_PRIX64 PRIX64
#else
#define LV_PRId32 "d"
#define LV_PRIu32 "u"
#define LV_PRIx32 "x"
#define LV_PRIX32 "X"
#define LV_PRId64 "lld"
#define LV_PRIu64 "llu"
#define LV_PRIx64 "llx"
#define LV_PRIX64 "llX"
#endif
#else
/* hope this is correct for ports without __has_include or without inttypes.h */
@@ -26,6 +36,11 @@
#define LV_PRIu32 "u"
#define LV_PRIx32 "x"
#define LV_PRIX32 "X"
#define LV_PRId64 "lld"
#define LV_PRIu64 "llu"
#define LV_PRIx64 "llx"
#define LV_PRIX64 "llX"
#endif
#include "../misc/lv_types.h"