This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Controlling a systemtap script from userspace
- From: David A Sperry <David_A_Sperry at raytheon dot com>
- To: systemtap at sources dot redhat dot com
- Date: Tue, 9 Jan 2007 17:12:54 -0500
- Subject: Controlling a systemtap script from userspace
Hi,
I am interested in logging kernel stuff only during small
portions of a long test. About 10 milliseconds of logging every
10 minutes. I have a C++ program than knows when to do the
logging, the question is how to get that user space C++ program to set a
global in a systemTap script? Is there an obscure syscall
or something else I can use as a probe to set a global?
For example:
#!/usr/bin/env stap
#
# This script sporatically lists the top 20 systemcalls on the system
#
global syscalls isLogging
# turn on logging
probe ### something from user space ### {isLogging = 1}
# turn off logging
probe ### something else from user space #### {isLogging = 0}
# probe gated with isLogging
probe kernel.function("sys_*") {
if (isLogging == 1) {
syscalls[probefunc()]++
}
}
# print top syscalls every 5 seconds
probe timer.ms(5000) {
print_top ()
}
function print_top () {
cnt=0
printf ("SYSCALL\t\t\t\tCOUNT\n")
foreach ([name] in syscalls-) {
printf("%-20s\t\t%5d\n",name, syscalls[name])
if (cnt++ == 20)
break
}
printf("--------------------------------------\n")
delete syscalls
}