summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.examples/profiling/fntimes.stp
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/systemtap.examples/profiling/fntimes.stp')
-rwxr-xr-xtestsuite/systemtap.examples/profiling/fntimes.stp30
1 files changed, 30 insertions, 0 deletions
diff --git a/testsuite/systemtap.examples/profiling/fntimes.stp b/testsuite/systemtap.examples/profiling/fntimes.stp
new file mode 100755
index 00000000..e9daac77
--- /dev/null
+++ b/testsuite/systemtap.examples/profiling/fntimes.stp
@@ -0,0 +1,30 @@
+#! /usr/bin/stap
+
+# usage: fntimes.stp FUNCTIONPROBE
+# e.g. fntimes.stp 'module("ext4").function("*")'
+
+global mincount = 100 # training: beneath this number of hits, only collect data
+global note_percent = 250 # percent beyond maximum-so-far to generate report for
+function time() { return gettimeofday_us() } # time measurement function
+
+global times, entry
+
+probe $1.call {
+ entry[probefunc(),tid()] = time()
+}
+
+probe $1.return {
+ pf=probefunc()
+ tid=tid()
+ if ([pf,tid] in entry) { # seen function entry?
+ t = time()-entry[pf,tid] # t: elapsed time
+ delete entry[pf,tid]
+ if (@count(times[pf]) >= mincount
+ && t >= @max(times[pf]) * note_percent / 100) { # also consider @avg()
+ printf("function %s well over %s time (%d vs %d)\n",
+ pf, "maximum", t, @max(times[pf]))
+ # also consider: print_backtrace()
+ }
+ times[pf] <<< t # (increments @count, updates @max)
+ }
+}