Skip to main content

Notice: This Wiki is now read only and edits are no longer 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"

 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<h2>IDE Tutorial, Lesson Two: Writing Your First Script</h2>
+
== 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  
+
In this tutorial we will guide you through the process of writing your first Systemtap script. It is strongly recommended that you review the '''Systemtap website's tutorial''' - http://sourceware.org/systemtap/tutorial for up-to-date information on the latest version of Systemtap. <br><br>  
strongly recommended that you review the <b> Systemtap website's tutorial</b> - http://sourceware.org/systemtap/tutorial
+
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
+
Start by selecting <u>F</u>ile-&gt;<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>  
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>
+
[[Image:Newfile.png]]<br><br>  
  
<pre>Now type/copy the following:
+
Now type/copy the following:  
 
+
<pre>  
<code>
+
 
global read, write, start
 
global read, write, start
  
Line 27: Line 23:
 
write=0
 
write=0
 
}
 
}
</code></pre>
+
</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 [[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 point at which your cursor is at, and should look similar to the following:  
Now to demonstrate the functionality of the Probe Alias browser we will have you complete the read probe  
+
<pre>probe syscall.read
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
+
[[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
+
point at which your cursor is at, and should look similar to the following:
+
 
+
<pre><code>
+
probe syscall.read
+
 
{
 
{
 
/*
 
/*
Line 45: Line 33:
  
 
}
 
}
</code></pre>
+
</pre>  
 
+
Now insert the following line into the syscall.read probe:<br>  
Now insert the following line into the syscall.read probe:<br>
+
<pre>read += count</pre>  
 
+
You may remove the comment (/* ... */) if you wish.<br><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
+
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>  
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 [[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>
+
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>  
  
[[Linux_Tools_Project/Systemtap/User_Guide/ide/IDETutorial.html | Back to Tutorial Contents ]]
+
[[Linux Tools Project/Systemtap/User Guide/ide/IDETutorial.html|Back to Tutorial Contents ]]

Latest revision as of 07:03, 10 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 Systemtap website's tutorial - http://sourceware.org/systemtap/tutorial 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.

Newfile.png

Now type/copy the following:

 
	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
	}
 

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:

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

}

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

read += count

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