From 7f79ea13a0f64573ce13353257d322ae49ef0c27 Mon Sep 17 00:00:00 2001 From: William Cohen Date: Thu, 24 Apr 2008 12:20:13 -0400 Subject: Move examples to testsuite/systemtap.examples --- testsuite/systemtap.examples/small_demos/prof.stp | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 testsuite/systemtap.examples/small_demos/prof.stp (limited to 'testsuite/systemtap.examples/small_demos/prof.stp') diff --git a/testsuite/systemtap.examples/small_demos/prof.stp b/testsuite/systemtap.examples/small_demos/prof.stp new file mode 100755 index 00000000..389f743a --- /dev/null +++ b/testsuite/systemtap.examples/small_demos/prof.stp @@ -0,0 +1,35 @@ +#!/usr/bin/env stap + +# This is an example of profiling a specific command or pid. +# It works by recording the time when a system call is entered +# exited. + +# Usage: prof.stp -c "top -n5" +# Will start up "top" and after 5 iterations, will exit. +# +# Usage: prof.stp -x 3323 +# Will profile pid 3323 until it ^c is hit. +# + +probe kernel.function("sys_*").call { + if (target() == tid()) + calltime[tid()] = gettimeofday_us() +} + +probe kernel.function("sys_*").return { + if (target() != tid()) next + now = gettimeofday_us() + c = calltime[tid()] + if (!c) next + ttime[probefunc()] <<< now - c + delete calltime[tid()] +} + +probe end { + printf("\n") + foreach (x in ttime) + printf("%-20s\tcalls:%6d\tavg time (us):%5d\ttotal(us):%7d\n", + x, @count(ttime[x]), @avg(ttime[x]), @sum(ttime[x])) +} + +global calltime, ttime -- cgit