diff options
author | ddomingo <ddomingo@redhat.com> | 2008-11-03 12:05:28 +1000 |
---|---|---|
committer | ddomingo <ddomingo@redhat.com> | 2008-11-03 12:05:28 +1000 |
commit | 3be7261ad2c9496868e131147770fb3e9e409679 (patch) | |
tree | b9eaeaa4cecf1544ccb38d6d482c51f7dba0afbd /doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml | |
parent | 6a1d90ee1b3471847ff11e74bc2cb19928f5de1a (diff) | |
download | systemtap-steved-3be7261ad2c9496868e131147770fb3e9e409679.tar.gz systemtap-steved-3be7261ad2c9496868e131147770fb3e9e409679.tar.xz systemtap-steved-3be7261ad2c9496868e131147770fb3e9e409679.zip |
added aggregate stats
Diffstat (limited to 'doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml')
-rw-r--r-- | doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml | 223 |
1 files changed, 158 insertions, 65 deletions
diff --git a/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml b/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml index ebac139f..32fdf021 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml @@ -40,9 +40,9 @@ delta = gettimeofday_s() - foo[execname()] </screen> </example> -<para>In <xref linkend="arrayreadingvaluesfrom"/>, the first statement sets a timestamp associated with the returned value of the handler function <command>execname()</command> as a <emphasis>reference point</emphasis>. The second statement computes a value for the variable <command>delta</command> by subtracting the associated value the reference point from the current <command>gettimeofday_s()</command>.</para> +<para>In <xref linkend="arrayreadingvaluesfrom"/>, the first statement sets a timestamp associated with the returned value of the handler function <command>execname()</command> as a <emphasis>reference point</emphasis>. The second statement computes a value for the variable <command>delta</command> by subtracting the associated value the reference point from the current <command>gettimeofday_s()</command>. Note that the first statement writes the value of <command>gettimeofday_s()</command> into the appropriate key of array <literal>foo</literal>, while in the second statement the value of <command>foo[execname()]</command> is <emphasis>read</emphasis> from the array in order to compute for <literal>delta</literal>.</para> -<para>In this situation, if the <command><replaceable>index_expression</replaceable></command> cannot find the unique key, it returns a null value (zero) by default. </para> +<para>In this situation, if the <command><replaceable>index_expression</replaceable></command> cannot find the unique key, it returns a value of 0 (for numerical operations, such as <xref linkend="arrayreadingvaluesfrom"/>) or a null/empty string value (for string operations) by default. </para> </section> <section id="arrayops-increment"> <title>Incrementing Associated Values</title> @@ -117,18 +117,19 @@ probe timer.s(3) <example id="simplevfsreadprintnotcumulative"> <title>vfsreads-per-2secs.stp</title> <programlisting> -global reads
-probe kernel.function("vfs_read")
-{
- reads[execname()] ++
-}
-probe timer.s(2)
-{
- printf("=======\n")
- foreach (count in reads+)
- printf("%s : %d \n", count, reads[count])
- delete reads
-}
+global reads +probe kernel.function("vfs_read") +{ + reads[execname()] ++ + +} +probe timer.s(2) +{ + printf("=======\n") + foreach (count in reads+) + printf("%s : %d \n", count, reads[count]) + delete reads +} </programlisting> </example> @@ -139,28 +140,28 @@ probe timer.s(2) <para>You can have multiple array operations within the same probe. Using the examples from <xref linkend="arrayops-foreach"/> and <xref linkend="arrayops-deleting"/> , you can track the number of VFS reads each process makes per 2-second period <emphasis>and</emphasis> tally the cumulative VFS reads of those same processes. Consider the following example:</para> <screen> -global reads, totalreads
-
-probe kernel.function("vfs_read")
-{
- reads[execname()] ++
- totalreads[execname()] ++
-}
-
-probe timer.s(2)
-{
- printf("=======\n")
- foreach (count in reads+)
- printf("%s : %d \n", count, reads[count])
- delete reads
-
-}
-probe end
-{
- printf("TOTALS\n")
- foreach (total in totalreads+)
- printf("%s : %d \n", total, totalreads[total])
-}
+global reads, totalreads + +probe kernel.function("vfs_read") +{ + reads[execname()] ++ + totalreads[execname()] ++ +} + +probe timer.s(2) +{ + printf("=======\n") + foreach (count in reads+) + printf("%s : %d \n", count, reads[count]) + delete reads + +} +probe end +{ + printf("TOTALS\n") + foreach (total in totalreads+) + printf("%s : %d \n", total, totalreads[total]) +} </screen> <para>In this example, the arrays <command>reads</command> and <command>totalreads</command> track the same information, and are printed out in a similar fashion. The only difference here is that <command>reads</command> is cleared every 2-second period, whereas <command>totalreads</command> keeps growing.</para> @@ -174,18 +175,19 @@ probe end <example id="simplevfsreadprintif"> <title>vfsreads-stop-on-stapio.stp</title> <programlisting> -global reads
-probe kernel.function("vfs_read")
-{
- reads[execname()] ++
-}
-probe timer.s(2)
-{
- printf("=======\n")
- foreach (count in reads+)
- printf("%s : %d \n", count, reads[count])
- if(reads["stapio"] >= 20)
- {exit()}
+global reads +probe kernel.function("vfs_read") +{ + reads[execname()] ++ +} + +probe timer.s(2) +{ + printf("=======\n") + foreach (count in reads+) + printf("%s : %d \n", count, reads[count]) + if(reads["stapio"] >= 20) + {exit()} } </programlisting> </example> @@ -206,27 +208,118 @@ if([<replaceable>index_expression</replaceable>] in <replaceable>array_name</rep <example id="simplesimplevfsreadprintifmember"> <title>vfsreads-stop-on-stapio2.stp</title> <programlisting> -global reads
-
-probe kernel.function("vfs_read")
-{
- reads[execname()] ++
-}
-
-probe timer.s(2)
-{
- printf("=======\n")
- foreach (count in reads+)
- printf("%s : %d \n", count, reads[count])
- if(["stapio"] in reads)
- {printf("stapio read detected, exiting\n")
- exit()
- }
-}
+global reads + +probe kernel.function("vfs_read") +{ + reads[execname()] ++ +} + +probe timer.s(2) +{ + printf("=======\n") + foreach (count in reads+) + printf("%s : %d \n", count, reads[count]) + if(["stapio"] in reads) + {printf("stapio read detected, exiting\n") + exit() + } +} </programlisting> </example> <para>The <command>if(["stapio"] in reads)</command> statement instructs the script to print <computeroutput>stapio read detected, exiting</computeroutput> once the unique key <command>stapio</command> is added to the array <command>reads</command>.</para> </section> +<section id="arrayops-aggregates"> + <title>Computing for Statistical Aggregates</title> + +<para>Statistical aggregates are used to collect statistics on numerical values where it is important to accumulate new data quickly and in large volume (i.e. storing only aggregated stream statistics). Statistical aggregates can be used in global variables or as elements in an array.</para> + +<para>To add value to a statistical aggregate, use the operator <command><<< <replaceable>value</replaceable></command>.</para> + +<remark>need more examples of supported rvalues, e.g. length, count, and what each one does.</remark> + +<example id="simpleaggregates"> + <title>stat-aggregates.stp</title> +<programlisting> +global writes +probe vfs_write +{ +writes[execname()] <<< count +} +</programlisting> +</example> + +<para>In <xref linkend="simpleaggregates"/>, the operator <command><<< count</command> <emphasis>stores</emphasis> the amount returned by <literal>count</literal> to to the associated value of the corresponding <command>execname()</command> in the <literal>writes</literal> array. Remember, these values are <emphasis>stored</emphasis>; 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 (<command>execname()</command>) having multiple associated values, accumulating with each probe handler run.</para> + +<note> + <title>Note</title> + <para>In the context of <xref linkend="simpleaggregates"/>, <literal>count</literal> returns the amount of data written by the returned <command>execname()</command> to the virtual file system.</para> +</note> + +<para>To extract data collected by statistical aggregates, use the syntax format <command>@<replaceable>extractor</replaceable>(<replaceable>variable/array index expression</replaceable>)</command>. <command><replaceable>extractor</replaceable></command> can be any of the following integer extractors:</para> + +<variablelist> + +<varlistentry> + <term>count</term> +<listitem> +<para> + Returns the number of all values stored into the variable/array index expression. Given the sample probe in <xref linkend="simpleaggregates"/>, the expression <command>@count(writes[execname()])</command> will return <emphasis>how many values are stored</emphasis> in each unique key in array <literal>writes</literal>. +</para> +</listitem> +</varlistentry> + +<varlistentry> + <term>sum</term> +<listitem> +<para> + Returns the sum of all values stored into the variable/array index expression. Again, given sample probe in <xref linkend="simpleaggregates"/>, the expression <command>@sum(writes[execname()])</command> will return <emphasis>the total of all values stored</emphasis> in each unique key in array <literal>writes</literal>. +</para> + </listitem> +</varlistentry> + +<varlistentry> + <term>min</term> +<listitem> +<para> + Returns the smallest among all the values stored in the variable/array index expression. +</para> +</listitem> +</varlistentry> + +<varlistentry> + <term>max</term> +<listitem> +<para> + Returns the largest among all the values stored in the variable/array index expression. +</para> +</listitem> +</varlistentry> + +<varlistentry> + <term>avg</term> +<listitem> +<para> + Returns the average of all values stored in the variable/array index expression. +</para> +</listitem> +</varlistentry> + + + +<!-- +<varlistentry> + <term></term> +<listitem> +<para> +</para> +</listitem> +</varlistentry> +--> + +</variablelist> +</section> + </section>
\ No newline at end of file |