diff options
author | Dave Brolley <brolley@redhat.com> | 2009-10-13 11:55:11 -0400 |
---|---|---|
committer | Dave Brolley <brolley@redhat.com> | 2009-10-13 11:55:11 -0400 |
commit | f990359bd63bd4fc21e600e71c6a513d5b5b2ccb (patch) | |
tree | 16fb7638f2089476b2994ec7d8b2131e4a7b0b69 /tapset/task_time.stp | |
parent | 8f6d8c2bd3e5c1d2881e2ebe1c7ad5deb389e581 (diff) | |
parent | ba9abf303e1bed196668f103b2a17c48e3df70aa (diff) | |
download | systemtap-steved-f990359bd63bd4fc21e600e71c6a513d5b5b2ccb.tar.gz systemtap-steved-f990359bd63bd4fc21e600e71c6a513d5b5b2ccb.tar.xz systemtap-steved-f990359bd63bd4fc21e600e71c6a513d5b5b2ccb.zip |
Merge branch 'master' of ssh://sources.redhat.com/git/systemtap
Diffstat (limited to 'tapset/task_time.stp')
-rw-r--r-- | tapset/task_time.stp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tapset/task_time.stp b/tapset/task_time.stp new file mode 100644 index 00000000..55b7934c --- /dev/null +++ b/tapset/task_time.stp @@ -0,0 +1,101 @@ +// Task time query and utility functions. +// Copyright (C) 2009 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 +// Public License (GPL); either version 2, or (at your option) any +// later version. + +// <tapsetdescription> +// Task time query and utility functions provide information about +// the time resource usage of the current task. These functions provide +// information about the user time and system time of the current +// task. And provide utility functions to turn the reported times +// into miliseconds and create human readable string representations +// of task time used. The reported times are approximates and should +// be used for "coarse grained" measurements only. The reported user +// and system time are only for the current task, not for the process +// as a whole nor of any time spend by children of the current task. +// </tapsetdescription> + +%{ +#include <asm/cputime.h> +#include <linux/time.h> +%} + +/** + * sfunction task_utime - User time of the current task. + * + * Description: Returns the user time of the current task in cputime. + * 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:long () +%{ /* pure */ /* unprivileged */ + THIS->__retvalue = current->utime; +%} + +/** + * sfunction task_stime - System time of the current task. + * + * Description: Returns the system time of the current task in cputime. + * 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:long () +%{ /* pure */ /* unprivileged */ + THIS->__retvalue = current->stime; +%} + +/** + * sfunction cputime_to_msecs - Translates the given cputime into milliseconds. + * @cputime: Time to convert to milliseconds. + */ +function cputime_to_msecs:long (cputime:long) +%{ /* pure */ /* unprivileged */ + THIS->__retvalue = cputime_to_msecs (THIS->cputime); +%} + +/** + * sfunction msecs_to_string - Human readable string for given milliseconds. + * @msecs: Number of milliseconds to translate. + * + * Description: Returns a string representing the number of + * milliseconds as a human readable string consisting of "XmY.ZZZs", + * where X is the number of minutes, Y is the number of seconds and + * ZZZ is the number of milliseconds. + */ +function msecs_to_string:string (msecs:long) +{ + ms = msecs % 1000; + secs = msecs / 1000; + mins = secs / 60; + secs = secs % 60; + return sprintf("%dm%d.%.3ds", mins, secs, ms); +} + +/** + * sfunction cputime_to_string - Human readable string for given cputime. + * @cputime: Time to translate. + * + * Description: Equivalent to calling: + * msec_to_string (cputime_to_msecs (cputime). + */ +function cputime_to_string:string (cputime:long) +{ + return msecs_to_string (cputime_to_msecs (cputime)); +} + +/** + * sfunction task_time_string - Human readable string of task time usage. + * + * Description: Returns a human readable string showing the user and + * system time the current task has used up to now. For example + * "usr: 0m12.908s, sys: 1m6.851s". + */ +function task_time_string:string () +{ + return sprintf ("usr: %s, sys: %s", + cputime_to_string (task_utime()), + cputime_to_string (task_stime())); +} |