| 1 |
#! /usr/bin/env stap |
| 2 |
# traceio.stp |
| 3 |
# Copyright (C) 2007-2018 Red Hat, Inc., Eugene Teo <[email protected]> |
| 4 |
# Copyright (C) 2009 Kai Meyer <[email protected]> |
| 5 |
# Fixed a bug that allows this to run longer |
| 6 |
# And added the humanreadable function |
| 7 |
# |
| 8 |
# This program is free software; you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License version 2 as |
| 10 |
# published by the Free Software Foundation. |
| 11 |
# |
| 12 |
|
| 13 |
global reads, writes, total_io |
| 14 |
|
| 15 |
probe vfs.read.return { |
| 16 |
if (returnval() > 0) { |
| 17 |
reads[pid(),execname()] += returnval() |
| 18 |
total_io[pid(),execname()] += returnval() |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
probe vfs.write.return { |
| 23 |
if (returnval() > 0) { |
| 24 |
writes[pid(),execname()] += returnval() |
| 25 |
total_io[pid(),execname()] += returnval() |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
function humanreadable(bytes) { |
| 30 |
if (bytes > 1024*1024*1024) { |
| 31 |
return sprintf("%d GiB", bytes/1024/1024/1024) |
| 32 |
} else if (bytes > 1024*1024) { |
| 33 |
return sprintf("%d MiB", bytes/1024/1024) |
| 34 |
} else if (bytes > 1024) { |
| 35 |
return sprintf("%d KiB", bytes/1024) |
| 36 |
} else { |
| 37 |
return sprintf("%d B", bytes) |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
probe timer.s(1) { |
| 42 |
foreach([p,e] in total_io- limit 10) |
| 43 |
printf("%8d %15s r: %12s w: %12s\n", |
| 44 |
p, e, humanreadable(reads[p,e]), |
| 45 |
humanreadable(writes[p,e])) |
| 46 |
printf("\n") |
| 47 |
# Note we don't zero out reads, writes and total_io, |
| 48 |
# so the values are cumulative since the script started. |
| 49 |
} |