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.
Difference between revisions of "Linux Tools Project/Systemtap/User Guide/ide/lesson2.html"
Line 2: | Line 2: | ||
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 <b> Systemtap website's tutorial</b> - http://sourceware.org/systemtap/tutorial | + | 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-><u>N</u>ew. Specify a file name of your choosing, but be sure that it | ||
Line 10: | Line 9: | ||
<img src="images/newfile.png"><br><br> | <img src="images/newfile.png"><br><br> | ||
− | + | Now type/copy the following: | |
− | < | + | <pre> |
global read, write, start | global read, write, start | ||
Line 27: | Line 26: | ||
write=0 | write=0 | ||
} | } | ||
− | + | </pre> | |
Now to demonstrate the functionality of the Probe Alias browser we will have you complete the read probe | Now to demonstrate the functionality of the Probe Alias browser we will have you complete the read probe | ||
Line 36: | Line 35: | ||
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: | ||
− | <pre | + | <pre> |
probe syscall.read | probe syscall.read | ||
{ | { | ||
Line 45: | Line 44: | ||
} | } | ||
− | + | </pre> | |
Now insert the following line into the syscall.read probe:<br> | Now insert the following line into the syscall.read probe:<br> | ||
− | <pre | + | <pre>read += count</pre> |
You may remove the comment (/* ... */) if you wish.<br><br> | You may remove the comment (/* ... */) if you wish.<br><br> |
Revision as of 10:50, 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 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.
<img src="images/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.