Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: deea0b8561d2c958399c005444953951e9448fad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<a href="../../toc.html">Table of Contents</a> > <a href="../gettingStarted.html">Getting Started</a> > <a href="../IDETutorial.html">IDE Tutorial</a>

<h2>
IDE Tutorial, Lesson Two: Writing Your First Script
</h2>

In this tutorial we will guide you through the process of writing your first Systemtap script. It is 
strongly recommended that you review the <a href="http://sourceware.org/systemtap/tutorial/">
Systemtap website's tutorial</a> for up-to-date information on the latest version of Systemtap.<br><br>

Start by selecting <u>F</u>ile-><u>N</u>ew. Specify a file name of your choosing, but be sure that it
ends with an .stp extension. Click ok. Your blank script should be present in the editor pane.<br><br>

<img src="images/newfile.png"><br><br>

<pre>Now type/copy the following:

<code>
	global read, write, start

	probe begin {
		start = gettimeofday_s()
	}
	probe syscall.write {
		write += count
	}

	probe timer.ms(1000) {
		printf("%d\t%d\t%d\n", (gettimeofday_s()-start), read, write)
		read=0
		write=0
	}
</code></pre>

Now to demonstrate the functionality of the Probe Alias browser we will have you complete the read probe 
yourself. Start by opening the syscall folder in the Probe Alias browser. If you do not have any content
in the browser you are experiencing a problem with Systemtap installation and should refer to our
<a href="./installation.html">installation help</a>. Ensure your cursor is located at the end of the file.
Now scroll down and double click the read probe alias. Systemtap GUI will insert the skeleton probe at the
point at which your cursor is at, and should look similar to the following:

<pre><code>
probe syscall.read
{
	/*
	 * available variables on this probe:
	 * argstr, buf_uaddr, count, fd, name
	 */

}
</code></pre>

Now insert the following line into the syscall.read probe:<br>

<pre><code>read += count</code></pre>

You may remove the comment (/* ... */) if you wish.<br><br>

This will count the number of bytes read and written each second and print it out. The begin probe executes
first, by getting the time of day. The read and write probes increment each time the function is called. The
timer probe prints the information every second. If you typed the script in manually you may have noticed 
that the editor provides code completion for probe aliasi. If you did not, type "syscall.". You'll see a 
box come up that you may use to select an item to complete your probe alias.<br><br>

In <a href="lesson3.html">Lesson 3</a> you will learn how to run Systemtap scripts in the IDE Perspective.<br><br>

<a href="../IDETutorial.html>Back to Tutorial Contents</a>  



Back to the top