1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#! /usr/bin/env stap
global command, syscall_count, syscall_times, this_syscall_time, this_syscall
function accumulate () {
tid = tid()
if (! ([tid] in command)) command[tid] = execname()
syscall=pp() # just the substring ideally
syscall_count[tid,syscall] ++
this_syscall[tid] = syscall
this_syscall_time[tid] = gettimeofday_us()
}
function decumulate () {
tid = tid()
syscall = this_syscall[tid]
syscall_times[tid,syscall] += gettimeofday_us() - this_syscall_time[tid]
# free up memory
delete(this_syscall[tid])
delete(this_syscall_time[tid])
}
probe kernel.function("sys_*").call {
accumulate ()
}
probe kernel.function("sys_*").return {
decumulate ()
}
probe timer.ms(5000) {
exit ()
}
probe end {
foreach ([tid,syscall] in syscall_count- limit 30) {
printf("%s(%d) %s count=%d ttime=%d\n", command[tid], tid, syscall,
syscall_count[tid,syscall], syscall_times[tid,syscall])
}
}
|