public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mjw@redhat.com>
To: systemtap@sourceware.org
Subject: task time tapset
Date: Fri, 09 Oct 2009 15:18:00 -0000	[thread overview]
Message-ID: <1255101479.3357.92.camel@springer.wildebeest.org> (raw)
In-Reply-To: <1254755216.26675.30.camel@springer.wildebeest.org>

[-- Attachment #1: Type: text/plain, Size: 2033 bytes --]

Hi,

As an addition to the proc_mem tapset I created a task_time tapset. Like
the process memory tapset it only works on the current task. But that
makes it really trivial to implement. I think it would be a nice
addition since it allows you to do these "pass based statistics" fully
dynamically (and they would of course also work with function probes, or
any other probe that targets user processes).

To extend the previous example, you can now almost completely mimic to
stap -v output:
$ stap -e 'probe process("stap").mark("pass[0-3]*end")
  { log($$name . "\t" . proc_mem_string() . "\n\t\t" . task_time_string()) }'
  -c 'stap -w -k -p4 testsuite/buildok/syscall.stp'

pass0__end  size: 55.9M, rss: 2.62M, shr: 1.93M, txt: 1.34M, data: 1.01M
            usr: 0m0.002s, sys: 0m0.003s
pass1__end  size: 72.5M, rss: 19.1M, shr: 2.23M, txt: 1.34M, data: 17.6M
            usr: 0m0.103s, sys: 0m0.016s
pass2__end  size:  167M, rss: 96.5M, shr: 42.9M, txt: 1.34M, data: 54.4M
            usr: 0m2.102s, sys: 0m0.035s
pass3__end  size:  167M, rss: 96.6M, shr: 43.0M, txt: 1.34M, data: 54.4M
            usr: 0m2.354s, sys: 0m0.048s

These are total user and system times. It doesn't include real time atm.
In theory this can be gotten. The task struct keeps the start time. But
this is in monotonic or boot time and we currently only have daytime. It
shouldn't be too hard to add that, but I didn't want to do that atm.
Recent kernels export a per cpu_clock() (based on sched_clock) that
might be helpful.

It also doesn't do anything fancy like the task.stp tapset that also
works for tasks that aren't current. Again it shouldn't be too hard to
extend it to also make it do that, task.stp shows how the locking should
work. But I didn't really saw the complexity being worth it.

Again these functions are marked unprivileged since the same info can be
gotten from proc/pid/tasks/* already.

Tested against 2.6.18 and 2.6.31.1 on x86_64, tests on other kernels and
architectures or any other feedback very welcome.

Cheers,

Mark

[-- Attachment #2: task_time.stp --]
[-- Type: text/x-csrc, Size: 3340 bytes --]

// 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()));
}

  parent reply	other threads:[~2009-10-09 15:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-05 15:07 proc memory statistics tapset Mark Wielaard
2009-10-05 18:09 ` Josh Stone
2009-10-06 17:26   ` Mark Wielaard
2009-10-06 23:39     ` Josh Stone
2009-10-09 12:54       ` Mark Wielaard
2009-10-09 17:26         ` Josh Stone
2009-10-09 15:18 ` Mark Wielaard [this message]
2009-10-09 22:53   ` task time tapset Josh Stone
2009-10-10  9:12     ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1255101479.3357.92.camel@springer.wildebeest.org \
    --to=mjw@redhat.com \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).