procfs: add total time running time of task

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2023-04-20 16:45:14 +08:00 committed by Xiang Xiao
parent 3d3a86ae53
commit c418d147fe
3 changed files with 12 additions and 3 deletions

View File

@ -762,6 +762,7 @@ static ssize_t proc_critmon(FAR struct proc_file_s *procfile,
size_t buflen, off_t offset) size_t buflen, off_t offset)
{ {
struct timespec maxtime; struct timespec maxtime;
struct timespec runtime;
size_t remaining; size_t remaining;
size_t linesize; size_t linesize;
size_t copysize; size_t copysize;
@ -851,12 +852,18 @@ static ssize_t proc_critmon(FAR struct proc_file_s *procfile,
/* Reset the maximum */ /* Reset the maximum */
tcb->run_max = 0; 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_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, copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
&offset); &offset);

View File

@ -639,6 +639,7 @@ struct tcb_s
unsigned long crit_max; /* Max time in critical section */ unsigned long crit_max; /* Max time in critical section */
unsigned long run_start; /* Time when thread begin run */ unsigned long run_start; /* Time when thread begin run */
unsigned long run_max; /* Max time thread run */ unsigned long run_max; /* Max time thread run */
unsigned long run_time; /* Total time thread run */
#endif #endif
/* State save areas *******************************************************/ /* State save areas *******************************************************/

View File

@ -297,6 +297,7 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb)
unsigned long current = up_perf_gettime(); unsigned long current = up_perf_gettime();
unsigned long elapsed = current - tcb->run_start; unsigned long elapsed = current - tcb->run_start;
tcb->run_time += elapsed;
if (elapsed > tcb->run_max) if (elapsed > tcb->run_max)
{ {
tcb->run_max = elapsed; tcb->run_max = elapsed;