This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: timing system calls or other functions


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]