GIF89a;
EcchiShell v1.0
/
/
proc/
self/
root/
usr/
share/
systemtap/
0 ]]; then
exit 1
fi
if [[ $F_EXEC > 0 || $F_PID > 0 || $F_UID > 0 ]]; then
FILTER=1
fi
echo "Creating and building SystemTap module..."
#
# SystemTap script
#
stap $P_VERBOSE_STR -w "$P_PROCESS_STR" -e '
global starttime, timebycall, timebypid, timebyuid, timebyexec
global f_exec_str, f_pid_str, f_uid_str
global f_exec, f_pid, f_uid
global prt_totals, filter_str
probe begin {
printf("Collecting data - type Ctrl-C to print output and exit...\n")
# If no filters specified, skip filter processing
if ('$FILTER' == 0) {
filter_str = " (unfiltered)"
prt_totals = 1 // On by default if no filtering
next
} else
filter_str = " (filtered)"
prt_totals = '$P_TOTALS'
if ('$F_EXEC') f_exec_str = "'$F_EXECSTR'"
if ('$F_PID') f_pid_str = "'$F_PIDSTR'"
if ('$F_UID') f_uid_str = "'$F_UIDSTR'"
delim = "'$DELIM'"
# Process names
if ('$F_EXEC') {
pname = tokenize(f_exec_str, delim)
while (pname != "") {
f_exec[pname] = 1
pname = tokenize("", delim)
}
}
# Process IDs
if ('$F_PID') {
pid = tokenize(f_pid_str, delim)
while (pid != "") {
f_pid[strtol(pid, 10)] = 1
pid = tokenize("", delim)
}
}
# User IDs
if ('$F_UID') {
uid = tokenize(f_uid_str, delim)
while (uid != "") {
f_uid[strtol(uid, 10)] = 1
uid = tokenize("", delim)
}
}
}
probe syscall_any {
starttime[name, tid()] = gettimeofday_ns()
}
probe syscall_any.return {
# Skip if we have not seen this before
if (!([name, tid()] in starttime)) next
delta = gettimeofday_ns() - starttime[name, tid()]
# Check filters
if ('$FILTER') {
target = 0
if (('$F_PID') && (pid() in f_pid)) {
timebypid[name, pid()] <<< delta
target = 1
}
if (('$F_UID') && (uid() in f_uid)) {
timebyuid[name, uid()] <<< delta
target = 1
}
if (('$F_EXEC') && (execname() in f_exec)) {
timebyexec[name, execname()] <<< delta
target = 1
}
} else
target = 1
# Totals
if (target && prt_totals)
timebycall[name] <<< delta
delete starttime[name, tid()]
}
function print_header() {
printf("%22s %10s %12s %12s %12s %12s\n",
"System Call", "Count", "Total ns",
"Avg ns", "Min ns", "Max ns")
}
probe end {
if (prt_totals) {
printf("\nTimes for all processes%s:\n\n", filter_str)
print_header()
foreach (call in timebycall)
printf("%22s %10d %12d %12d %12d %12d\n", call,
@count(timebycall[call]),
@sum(timebycall[call]),
@avg(timebycall[call]),
@min(timebycall[call]),
@max(timebycall[call]))
}
if ('$F_PID') {
curpid = -1
foreach ([call, pid-] in timebypid) {
if (curpid != pid) {
curpid = pid
printf("\nTimes for process ID %d:\n\n", curpid)
print_header()
}
printf("%22s %10d %12d %12d %12d %12d\n", call,
@count(timebypid[call, pid]),
@sum(timebypid[call, pid]),
@avg(timebypid[call, pid]),
@min(timebypid[call, pid]),
@max(timebypid[call, pid]))
}
printf("\n")
}
if ('$F_EXEC') {
curexec = ""
foreach ([call, exec-] in timebyexec) {
if (curexec != exec) {
curexec = exec
printf("\nTimes for process name %s:\n\n", curexec)
print_header()
}
printf("%22s %10d %12d %12d %12d %12d\n", call,
@count(timebyexec[call, exec]),
@sum(timebyexec[call, exec]),
@avg(timebyexec[call, exec]),
@min(timebyexec[call, exec]),
@max(timebyexec[call, exec]))
}
printf("\n")
}
if ('$F_UID') {
curuid = -1
foreach ([call, uid-] in timebyuid) {
if (curuid != uid) {
curuid = uid
printf("\nTimes for user ID %d:\n\n", curuid)
print_header()
}
printf("%22s %10d %12d %12d %12d %12d\n", call,
@count(timebyuid[call, uid]),
@sum(timebyuid[call, uid]),
@avg(timebyuid[call, uid]),
@min(timebyuid[call, uid]),
@max(timebyuid[call, uid]))
}
printf("\n")
}
delete timebycall
if ('$F_PID') delete timebypid
if ('$F_UID') delete timebyuid
if ('$F_EXEC') delete timebyexec
}'