| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ |
| 3 |
]> |
| 4 |
|
| 5 |
|
| 6 |
<section id="useful-disk-graphwithgnuplot"> |
| 7 |
<title>Real-Time Graphing of Disk and CPU Utilization</title> |
| 8 |
|
| 9 |
<remark> |
| 10 |
http://sourceware.org/systemtap/examples/subsystem-index.html |
| 11 |
</remark> |
| 12 |
|
| 13 |
<remark> |
| 14 |
Graphing Disk and CPU Utilization - http://sourceware.org/systemtap/examples/general/graphs.stp |
| 15 |
</remark> |
| 16 |
|
| 17 |
<para>This section describes how you can graph disk and CPU utilization in real-time, that is, in samples of 1 second each.</para> |
| 18 |
|
| 19 |
<formalpara id="scriptdiskusage"> |
| 20 |
<title>disk-usage-graph.stp</title> |
| 21 |
<para> |
| 22 |
<programlisting>#! stap |
| 23 |
# disk I/O stats |
| 24 |
probe begin { qnames["ioblock"] ++; qsq_start ("ioblock") } |
| 25 |
probe ioblock.request { qs_wait ("ioblock") qs_run("ioblock") } |
| 26 |
probe ioblock.end { qs_done ("ioblock") } |
| 27 |
# CPU utilization |
| 28 |
probe begin { qnames["cpu"] ++; qsq_start ("cpu") } |
| 29 |
probe scheduler.cpu_on { if (!idle) {qs_wait ("cpu") qs_run ("cpu") }} |
| 30 |
probe scheduler.cpu_off { if (!idle) qs_done ("cpu") } |
| 31 |
# ------------------------------------------------------------------------ |
| 32 |
# utilization history tracking |
| 33 |
global N |
| 34 |
probe begin { N = 50 } |
| 35 |
global qnames, util, histidx |
| 36 |
function qsq_util_reset(q) { |
| 37 |
u=qsq_utilization (q, 100) |
| 38 |
qsq_start (q) |
| 39 |
return u |
| 40 |
} |
| 41 |
probe timer.ms(100) { # collect utilization percentages frequently |
| 42 |
histidx = (histidx + 1) % N # into circular buffer |
| 43 |
foreach (q in qnames) |
| 44 |
util[histidx,q] = qsq_util_reset(q) |
| 45 |
} |
| 46 |
# ------------------------------------------------------------------------ |
| 47 |
# general gnuplot graphical report generation |
| 48 |
probe timer.ms(1000) { |
| 49 |
# emit gnuplot command to display recent history |
| 50 |
printf ("set yrange [0:100]\n") |
| 51 |
printf ("plot ") |
| 52 |
foreach (q in qnames+) |
| 53 |
{ |
| 54 |
if (++nq >= 2) printf (", ") |
| 55 |
printf ("'-' title \"%s\" with lines", q) |
| 56 |
} |
| 57 |
printf ("\n") |
| 58 |
foreach (q in qnames+) { |
| 59 |
for (i = (histidx + 1) % N; i != histidx; i = (i + 1) % N) |
| 60 |
printf("%d\n", util[i,q]) |
| 61 |
printf ("e\n") |
| 62 |
} |
| 63 |
printf ("pause 1\n") |
| 64 |
}</programlisting> |
| 65 |
</para> |
| 66 |
</formalpara> |
| 67 |
|
| 68 |
<para><xref linkend="scriptdiskusage"/> outputs raw statistics on both CPU and disk usage per second. I/O usage is tracked through the events <command>ioblock.request</command> and <command>ioblock.request.end</command>, which track each request (and request completion) for a generic block I/O. CPU usage is tracked through <command>scheduler.cpu_on</command> and <command>scheduler.cpu_off</command>, which are activated whenever a process begins (and ends) a command execution on a CPU.</para> |
| 69 |
|
| 70 |
<section id="gnuplotexplain"> |
| 71 |
<title>gnuplot</title> |
| 72 |
<para>Running <xref linkend="scriptdiskusage"/> by itself hardly presents any data that is useful, as in <xref linkend="rawdiskusagegraph"/>.</para> |
| 73 |
|
| 74 |
<example id="rawdiskusagegraph"><title>Raw disk-usage-graph.stp Output</title> |
| 75 |
<screen>[...] |
| 76 |
62 |
| 77 |
5 |
| 78 |
3 |
| 79 |
4 |
| 80 |
6 |
| 81 |
4 |
| 82 |
4 |
| 83 |
5 |
| 84 |
5 |
| 85 |
3 |
| 86 |
6 |
| 87 |
5 |
| 88 |
e |
| 89 |
pause 1</screen> |
| 90 |
</example> |
| 91 |
|
| 92 |
<para>However, refining the output of <xref linkend="scriptdiskusage"/> through <command>gnuplot</command> presents us with a more useful result. <command>gnuplot</command> is a lightweight, command-line driven plotting program that helps you display data in a graphical format.</para> |
| 93 |
|
| 94 |
<para>By piping <xref linkend="scriptdiskusage"/> output to <command>gnuplot</command> (as in <command>stap disk-usage-gr<remark> |
| 95 |
http://sourceware.org/systemtap/examples/subsystem-index.html |
| 96 |
</remark> |
| 97 |
|
| 98 |
<remark> |
| 99 |
Graphing Disk and CPU Utilization - http://sourceware.org/systemtap/examples/general/graphs.stp |
| 100 |
</remark> aph.stp | gnuplot</command>), we get a graphical output similar to the following:</para> |
| 101 |
|
| 102 |
<figure id="gnuoutputsample"> |
| 103 |
<title>Graphical Output Sample</title> |
| 104 |
<mediaobject> |
| 105 |
<imageobject> |
| 106 |
<imagedata fileref="images/gnuplotsample.png" format="PNG"/> |
| 107 |
</imageobject> |
| 108 |
<textobject> |
| 109 |
<phrase>Sample output</phrase> |
| 110 |
</textobject> |
| 111 |
<caption> |
| 112 |
<para> |
| 113 |
Sample output of <xref linkend="scriptdiskusage"/> when piped through <command>gnuplot</command> |
| 114 |
</para> |
| 115 |
</caption> |
| 116 |
</mediaobject> |
| 117 |
</figure> |
| 118 |
|
| 119 |
<para><xref linkend="gnuoutputsample"/> 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.</para> |
| 120 |
|
| 121 |
<remark> |
| 122 |
question: does this script also capture stap process? that is, does the graph also include CPU utilization by systemtap while the script is running? |
| 123 |
</remark> |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
<!-- |
| 128 |
disktop has no entry in war stories |
| 129 |
<remark> |
| 130 |
Summarize Disk Read/Write Traffic |
| 131 |
http://sourceware.org/systemtap/examples/io/disktop.stp |
| 132 |
</remark>--> |
| 133 |
</section> |
| 134 |
</section> |
| 135 |
|