<?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/"
	>

<channel>
	<title>Case &#187; pv</title>
	<atom:link href="http://case.net.ru/tag/pv/feed/" rel="self" type="application/rss+xml" />
	<link>http://case.net.ru</link>
	<description>Just another technical weblog</description>
	<lastBuildDate>Sun, 29 Jan 2012 08:48:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Pipe Viewer (pv)</title>
		<link>http://case.net.ru/2009/07/26/pipe-viewer-pv/</link>
		<comments>http://case.net.ru/2009/07/26/pipe-viewer-pv/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 04:48:40 +0000</pubDate>
		<dc:creator>Case</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[pv]]></category>

		<guid isPermaLink="false">http://case.net.ru/?p=679</guid>
		<description><![CDATA[Pipe Viewer (pv) is a terminal-based tool for monitoring the progress of data through a pipeline. It can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how [...]]]></description>
			<content:encoded><![CDATA[<p>
<blockquote>Pipe Viewer (pv) is a terminal-based tool for monitoring the progress of data through a pipeline. It can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion.</p>
<p>Author: Andrew Wood <andrew.wood@ivarch.com><br />
WWW: http://www.ivarch.com/programs/pv.shtml</p></blockquote>
<p>PV — это сокращенно от pipeviewer, то есть ни много не мало как просмотрщик пайпов. Про эффективность использования пайпов расказывать не буду, ни для кого это не секрет. Единственное, «но» в работе с ними — это то, что набрав команду и нажав Enter часто не хватает самой малости — знать сколько времени займет ее выполнение. Именно cкорость обработки данных и будет нам показывать pv.</p>
<p>Установка:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>sysutils<span style="color: #000000; font-weight: bold;">/</span>pv; <span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> clean</pre></div></div>

<p>Дальше вводная, допустим вы такой же как и я счасливый обладатель каких-нибудь полезных логов и в какой-то момент у вас дошли руки их заархивировать, например так</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> rt94-<span style="color: #000000;">171</span>-06 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">&gt;</span> rt94-<span style="color: #000000;">171</span>-06.gz</pre></div></div>

<p>Есть мысли, сколько времени займет эта операция?</p>
<p>Тоже самое при помощи pv</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span>pv rt94-<span style="color: #000000;">171</span>-06 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">&gt;</span> rt94-<span style="color: #000000;">171</span>-06.gz 
128MB <span style="color: #000000;">0</span>:00:<span style="color: #000000;">15</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> 9.1MB<span style="color: #000000; font-weight: bold;">/</span>s<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>=====<span style="color: #000000; font-weight: bold;">&gt;</span>.....................<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">18</span><span style="color: #000000; font-weight: bold;">%</span> ETA <span style="color: #000000;">0</span>:01:07</pre></div></div>

<p>Наглядно видно, что через пайп за 15 секунд прошло 128Мб — это 18% от всего объема, операция займет еще минуту и 7 секунд. </p>
<p>Может показаться, что pv это такая замена для cat, но на самом деле ее возможности намного шире. Например, упаковываем весь каталог в сжатый архив</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-czf</span> - . <span style="color: #000000; font-weight: bold;">|</span> pv <span style="color: #000000; font-weight: bold;">&gt;</span> out.tgz
21.9MB <span style="color: #000000;">0</span>:00:<span style="color: #000000;">15</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>1.47MB<span style="color: #000000; font-weight: bold;">/</span>s<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #000000; font-weight: bold;">&lt;</span>=<span style="color: #000000; font-weight: bold;">&gt;</span>.....................<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Уже неплохо, но хочеться большего, чтобы показывалось время окончания работы. Для этого всего лишь надо при помощи ключа -s передать pv размер каталога в байтах</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-czf</span> - . <span style="color: #000000; font-weight: bold;">|</span> pv <span style="color: #660033;">-s</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-sb</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">'[0-9]*'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> out.tgz
44.3MB <span style="color: #000000;">0</span>:00:<span style="color: #000000;">27</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>1.73MB<span style="color: #000000; font-weight: bold;">/</span>s<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">&gt;</span>..........................<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span> ETA <span style="color: #000000;">13</span>:<span style="color: #000000;">36</span>:<span style="color: #000000;">22</span></pre></div></div>

<p>Можно так же составлять команды из несколько копий pv.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-cf</span> - . <span style="color: #000000; font-weight: bold;">|</span> pv <span style="color: #660033;">-cN</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-s</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-sb</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">'[0-9]*'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">|</span> pv <span style="color: #660033;">-cN</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">&gt;</span> out.tgz
<span style="color: #c20cb9; font-weight: bold;">tar</span>: 97.1MB <span style="color: #000000;">0</span>:00:08 <span style="color: #7a0874; font-weight: bold;">&#91;</span>12.3MB<span style="color: #000000; font-weight: bold;">/</span>s<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">&gt;</span>......................<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span> ETA <span style="color: #000000;">1</span>:<span style="color: #000000;">50</span>:<span style="color: #000000;">26</span>
<span style="color: #c20cb9; font-weight: bold;">gzip</span>: 13.1MB <span style="color: #000000;">0</span>:00:08 <span style="color: #7a0874; font-weight: bold;">&#91;</span>1.6MB<span style="color: #000000; font-weight: bold;">/</span>s<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>....<span style="color: #000000; font-weight: bold;">&lt;</span>=<span style="color: #000000; font-weight: bold;">&gt;</span>................<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Ключ -c нужен, чтобы несколько копий pv не выводили информацию друг поверх друга. Ключ -N дает имя шкале.</p>
<p>Ну и под конец забавный пример с одного англоязычного блога о Линуксе</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span>pv <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
18MB <span style="color: #000000;">0</span>:00:05 <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">3</span>,6MB<span style="color: #000000; font-weight: bold;">/</span>s<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #000000; font-weight: bold;">&lt;</span>=<span style="color: #000000; font-weight: bold;">&gt;</span>............................<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Оригинал статьи: <a href="http://habrahabr.ru/blogs/linux/65384/">pv — маленькая, но очень полезная утилита</a></p>
]]></content:encoded>
			<wfw:commentRss>http://case.net.ru/2009/07/26/pipe-viewer-pv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
