From c45b18d71eb8d57db62fced5774c12adcaf4eaba Mon Sep 17 00:00:00 2001 From: ddomingo Date: Mon, 29 Sep 2008 14:47:40 +1000 Subject: added file --- .../en-US/Useful_Scripts-disktop.xml | 212 +++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-disktop.xml (limited to 'doc/SystemTap_Beginners_Guide') diff --git a/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-disktop.xml b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-disktop.xml new file mode 100644 index 00000000..df6477de --- /dev/null +++ b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-disktop.xml @@ -0,0 +1,212 @@ + + + + +
+ Summarizing Disk Read/Write Traffic + + + + NO ENTRY IN WAR STORIES: Summarize Disk Read/Write Traffic + http://sourceware.org/systemtap/examples/io/disktop.stp + + + + This section describes how to identify which processes are performing the heaviest disk reads/writes to the system. + + + disktop.stp + + +#!/usr/bin/env stap +# +# Copyright (C) 2007 Oracle Corp. +# +# Get the status of reading/writing disk every 5 seconds, output top ten entries +# +# This is free software,GNU General Public License (GPL); either version 2, or (at your option) any +# later version. +# +# Usage: +# ./disktop.stp +# + +global io_stat,device +global read_bytes,write_bytes + +probe kernel.function("vfs_read").return { + if ($return>0) { + dev = __file_dev($file) + devname = __find_bdevname(dev,__file_bdev($file)) + + if (devname!="N/A") {/*skip read from cache*/ + io_stat[pid(),execname(),uid(),ppid(),"R"] += $return + device[pid(),execname(),uid(),ppid(),"R"] = devname + read_bytes += $return + } + } +} + +probe kernel.function("vfs_write").return { + if ($return>0) { + dev = __file_dev($file) + devname = __find_bdevname(dev,__file_bdev($file)) + + if (devname!="N/A") { /*skip update cache*/ + io_stat[pid(),execname(),uid(),ppid(),"W"] += $return + device[pid(),execname(),uid(),ppid(),"W"] = devname + write_bytes += $return + } + } +} + +probe timer.ms(5000) { + /* skip non-read/write disk */ + if (read_bytes+write_bytes) { + + printf("\n%-25s, %-8s%4dKb/sec, %-7s%6dKb, %-7s%6dKb\n\n",ctime(gettimeofday_s()),"Average:", + ((read_bytes+write_bytes)/1024)/5,"Read:",read_bytes/1024,"Write:",write_bytes/1024) + + /* print header */ + printf("%8s %8s %8s %25s %8s %4s %12s\n","UID","PID","PPID","CMD","DEVICE","T","BYTES") + } + /* print top ten I/O */ + foreach ([process,cmd,userid,parent,action] in io_stat- limit 10) + printf("%8d %8d %8d %25s %8s %4s %12d\n",userid,process,parent,cmd,device[process,cmd,userid,parent,action],action,io_stat[process,cmd,userid,parent,action]) + + /* clear data */ + delete io_stat + delete device + read_bytes = 0 + write_bytes = 0 +} + +probe end{ + delete io_stat + delete device + delete read_bytes + delete write_bytes +} + + + + + outputs the top ten processes responsible for the heaviest reads/writes to disk. displays a sample output for this script, and includes the following data per listed process: + + + UID — user ID. A user ID of 0 refers to the root user. + + PID — the ID of the listed process. + + PPID — the process ID of the listed process's parent process. + + CMD — the name of the listed process. + + DEVICE — which storage device the listed process is reading from or writing to. + + T — the type of action performed by the listed process; W refers to write, while R refers to read. + + BYTES — the amount of data read to or written from disk. + + + + + <xref linkend="scriptdisktop"/> Sample Output + +[...] +Mon Sep 29 03:38:28 2008 , Average: 19Kb/sec, Read: 7Kb, Write: 89Kb + +UID PID PPID CMD DEVICE T BYTES +0 26319 26294 firefox sda5 W 90229 +0 2758 2757 pam_timestamp_c sda5 R 8064 +0 2885 1 cupsd sda5 W 1678 + +Mon Sep 29 03:38:38 2008 , Average: 1Kb/sec, Read: 7Kb, Write: 1Kb + +UID PID PPID CMD DEVICE T BYTES +0 2758 2757 pam_timestamp_c sda5 R 8064 +0 2885 1 cupsd sda5 W 1678 + + + + + + + + + + + + + + outputs raw statistics on both CPU and disk usage per second. I/O usage is tracked through the events ioblock.request and ioblock.request.end, which track each request (and request completion) for a generic block I/O. CPU usage is tracked through scheduler.cpu_on and scheduler.cpu_off, which are activated whenever a process begins (and ends) a command execution on a CPU. + +
+ gnuplot +Running by itself hardly presents any data that is useful, as in . + +Raw disk-usage-graph.stp Output + +[...] +62 +5 +3 +4 +6 +4 +4 +5 +5 +3 +6 +5 +e +pause 1 + + + +However, refining the output of through gnuplot presents us with a more useful result. gnuplot is a lightweight, command-line driven plotting program that helps you display data in a graphical format. + +By piping output to gnuplot (as in stap disk-usage-graph.stp | gnuplot), we get a graphical output similar to the following: + +
+ Graphical Output Sample + + + + + + Sample output + + + + Sample output of when piped through gnuplot + + + +
+ + presents a cleaner, more useful graphical output. This graph can show you the level of utilization for both I/O and CPU, in real time. + + + question: does this script also capture stap process? i.e. does the graph also include CPU utilization by systemtap while the script is running? + + + + + http://sourceware.org/systemtap/examples/subsystem-index.html + + + + Graphing Disk and CPU Utilization - http://sourceware.org/systemtap/examples/general/graphs.stp + + + + + Summarize Disk Read/Write Traffic + http://sourceware.org/systemtap/examples/io/disktop.stp + +
+
+ -- cgit