From 76297499ddb5d1cb1b372e7bf86b4fcf2bd6f06e Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 24 May 2013 10:33:06 -0400 Subject: [PATCH] traceio.stp example: check for negative $return The I/O reads and writes should only be counted when $return is nonnegative. A negative $result occurs if an error was met (e.g. EAGAIN = -11). We could have instead here used the bytes_read/written variables provided by the tapset, but this example demonstrates the use of local vars and is also consistent with the disktop.stp example. --- .../en-US/Useful_Scripts-traceio.xml | 47 ++++++++++++------- testsuite/systemtap.examples/io/traceio.stp | 12 +++-- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-traceio.xml b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-traceio.xml index 6da1e2b20..c12fac15e 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-traceio.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-traceio.xml @@ -106,27 +106,42 @@ pam_timestamp_c r: 138 KiB w: 0 KiB + foreach([p,e] in total_io- limit 10) + printf("%8d %15s r: %12s w: %12s\n", + p, e, humanreadable(reads[p,e]), + humanreadable(writes[p,e])) + printf("\n") + # Note we don't zero out reads, writes and total_io, + # so the values are cumulative since the script started. +} +--> diff --git a/testsuite/systemtap.examples/io/traceio.stp b/testsuite/systemtap.examples/io/traceio.stp index 875000cb8..4dcb155c3 100755 --- a/testsuite/systemtap.examples/io/traceio.stp +++ b/testsuite/systemtap.examples/io/traceio.stp @@ -13,13 +13,17 @@ global reads, writes, total_io probe vfs.read.return { - reads[pid(),execname()] += $return - total_io[pid(),execname()] += $return + if ($return > 0) { + reads[pid(),execname()] += $return + total_io[pid(),execname()] += $return + } } probe vfs.write.return { - writes[pid(),execname()] += $return - total_io[pid(),execname()] += $return + if ($return > 0) { + writes[pid(),execname()] += $return + total_io[pid(),execname()] += $return + } } function humanreadable(bytes) { -- 2.43.5