<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss">

<channel>
	<title>Here comes the Sun &#187; gnuplot</title>
	<atom:link href="http://sunng.info/blog/tag/gnuplot/feed/" rel="self" type="application/rss+xml" />
	<link>http://sunng.info/blog</link>
	<description>Life ramblings</description>
	<lastBuildDate>Tue, 07 Sep 2010 13:05:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Performance Visualization with Gnuplot, continued</title>
		<link>http://sunng.info/blog/2009/09/performance-visualization-with-gnuplot-continued/</link>
		<comments>http://sunng.info/blog/2009/09/performance-visualization-with-gnuplot-continued/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 13:07:46 +0000</pubDate>
		<dc:creator>Sunng</dc:creator>
				<category><![CDATA[装备]]></category>
		<category><![CDATA[foss]]></category>
		<category><![CDATA[gnuplot]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[vmstat]]></category>

		<guid isPermaLink="false">http://www.classicning.com/blog/?p=203</guid>
		<description><![CDATA[After I post my command to commandlinefu.com, there is an alternative command followed: (echo &#8220;set terminal png;plot &#8216;-&#8217; u 1:2 t &#8216;cpu&#8217; w linespoints;&#8221;; sudo vmstat 2 10 &#124; awk &#8216;NR &#62; 2 {print NR, $13}&#8217;) &#124; gnuplot &#62; plot.png This one is appreciated for using pipes and redirection. It works on Ubuntu Jaunty, on [...]]]></description>
			<content:encoded><![CDATA[<p>After I post my command to <a href="http://www.commandlinefu.com/" target="_blank">commandlinefu.com</a>, there is an alternative command followed:<br />
<em>(echo &#8220;set terminal png;plot &#8216;-&#8217; u 1:2 t &#8216;cpu&#8217; w linespoints;&#8221;; sudo vmstat 2 10 | awk &#8216;NR &gt; 2 {print NR, $13}&#8217;) | gnuplot &gt; plot.png</em></p>
<p>This one is appreciated for using pipes and redirection. It works on Ubuntu Jaunty, on which, gnuplot doesn&#8217;t provide a -e option. The author also showed an link to an open source project &#8216;vmplot&#8217; on <a href="http://freshmeat.net/projects/vmplot/" target="_blank">freshmeat</a>. Vmplot is written in python, which combines parameters with scripts and end up with an os.system call. Grab the source from <a href="http://elvis.elte.hu/~fuji/stuff/vmplot.py" target="_blank">here</a>. (Why use python instead on a simple bash command? because it&#8217;s difficult to draw a multiplot without temp file or variables, you cannot read &#8216;-&#8217; twice.)</p>
<p>There are several people vote me down for my command! It must be primers whose use ubuntu and knows the world via Synaptic only, because they failed to run the command on their dated machine (*_*)</p>
]]></content:encoded>
			<wfw:commentRss>http://sunng.info/blog/2009/09/performance-visualization-with-gnuplot-continued/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Performance Visualization with Gnuplot</title>
		<link>http://sunng.info/blog/2009/09/performance-visualization-with-gnuplot/</link>
		<comments>http://sunng.info/blog/2009/09/performance-visualization-with-gnuplot/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 13:22:35 +0000</pubDate>
		<dc:creator>Sunng</dc:creator>
				<category><![CDATA[装备]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[foss]]></category>
		<category><![CDATA[gnuplot]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.classicning.com/blog/?p=195</guid>
		<description><![CDATA[Gnuplot is considered to be one of the most famous plotting tools on both linux and windows. With Gnuplot, generation of charts becomes agile and easy. Gnuplot supports sorts of terminals range from gui, image to printer. To enable png terminal support, we will build gnuplot with following steps. (However, on most linux distributions you [...]]]></description>
			<content:encoded><![CDATA[<p>Gnuplot is considered to be one of the most famous plotting tools on both linux and windows. With Gnuplot, generation of charts becomes agile and easy. Gnuplot supports sorts of terminals range from gui, image to printer. To enable png terminal support, we will build gnuplot with following steps. (However, on most linux distributions you don&#8217;t have to do these manually, install gnuplot with package manager is doubtlessly the best choice for most cases.)</p>
<p>Well, for a naked machine, it won&#8217;t be too long to type commands in gnuplot.</p>
<h3>Installing libpng</h3>
<p>linpng provides functionality to write png images.<br />
Grab source form libpng&#8217;s website:<br />
<em>wget http://downloads.sourceforge.net/project/libpng/00-libpng-stable/1.2.39/libpng-1.2.39.tar.gz?use_mirror=ncu</em></p>
<p>Uncompress the package:<br />
<em>tar xfz libpng-1.2.39.tar.gz</em></p>
<p>cd to result directory and build it:<br />
<em>cd libpng-1.2.39<br />
./configure<br />
make<br />
make install</em></p>
<h3>Installing libgd</h3>
<p>gd provides api for programmer to draw images like Graphics2d in java. Gnuplot uses gd to draw charts on images.<br />
Grab source from gd&#8217;s website:<br />
<em>wget http://www.libgd.org/releases/gd-2.0.35.tar.gz</em></p>
<p>Uncompress it:<br />
<em>tar xfz gd-2.0.35.tar.gz</em></p>
<p>build it:<br />
<em>cd gd-2.0.35<br />
./configure<br />
make<br />
make install</em></p>
<h3>Compiling and building Gnuplot</h3>
<p>Grab source from sourceforge:<br />
<em>wget http://downloads.sourceforge.net/project/gnuplot/gnuplot/4.2.6/gnuplot-4.2.6.tar.gz?use_mirror=ncu</em></p>
<p>Uncompress and compile:<br />
<em>tar xfz gnuplot-4.2.6.tar.gz<br />
cd gnuplot<br />
./configure<br />
make<br />
make install</em></p>
<p>if &#8220;<em>&#8216;@LIBICONV@&#8217; not found</em>&#8221; encountered during make, just edit <em>src/Makefile</em> to replace <em>-l@LIBICONV@</em> to <em>-liconv</em>, and make again.<br />
Try to start gnuplot simply with:<br />
<em>gnuplot</em></p>
<p>Now you may be stopped by error message like<em> libiconv.so.2</em> not found, then you have to copy it from somewhere(such as<em> /usr/local/lib</em>) to<em> /usr/lib</em>, the it will work.</p>
<h3>Using Gnuplot</h3>
<p>As the installation completed, we start to use it.</p>
<p>vmstat is a great utility shows you the status of your process queue, memory, swap, io rates, interrupts and cpu usage. With command-line arguments, we can dump these data in a fixed interval and fixed count:<br />
<em>vmstat 5 10</em></p>
<p>awk is a well-known editor to analyze and extract text from input, we can filter specified fields with awk like this:<br />
<em>vmstat 5 10 | awk &#8216;NR &gt; 2 {print NR-2, $13}&#8217;</em><br />
The header was ignored by the conditional expression NR&gt;2 which NR stands for Number-of-Row</p>
<p>The output is just enough for gnuplot, now use pipe to connect them together:<br />
<em>vmstat 5 10 | awk &#8216;NR &gt; 2 {print NR, $13}&#8217; | gnuplot -e &#8220;set terminal png; set output &#8216;v.png&#8217;; plot &#8216;-&#8217; u 1:2 t &#8216;cpu&#8217; w linespoints;&#8221;</em></p>
<p>To gather more information at one time, a more complex command is needed:<br />
<em>vmstat 10 360 | awk &#8216;NR &gt; 2 {print NR, $4, $9, $10, $13}&#8217; &gt; vmstat.dat ; gnuplot -e &#8220;set terminal png;set output &#8216;vmstat.png&#8217;;set grid; set multiplot;set size 0.5, 0.5;set origin 0, 0;plot &#8216;vmstat.dat&#8217; u 1:2 t &#8216;freemem&#8217; w linespoints;set size 0.5, 0.5;set origin 0.5, 0;plot &#8216;vmstat.dat&#8217; u 1:3 t &#8216;bi&#8217; w linespoints;set size 0.5, 0.5;set origin 0, 0.5;plot &#8216;vmstat.dat&#8217; u 1:4 t &#8216;bo&#8217; w linespoints;set size 0.5, 0.5;set origin 0.5, 0.5;plot &#8216;vmstat.dat&#8217; u 1:5 t &#8216;cpu&#8217; w linespoints;unset multiplot;&#8221;</em></p>
<p>Unfortunately, gnuplot in Ubuntu jaunty is at version of 4.2.4, which doesn&#8217;t support -e option. So you cannot send gnuplot commands directly in command-line. The solution is split it to several steps:<br />
<em>vmstat 10 360 | awk &#8216;NR &gt; 2 {print NR, $4, $9, $10, $13}&#8217; &gt; vmstat.dat<br />
gnuplot<br />
&gt;set terminal png;<br />
&gt;set output &#8216;vmstat.png&#8217;;<br />
&gt;set grid;<br />
&gt;set multiplot;<br />
&gt;set size 0.5, 0.5;<br />
&gt;set origin 0, 0;<br />
&gt;plot &#8216;vmstat.dat&#8217; u 1:2 t &#8216;freemem&#8217; w linespoints;<br />
&gt;set size 0.5, 0.5;<br />
&gt;set origin 0.5, 0;<br />
&gt;plot &#8216;vmstat.dat&#8217; u 1:3 t &#8216;bi&#8217; w linespoints;<br />
&gt;set size 0.5, 0.5;<br />
&gt;set origin 0, 0.5;plot &#8216;vmstat.dat&#8217; u 1:4 t &#8216;bo&#8217; w linespoints;<br />
&gt;set size 0.5, 0.5;<br />
&gt;set origin 0.5, 0.5;<br />
&gt;plot &#8216;vmstat.dat&#8217; u 1:5 t &#8216;cpu&#8217; w linespoints;<br />
&gt;unset multiplot;</em></p>
<p>This picture is a stat result of performance test this afternoon</p>
<p><img class="alignnone" src="http://pic.yupoo.com/classicning/3794181d957c/medium.jpg" alt="" width="500" height="375" /></p>
<p>For more detailed tutorials, check the article on ibm dw:<br />
<a href="http://www.ibm.com/developerworks/library/l-gnuplot/" target="_blank">http://www.ibm.com/developerworks/library/l-gnuplot/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sunng.info/blog/2009/09/performance-visualization-with-gnuplot/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
