From c59943f6936e93819978d5149500ca217d09667a Mon Sep 17 00:00:00 2001 From: ddomingo Date: Thu, 20 Nov 2008 11:19:00 +1000 Subject: revise as per wcohen, run 3 --- .../en-US/Array-Operations.xml | 35 +++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'doc/SystemTap_Beginners_Guide') diff --git a/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml b/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml index 270c6fc9..4aef21f4 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml @@ -196,7 +196,28 @@ probe end You can also use associative arrays in if statements. This is useful if you want to execute a subroutine once a value in the array matches a certain condition. Consider the following example: - vfsreads-stop-on-stapio.stp + vfsreads-print-if-1kb.stp + +global reads +probe vfs.read +{ + reads[execname()] ++ +} + +probe timer.s(2) +{ + printf("=======\n") + foreach (count in reads-) + if (reads[count] >= 1024) + printf("%s : %dkB \n", count, reads[count]/1024) + else + printf("%s : %dB \n", count, reads[count]) +} + + + +Every two seconds, prints out a list of all processes, along with how many times each process performed a VFS read. If the associated value of a process name is equal or greater than 1024, the if statement in the script converts and prints it out in kB. + Testing for Membership You can also test whether a specific unique key is a member of an array. Further, membership in an array can be used in if statements, as in: @@ -235,7 +256,7 @@ if([index_expression] in array_name global reads -probe kernel.function("vfs_read") +probe vfs.read { reads[execname()] ++ } @@ -269,15 +290,15 @@ probe timer.s(2) stat-aggregates.stp -global writes -probe vfs_write +global reads +probe vfs.read { -writes[execname()] <<< count +reads[execname()] <<< count } -In , the operator <<< count stores the amount returned by count to to the associated value of the corresponding execname() in the writes array. Remember, these values are stored; they are not added to the associated values of each unique key, nor are they used to replace the current associated values. In a manner of speaking, think of it as having each unique key (execname()) having multiple associated values, accumulating with each probe handler run. +In , the operator <<< count stores the amount returned by count to to the associated value of the corresponding execname() in the reads array. Remember, these values are stored; they are not added to the associated values of each unique key, nor are they used to replace the current associated values. In a manner of speaking, think of it as having each unique key (execname()) having multiple associated values, accumulating with each probe handler run. Note -- cgit