From 9b06e18aef324786a88a0fbb61dcfdb369586e7f Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 3 Mar 2010 15:05:36 +0100 Subject: Add task_stime_tid(), task_utime_tid() and task_time_string_tid() support. * tapset/task_time.stp: New functions task_stime_tid(), task_utime_tid() and task_time_string_tid(). * testsuite/buildok/task_test.stp: Add tests. --- tapset/task_time.stp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'tapset/task_time.stp') diff --git a/tapset/task_time.stp b/tapset/task_time.stp index 55b7934c..c6af10d0 100644 --- a/tapset/task_time.stp +++ b/tapset/task_time.stp @@ -1,5 +1,5 @@ // Task time query and utility functions. -// Copyright (C) 2009 Red Hat Inc. +// Copyright (C) 2009, 2010 Red Hat Inc. // // This file is part of systemtap, and is free software. You can // redistribute it and/or modify it under the terms of the GNU General @@ -35,6 +35,23 @@ function task_utime:long () THIS->__retvalue = current->utime; %} +/** + * sfunction task_utime - User time of the given task. + * + * Description: Returns the user time of the given task in cputime, + * or zero if the task doesn't exist. + * Does not include any time used by other tasks in this process, nor + * does it include any time of the children of this task. + */ +function task_utime_tid:long(tid:long) +{ + task = pid2task(tid); + if (task != 0) + return @cast(task, "task_struct", "kernel")->utime; + else + return 0; +} + /** * sfunction task_stime - System time of the current task. * @@ -47,6 +64,23 @@ function task_stime:long () THIS->__retvalue = current->stime; %} +/** + * sfunction task_stime_tid - System time of the given task. + * + * Description: Returns the system time of the given task in cputime, + * or zero if the task doesn't exist. + * Does not include any time used by other tasks in this process, nor + * does it include any time of the children of this task. + */ +function task_stime_tid:long(tid:long) +{ + task = pid2task(tid); + if (task != 0) + return @cast(task, "task_struct", "kernel")->stime; + else + return 0; +} + /** * sfunction cputime_to_msecs - Translates the given cputime into milliseconds. * @cputime: Time to convert to milliseconds. @@ -99,3 +133,17 @@ function task_time_string:string () cputime_to_string (task_utime()), cputime_to_string (task_stime())); } + +/** + * sfunction task_time_string_tid - Human readable string of task time usage. + * + * Description: Returns a human readable string showing the user and + * system time the given task has used up to now. For example + * "usr: 0m12.908s, sys: 1m6.851s". + */ +function task_time_string_tid:string (tid:long) +{ + return sprintf ("usr: %s, sys: %s", + cputime_to_string (task_utime_tid(tid)), + cputime_to_string (task_stime_tid(tid))); +} -- cgit