This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: timing system calls or other functions
- From: PrzemysÅaw PaweÅczyk <przemyslaw at pawelczyk dot it>
- To: Ivan Novick <novickivan at gmail dot com>
- Cc: systemtap at sources dot redhat dot com
- Date: Tue, 12 Jan 2010 02:09:43 +0100
- Subject: Re: timing system calls or other functions
- References: <619ad6271001111609r6af6760crfc580df0d9dc0470@mail.gmail.com>
On Tue, Jan 12, 2010 at 01:09, Ivan Novick <novickivan@gmail.com> wrote:
> Is there a way to write an if statement that checks for the presence
> of a key in an associative array? ÂThan the solution would seem
> straightforward.
Yes, ([key1, key2, ...] in array)
> The other question is regarding multi-threading. ÂPresumably the same
> system call can be made from the same process multiple times before
> exiting, so my associate array should probably be keyed on pid, tid,
> and syscall name. ÂCorrect?
Tid is system-wide unique, so pid is useless here. Tid and syscall
name are sufficient as a key for begin timestamp, but only the last
one per syscall. If you want to aggregate these times, you have to use
another associative array with key = syscall name and add there your
timestamp subtraction results via <<< operator.
Look at my script below (it's not exactly what you're looking for, but
it's close and should be helpful):
#!/usr/bin/env stap
# strace-only-stats-set.stp
# Copyright (C) 2009 Przemyslaw Pawelczyk <przemyslaw@pawelczyk.it>
#
# ./strace-only-stats-set.stp -c '<tracee>'
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
global starttime[65536], stats, tstats
probe syscall.* {
if (target_set_pid(pid())) {
starttime[name, tid()] = gettimeofday_us()
}
}
probe syscall.*.return {
if (target_set_pid(pid()) && ([name, tid()] in starttime)) {
delta = gettimeofday_us() - starttime[name, tid()]
stats[name] <<< delta
tstats <<< delta
delete starttime[name, tid()]
}
}
probe end {
printf("\n%11s %11s %9s %-16s\n", "useconds", "usecs/call", "calls", "syscall")
printf("%11s %11s %9s %-16s\n", "-----------", "-----------",
"---------", "----------------")
n = 0 # different calls counter
foreach (call in stats) {
printf("%11d %11d %9d %-16s\n",
@sum(stats[call]),
@avg(stats[call]),
@count(stats[call]),
call)
n++
}
printf("%11s %11s %9s %-16s\n", "-----------", "-----------",
"---------", "----------------")
printf("%11d %11d %9d %s (%d)\n", @sum(tstats), @avg(tstats),
@count(tstats), "total", n)
delete stats
delete tstats
}
Regards.
--
PrzemysÅaw PaweÅczyk