add thread cpu time for zephyr (#3937)

This commit is contained in:
TianlongLiang 2024-11-28 11:49:55 +08:00 committed by GitHub
parent fd91b51cfb
commit 8698d22e67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View File

@ -14,6 +14,17 @@ os_time_get_boot_us()
uint64
os_time_thread_cputime_us(void)
{
/* FIXME if u know the right api */
return os_time_get_boot_us();
k_tid_t tid;
struct k_thread_runtime_stats stats;
uint32 clock_freq;
uint64 cpu_cycles, time_in_us = 0;
tid = k_current_get();
if (k_thread_runtime_stats_get(tid, &stats) == 0) {
cpu_cycles = stats.execution_cycles;
clock_freq = CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
time_in_us = (cpu_cycles * 1000000) / clock_freq;
}
return time_in_us;
}

View File

@ -5,3 +5,4 @@ CONFIG_STACK_SENTINEL=y
CONFIG_PRINTK=y
CONFIG_LOG=y
CONFIG_LOG_BUFFER_SIZE=4096
CONFIG_THREAD_RUNTIME_STATS=y