Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Linux Tools Project/Systemtap/User Guide/ide/lesson2.html"

(New page: <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 t...)
 
Line 1: Line 1:
<h2>
+
<h2>IDE Tutorial, Lesson Two: Writing Your First Script</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  
 
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/">
+
strongly recommended that you review the "http://sourceware.org/systemtap/tutorial"
 
Systemtap website's tutorial</a> for up-to-date information on the latest version of Systemtap.<br><br>
 
Systemtap website's tutorial</a> for up-to-date information on the latest version of Systemtap.<br><br>
  
Line 34: Line 32:
 
yourself. Start by opening the syscall folder in the Probe Alias browser. If you do not have any content
 
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
 
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.
+
[[Linux_Tools_Project/Systemtap/User_Guide/installation | Installation help page]]. 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
 
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:
 
point at which your cursor is at, and should look similar to the following:
Line 61: Line 59:
 
box come up that you may use to select an item to complete your probe alias.<br><br>
 
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>
+
In [[Linux_Tools_Project/Systemtap/User_Guide/ide/lesson3.html | Lesson 3]] you will learn how to run Systemtap scripts in the IDE Perspective.<br><br>
  
<a href="../IDETutorial.html>Back to Tutorial Contents</a>
+
[[Linux_Tools_Project/Systemtap/User_Guide/ide/IDETutorial.html | Back to Tutorial Contents ]]

Revision as of 10:45, 9 November 2010

IDE Tutorial, Lesson Two: Writing Your First Script

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

Start by selecting File->New. 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.

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

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>

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 Installation help page. 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:

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

}
</code>

Now insert the following line into the syscall.read probe:

<code>read += count</code>

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

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.

In Lesson 3 you will learn how to run Systemtap scripts in the IDE Perspective.

Back to Tutorial Contents

Back to the top