public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] taskstats: Add e/u/stime for TGID command
@ 2017-03-03  2:33 Zhang Xiao
  2017-03-06 22:40 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Zhang Xiao @ 2017-03-03  2:33 UTC (permalink / raw)
  To: bsingharora; +Cc: linux-kernel, xiao.zhang

Add elapsed time, user CPU time and system CPU time to
thread group status request.

Signed-off-by: Zhang Xiao <xiao.zhang@windriver.com>
---
 kernel/taskstats.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index 8a5e442..802a2bb 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -210,6 +210,7 @@ static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats)
 	struct task_struct *tsk, *first;
 	unsigned long flags;
 	int rc = -ESRCH;
+	u64 delta, utime, stime;
 
 	/*
 	 * Add additional stats from live tasks except zombie thread group
@@ -238,6 +239,16 @@ static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats)
 		 */
 		delayacct_add_tsk(stats, tsk);
 
+		/* calculate task elapsed time in nsec */
+		delta = ktime_get_ns() - tsk->start_time;
+		/* Convert to micro seconds */
+		do_div(delta, NSEC_PER_USEC);
+		stats->ac_etime += delta;
+
+		task_cputime(tsk, &utime, &stime);
+		stats->ac_utime += div_u64(utime, NSEC_PER_USEC);
+		stats->ac_stime += div_u64(stime, NSEC_PER_USEC);
+
 		stats->nvcsw += tsk->nvcsw;
 		stats->nivcsw += tsk->nivcsw;
 	} while_each_thread(first, tsk);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-07 20:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-03  2:33 [PATCH] taskstats: Add e/u/stime for TGID command Zhang Xiao
2017-03-06 22:40 ` Andrew Morton
2017-03-07  1:12   ` ZhangXiao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox