| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
/* |
| 4 |
* Copyright (C) 2006-2007 Red Hat Inc. |
| 5 |
* |
| 6 |
* This copyrighted material is made available to anyone wishing to use, |
| 7 |
* modify, copy, or redistribute it subject to the terms and conditions |
| 8 |
* of the GNU General Public License v.2. |
| 9 |
* |
| 10 |
* You should have received a copy of the GNU General Public License |
| 11 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 12 |
* |
| 13 |
* Print out the time spent in wait4 systemcall |
| 14 |
* |
| 15 |
* Format is: |
| 16 |
* timestamp pid (executabable) wait4: time_us pid |
| 17 |
* |
| 18 |
* 155789807 4196 (ssh) wait4: 12 4197 |
| 19 |
* 158270531 3215 (bash) wait4: 5410460 -1 |
| 20 |
* 158270659 3215 (bash) wait4: 9 -1 |
| 21 |
* 158557461 2614 (sendmail) wait4: 27 -1 |
| 22 |
* 158557487 2614 (sendmail) wait4: 5 -1 |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
global start |
| 27 |
global wait4_pid |
| 28 |
|
| 29 |
function timestamp:long() { |
| 30 |
return gettimeofday_us() - start |
| 31 |
} |
| 32 |
|
| 33 |
function proc:string() { |
| 34 |
return sprintf("%d (%s)", pid(), execname()) |
| 35 |
} |
| 36 |
|
| 37 |
probe begin { |
| 38 |
start = gettimeofday_us() |
| 39 |
} |
| 40 |
|
| 41 |
probe syscall.wait4 { |
| 42 |
// It would be nice to use @entry here, but "pid" has a non-trivial |
| 43 |
// expression in the tapset which we probably shouldn't duplicate. |
| 44 |
wait4_pid[tid()]=pid |
| 45 |
} |
| 46 |
|
| 47 |
probe syscall.wait4.return { |
| 48 |
elapsed_time = gettimeofday_us() - @entry(gettimeofday_us()) |
| 49 |
printf("%d %s wait4: %d %d\n", timestamp(), proc(), elapsed_time, |
| 50 |
wait4_pid[tid()]) |
| 51 |
delete wait4_pid[tid()] |
| 52 |
} |