diff options
| author | ajakop <ajakop> | 2015-06-17 17:42:58 +0000 |
|---|---|---|
| committer | ajakop <ajakop> | 2015-06-17 17:42:58 +0000 |
| commit | 7c787edaa5d0b8ad0b5e6176eb6247203c534254 (patch) | |
| tree | 7cf3719e68c33248ceed97859dcec061cb616f5b /SystemTap_Beginners_Guide/arrayops-conditionals.html | |
| parent | add new langref/*.html (diff) | |
removed man pages
Diffstat (limited to 'SystemTap_Beginners_Guide/arrayops-conditionals.html')
| -rw-r--r-- | SystemTap_Beginners_Guide/arrayops-conditionals.html | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/SystemTap_Beginners_Guide/arrayops-conditionals.html b/SystemTap_Beginners_Guide/arrayops-conditionals.html index 380f2bad..f7dba460 100644 --- a/SystemTap_Beginners_Guide/arrayops-conditionals.html +++ b/SystemTap_Beginners_Guide/arrayops-conditionals.html | |||
| @@ -1,8 +1,6 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title xmlns:d="http://docbook.org/ns/docbook">3.5.6. Using Arrays in Conditional Statements</title><link rel="stylesheet" type="text/css" href="Common_Content/css/default.css" /><link rel="stylesheet" media="print" href="Common_Content/css/print.css" type="text/css" /><meta xmlns:d="http://docbook.org/ns/docbook" name="generator" content="publican v4.1.3" /><meta xmlns:d="http://docbook.org/ns/docbook" name="package" content="SystemTap-SystemTap_Beginners_Guide-2.7-en-US-2.0-1" /><link rel="home" href="index.html" title="SystemTap Beginners Guide" /><link rel="up" href="arrayoperators.html" title="3.5. Array Operations in SystemTap" /><link rel="prev" href="arrayops-deleting.html" title="3.5.5. Clearing/Deleting Arrays and Array Elements" /><link rel="next" href="arrayops-aggregates.html" title="3.5.7. Computing for Statistical Aggregates" /></head><body><p id="title"><a class="left" href="https://fedorahosted.org/publican"><img alt="Product Site" src="Common_Content/images//image_left.png" /></a><a class="right" href="https://fedorahosted.org/publican"><img alt="Documentation Site" src="Common_Content/images//image_right.png" /></a></p><ul class="docnav top"><li class="previous"><a accesskey="p" href="arrayops-deleting.html"><strong>Prev</strong></a></li><li class="home">SystemTap Beginners Guide</li><li class="next"><a accesskey="n" href="arrayops-aggregates.html"><strong>Next</strong></a></li></ul><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="arrayops-conditionals"> | 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title xmlns:d="http://docbook.org/ns/docbook">3.5.6. Using Arrays in Conditional Statements</title><link rel="stylesheet" type="text/css" href="Common_Content/css/default.css" /><link rel="stylesheet" media="print" href="Common_Content/css/print.css" type="text/css" /><meta xmlns:d="http://docbook.org/ns/docbook" name="generator" content="not publican" /><meta xmlns:d="http://docbook.org/ns/docbook" name="package" content="" /><link rel="home" href="index.html" title="SystemTap Beginners Guide" /><link rel="up" href="arrayoperators.html" title="3.5. Array Operations in SystemTap" /><link rel="prev" href="arrayops-deleting.html" title="3.5.5. Clearing/Deleting Arrays and Array Elements" /><link rel="next" href="arrayops-aggregates.html" title="3.5.7. Computing for Statistical Aggregates" /></head><body><p id="title"></p><ul class="docnav top"><li class="previous"><a accesskey="p" href="arrayops-deleting.html"><strong>Prev</strong></a></li><li class="home">SystemTap Beginners Guide</li><li class="next"><a accesskey="n" href="arrayops-aggregates.html"><strong>Next</strong></a></li></ul><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="arrayops-conditionals"> |
| 3 | </a>3.5.6. Using Arrays in Conditional Statements</h3></div></div></div><a id="idm47748183004544" class="indexterm"></a><a id="idm47748183003136" class="indexterm"></a><a id="idm47748218468496" class="indexterm"></a><a id="idm47748218467088" class="indexterm"></a><div class="para"> | 3 | </a>3.5.6. Using Arrays in Conditional Statements</h3></div></div></div><a id="idm140174735917520" class="indexterm"></a><a id="idm140174735915888" class="indexterm"></a><a id="idm140174737343136" class="indexterm"></a><a id="idm140174737341504" class="indexterm"></a><div class="para">You can also use associative arrays in <code class="command">if</code> 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:</div><div class="example"><a id="simplevfsreadprintif"> |
| 4 | You can also use associative arrays in <code class="command">if</code> 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: | ||
| 5 | </div><div class="example"><a id="simplevfsreadprintif"> | ||
| 6 | </a><p class="title"><strong>Example 3.19. vfsreads-print-if-1kb.stp</strong></p><div class="example-contents"><pre class="programlisting">global reads | 4 | </a><p class="title"><strong>Example 3.19. vfsreads-print-if-1kb.stp</strong></p><div class="example-contents"><pre class="programlisting">global reads |
| 7 | probe vfs.read | 5 | probe vfs.read |
| 8 | { | 6 | { |
| @@ -17,13 +15,7 @@ probe timer.s(3) | |||
| 17 | printf("%s : %dkB \n", count, reads[count]/1024) | 15 | printf("%s : %dkB \n", count, reads[count]/1024) |
| 18 | else | 16 | else |
| 19 | printf("%s : %dB \n", count, reads[count]) | 17 | printf("%s : %dB \n", count, reads[count]) |
| 20 | }</pre></div></div><div class="para"> | 18 | }</pre></div></div><div class="para">Every three seconds, <a class="xref" href="arrayops-conditionals.html#simplevfsreadprintif">Example 3.19, “vfsreads-print-if-1kb.stp”</a> 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 <code class="command">if</code> statement in the script converts and prints it out in <code class="command">kB</code>.</div><div class="para"><div xmlns:d="http://docbook.org/ns/docbook" class="title">Testing for Membership</div><a id="idm140174733425296" class="indexterm"></a><a id="idm140174740246704" class="indexterm"></a><a id="idm140174742991696" class="indexterm"></a><a id="idm140174742989600" class="indexterm"></a><a id="idm140174735885744" class="indexterm"></a>You can also test whether a specific unique key is a member of an array. Further, membership in an array can be used in <code class="command">if</code> statements, as in:</div><pre class="screen">if([<em class="replaceable">index_expression</em>] in <em class="replaceable">array_name</em>) <em class="replaceable">statement</em></pre><div class="para">To illustrate this, consider the following example:</div><div class="example"><a id="simplesimplevfsreadprintifmember"> |
| 21 | Every three seconds, <a class="xref" href="arrayops-conditionals.html#simplevfsreadprintif">Example 3.19, “vfsreads-print-if-1kb.stp”</a> 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 <code class="command">if</code> statement in the script converts and prints it out in <code class="command">kB</code>. | ||
| 22 | </div><div class="para"><div xmlns:d="http://docbook.org/ns/docbook" class="title">Testing for Membership</div><a id="idm47748216719568" class="indexterm"></a><a id="idm47748216718352" class="indexterm"></a><a id="idm47748180329728" class="indexterm"></a><a id="idm47748180328512" class="indexterm"></a><a id="idm47748222288704" class="indexterm"></a> | ||
| 23 | You can also test whether a specific unique key is a member of an array. Further, membership in an array can be used in <code class="command">if</code> statements, as in: | ||
| 24 | </div><pre class="screen">if([<em class="replaceable">index_expression</em>] in <em class="replaceable">array_name</em>) <em class="replaceable">statement</em></pre><div class="para"> | ||
| 25 | To illustrate this, consider the following example: | ||
| 26 | </div><div class="example"><a id="simplesimplevfsreadprintifmember"> | ||
| 27 | </a><p class="title"><strong>Example 3.20. vfsreads-stop-on-stapio2.stp</strong></p><div class="example-contents"><pre class="programlisting">global reads | 19 | </a><p class="title"><strong>Example 3.20. vfsreads-stop-on-stapio2.stp</strong></p><div class="example-contents"><pre class="programlisting">global reads |
| 28 | 20 | ||
| 29 | probe vfs.read | 21 | probe vfs.read |
| @@ -40,6 +32,4 @@ probe timer.s(3) | |||
| 40 | printf("stapio read detected, exiting\n") | 32 | printf("stapio read detected, exiting\n") |
| 41 | exit() | 33 | exit() |
| 42 | } | 34 | } |
| 43 | }</pre></div></div><div class="para"> | 35 | }</pre></div></div><div class="para">The <code class="command">if(["stapio"] in reads)</code> statement instructs the script to print <code class="computeroutput">stapio read detected, exiting</code> once the unique key <code class="command">stapio</code> is added to the array <code class="command">reads</code>.</div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="arrayops-deleting.html"><strong>Prev</strong>3.5.5. Clearing/Deleting Arrays and Array Elements</a></li><li class="up"><a accesskey="u" href="#"><strong>Up</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>Home</strong></a></li><li class="next"><a accesskey="n" href="arrayops-aggregates.html"><strong>Next</strong>3.5.7. Computing for Statistical Aggregates</a></li></ul></body></html> \ No newline at end of file |
| 44 | The <code class="command">if(["stapio"] in reads)</code> statement instructs the script to print <code class="computeroutput">stapio read detected, exiting</code> once the unique key <code class="command">stapio</code> is added to the array <code class="command">reads</code>. | ||
| 45 | </div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="arrayops-deleting.html"><strong>Prev</strong>3.5.5. Clearing/Deleting Arrays and Array Elements</a></li><li class="up"><a accesskey="u" href="#"><strong>Up</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>Home</strong></a></li><li class="next"><a accesskey="n" href="arrayops-aggregates.html"><strong>Next</strong>3.5.7. Computing for Statistical Aggregates</a></li></ul></body></html> \ No newline at end of file | ||
