-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrubytop.stp
67 lines (58 loc) · 1.8 KB
/
rubytop.stp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# yum install systemtap-sdt-devel -y
# CONFIGURE_OPTS="--enable-dtrace" rbenv install 2.1.3
# stap rubytop.stp -DMAXMAPENTRIES=10240 -p4 -m rubytop
# staprun rubytop sort_etime=<0|1> num=<integer> refresh=<integer>
# @ton31337
global calls;
global etimes;
global sort_etime=0;
global num=20;
global refresh=1;
global timer=0;
@define skip(x,y) %( if(isinstr(@x, @y)) next; %)
@define stats %( printf("<%d.%06d> tid:%-8d count:%-8d [%s#%s] %s:%d\n",
(etime / 1000000), (etime % 1000000),
tid, calls[tid, class, method, file, line, etime], class, method, file, line) %)
function print_head()
{
ansi_clear_screen();
printf("Probing...Type CTRL+C to stop probing.\n");
}
function print_stats()
{
if(sort_etime) {
foreach([tid, class, method, file, line, etime-] in calls limit num)
@stats;
} else {
foreach([tid, class, method, file, line, etime] in calls- limit num)
@stats;
}
}
probe process("/opt/rbenv/versions/2.2.2/bin/ruby").mark("method__entry")
{
class = user_string($arg1);
method = user_string($arg2);
@skip(class, "Kernel");
etimes[tid(), class, method] = gettimeofday_us();
}
probe process("/opt/rbenv/versions/2.2.2/bin/ruby").mark("method__return")
{
class = user_string($arg1);
method = user_string($arg2);
file = user_string($arg3);
line = $arg4;
@skip(class, "Kernel");
etime = gettimeofday_us() - etimes[tid(), class, method];
if (!etimes[tid(), class, method])
next;
calls[tid(), class, method, file, line, etime]++;
}
probe timer.s(1) {
if (timer++ % refresh) next;
print_head();
print_stats();
}
probe timer.s(60), end {
delete calls;
delete etimes;
}