Skip to content

Commit

Permalink
add thread cpu time for zephyr (#3937)
Browse files Browse the repository at this point in the history
  • Loading branch information
TianlongLiang authored Nov 28, 2024
1 parent fd91b51 commit 8698d22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions core/shared/platform/zephyr/zephyr_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions product-mini/platforms/zephyr/simple/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ CONFIG_STACK_SENTINEL=y
CONFIG_PRINTK=y
CONFIG_LOG=y
CONFIG_LOG_BUFFER_SIZE=4096
CONFIG_THREAD_RUNTIME_STATS=y

0 comments on commit 8698d22

Please sign in to comment.