From c418d147fec475f08cb0e3fe8f1929d5d43ad356 Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Thu, 20 Apr 2023 16:45:14 +0800 Subject: [PATCH] procfs: add total time running time of task Signed-off-by: yinshengkai --- fs/procfs/fs_procfsproc.c | 13 ++++++++++--- include/nuttx/sched.h | 1 + sched/sched/sched_critmonitor.c | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 39d3f76702..10056341d9 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -762,6 +762,7 @@ static ssize_t proc_critmon(FAR struct proc_file_s *procfile, size_t buflen, off_t offset) { struct timespec maxtime; + struct timespec runtime; size_t remaining; size_t linesize; size_t copysize; @@ -851,12 +852,18 @@ static ssize_t proc_critmon(FAR struct proc_file_s *procfile, /* Reset the maximum */ tcb->run_max = 0; + up_perf_convert(tcb->run_time, &runtime); - /* Generate output for maximum time thread running */ + /* Output the maximum time the thread has run and + * the total time the thread has run + */ - linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%lu.%09lu\n", + linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, + "%lu.%09lu,%lu.%09lu\n", (unsigned long)maxtime.tv_sec, - (unsigned long)maxtime.tv_nsec); + (unsigned long)maxtime.tv_nsec, + (unsigned long)runtime.tv_sec, + (unsigned long)(runtime.tv_nsec)); copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, &offset); diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 8cd49978da..1a163f6ac5 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -639,6 +639,7 @@ struct tcb_s unsigned long crit_max; /* Max time in critical section */ unsigned long run_start; /* Time when thread begin run */ unsigned long run_max; /* Max time thread run */ + unsigned long run_time; /* Total time thread run */ #endif /* State save areas *******************************************************/ diff --git a/sched/sched/sched_critmonitor.c b/sched/sched/sched_critmonitor.c index 6425dfbb80..293e0a4b3e 100644 --- a/sched/sched/sched_critmonitor.c +++ b/sched/sched/sched_critmonitor.c @@ -297,6 +297,7 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb) unsigned long current = up_perf_gettime(); unsigned long elapsed = current - tcb->run_start; + tcb->run_time += elapsed; if (elapsed > tcb->run_max) { tcb->run_max = elapsed;