| 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 amount of time spent in the nanosleep and compat_nanosleep |
| 14 |
* systemcalls. This can help find which processes are waking based on time |
| 15 |
* rather than some real event than needs to be handled. |
| 16 |
* |
| 17 |
* Format is: |
| 18 |
* 12799538 3389 (xchat) nanosleep: 9547 |
| 19 |
* 12846944 2805 (NetworkManager) nanosleep: 100964 |
| 20 |
* 12947924 2805 (NetworkManager) nanosleep: 100946 |
| 21 |
* 13002925 4757 (sleep) nanosleep: 13000717 |
| 22 |
*/ |
| 23 |
|
| 24 |
global start |
| 25 |
global entry_nanosleep |
| 26 |
|
| 27 |
function timestamp:long() { |
| 28 |
return gettimeofday_us() - start |
| 29 |
} |
| 30 |
|
| 31 |
function proc:string() { |
| 32 |
return sprintf("%d (%s)", pid(), execname()) |
| 33 |
} |
| 34 |
|
| 35 |
probe begin { |
| 36 |
start = gettimeofday_us() |
| 37 |
} |
| 38 |
|
| 39 |
probe syscall.nanosleep, |
| 40 |
syscall.clock_nanosleep ?, |
| 41 |
syscall.compat_nanosleep ? |
| 42 |
{ |
| 43 |
t = gettimeofday_us(); p = pid() |
| 44 |
entry_nanosleep[p] = t |
| 45 |
} |
| 46 |
|
| 47 |
probe syscall.nanosleep.return, |
| 48 |
syscall.clock_nanosleep.return ?, |
| 49 |
syscall.compat_nanosleep.return ? |
| 50 |
{ |
| 51 |
if (pid() in entry_nanosleep) { |
| 52 |
elapsed_time = gettimeofday_us() - entry_nanosleep[pid()] |
| 53 |
printf("%d %s %s: %d\n", timestamp(), proc(), name, elapsed_time) |
| 54 |
} |
| 55 |
} |