| 1 |
#! /usr/bin/env stap |
| 2 |
# |
| 3 |
# Copyright (C) 2018 Red Hat, Inc. |
| 4 |
# By William cohen, Red Hat Inc. |
| 5 |
# [email protected] |
| 6 |
# |
| 7 |
|
| 8 |
global latency = 0 // non-zero to include latency info |
| 9 |
global syscalls = 0 // non-zero to include syscalls |
| 10 |
global tally |
| 11 |
global top = 100000 // High enough limit to be "infinite" |
| 12 |
global entry_time%, acc_time |
| 13 |
|
| 14 |
function method_entry(class:string, method:string) |
| 15 |
{ |
| 16 |
tally[class, method] <<< 1 |
| 17 |
if (latency) { |
| 18 |
entry_time[tid(), class, method] = gettimeofday_us() |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
function method_exit(class:string, method:string) |
| 23 |
{ |
| 24 |
t = entry_time[tid(), class, method] = gettimeofday_us() |
| 25 |
if (t) |
| 26 |
acc_time[class, method] <<< gettimeofday_us() - t |
| 27 |
} |
| 28 |
|
| 29 |
# probes for java |
| 30 |
probe hotspot.method_entry? { |
| 31 |
if (pid() == target()) method_entry(class, name) |
| 32 |
} |
| 33 |
|
| 34 |
probe hotspot.method_return? { |
| 35 |
if (latency && pid() == target()) method_exit(class, name) |
| 36 |
} |
| 37 |
|
| 38 |
# probes for perl |
| 39 |
probe perl.sub.call? { |
| 40 |
if (pid() == target()) method_entry(filename, sub) |
| 41 |
} |
| 42 |
|
| 43 |
probe perl.sub.return? { |
| 44 |
if (latency && pid() == target()) method_exit(filename, sub) |
| 45 |
} |
| 46 |
|
| 47 |
# probes for php |
| 48 |
probe process("php").mark("function__entry")? { |
| 49 |
if (pid() == target()) { |
| 50 |
class = user_string($arg4) |
| 51 |
method = user_string($arg1) |
| 52 |
method_entry(class, method) |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
probe process("php").mark("function__return")? { |
| 57 |
if (latency && pid() == target()) { |
| 58 |
class = user_string($arg4) |
| 59 |
method = user_string($arg1) |
| 60 |
method_exit(class, method) |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
# probes for python |
| 65 |
probe process("/usr/lib*/libpython*.so.1.0").mark("function__entry")? { |
| 66 |
if (pid() == target()) { |
| 67 |
class = user_string($arg1) |
| 68 |
method = user_string($arg2) |
| 69 |
method_entry(class, method) |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
probe process("/usr/lib*/libpython*.so.1.0").mark("function__return")? { |
| 74 |
if (latency && pid() == target()) { |
| 75 |
class = user_string($arg1) |
| 76 |
method = user_string($arg2) |
| 77 |
method_exit(class, method) |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
# probes for ruby |
| 82 |
probe ruby.method.entry? { |
| 83 |
if (pid() == target()) method_entry(classname, methodname) |
| 84 |
} |
| 85 |
|
| 86 |
probe ruby.method.return? { |
| 87 |
if (latency && pid() == target()) method_exit(classname, methodname) |
| 88 |
} |
| 89 |
|
| 90 |
# probes for tcl |
| 91 |
# TODO cmd__entry ? |
| 92 |
probe process("/usr/lib*/libtcl*.so").mark("proc__entry")? { |
| 93 |
if (pid() == target()) { |
| 94 |
method = user_string($arg1) |
| 95 |
method_entry("", method) |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
probe process("/usr/lib*/libtcl*.so").mark("proc__return")? { |
| 100 |
if (latency && pid() == target()) { |
| 101 |
method = user_string($arg1) |
| 102 |
method_exit("", method) |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
probe syscall_any { |
| 107 |
if (syscalls && pid() == target()) method_entry("syscall", name) |
| 108 |
} |
| 109 |
|
| 110 |
probe syscall_any.return { |
| 111 |
if (syscalls && latency && pid() == target()) method_exit("syscall", name) |
| 112 |
} |
| 113 |
|
| 114 |
function print_info() { |
| 115 |
printf("%-50s %8s", "METHOD", "# CALLS") |
| 116 |
if (latency) printf(" %9s", "TIME (us)") |
| 117 |
printf("\n") |
| 118 |
foreach([class, method] in tally- limit top){ |
| 119 |
class_method = sprintf("%s.%s", class, method) |
| 120 |
printf("%-50s %8d", class_method, @sum(tally[class, method])) |
| 121 |
if (latency) printf(" %9d", @sum(acc_time[class, method])) |
| 122 |
printf("\n") |
| 123 |
} |
| 124 |
printf("\n") |
| 125 |
} |
| 126 |
|
| 127 |
probe end |
| 128 |
{ |
| 129 |
print_info() |
| 130 |
delete tally |
| 131 |
delete entry_time |
| 132 |
delete acc_time |
| 133 |
} |
| 134 |
|
| 135 |
probe begin |
| 136 |
{ |
| 137 |
process_cmdline() |
| 138 |
} |
| 139 |
|
| 140 |
/* Handle the "top=<n>", "latency", and "syscall" options */ |
| 141 |
function process_cmdline () |
| 142 |
{ |
| 143 |
for (i=1; i <= argc; i++) { |
| 144 |
argument = tokenize(argv[i], "=") |
| 145 |
|
| 146 |
if ( argument == "top"){ |
| 147 |
top=strtol(tokenize("", "="),10) |
| 148 |
continue; |
| 149 |
} |
| 150 |
|
| 151 |
if ( argument == "latency"){ |
| 152 |
latency = 1 |
| 153 |
continue; |
| 154 |
} |
| 155 |
|
| 156 |
if ( argument == "syscalls"){ |
| 157 |
syscalls = 1 |
| 158 |
continue; |
| 159 |
} |
| 160 |
} |
| 161 |
} |