<?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>گنجه &#187; ابزار</title>
	<atom:link href="http://blog.ebrahim.ir/tag/tool/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ebrahim.ir</link>
	<description># tail -f /var/log/experience</description>
	<lastBuildDate>Wed, 25 Aug 2010 22:16:39 +0000</lastBuildDate>
	<language>fa</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>مقابله با ایرادهای فساد حافظه</title>
		<link>http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/</link>
		<comments>http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 01:03:31 +0000</pubDate>
		<dc:creator>ابراهیم</dc:creator>
				<category><![CDATA[رایانه]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[C++‎]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[Valgrind]]></category>
		<category><![CDATA[ابزار]]></category>
		<category><![CDATA[ایرادزدایی]]></category>
		<category><![CDATA[برنامه‌نویسی]]></category>
		<category><![CDATA[سرریز میان‌گیر]]></category>
		<category><![CDATA[فساد حافظه]]></category>
		<category><![CDATA[هم‌گردان]]></category>

		<guid isPermaLink="false">http://blog.ebrahim.ir/?p=261</guid>
		<description><![CDATA[مبنای بحث در این مطلب، زبان‌های C++‎ و C هستند، ولی مطالعهٔ آن برای برنامه‌نویسان هر زبانی که در معرض ایراد0های فساد حافظه1 است و حتی هر برنامه‌نویسی، احتمالاً خالی از سود نخواهد بود. برنامه‌ای نوشته‌اید که ایراد داره. اون رو حسابی آزموده‌اید و هر ایراد منطقی2 رو که فکر می‌کنید ممکن هست وجود داشته [...]]]></description>
			<content:encoded><![CDATA[<p><!--startnum=0--></p>
<p>مبنای بحث در این مطلب، زبان‌های C++‎ و C هستند، ولی مطالعهٔ آن برای برنامه‌نویسان هر زبانی که در معرض ایراد<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_0_261" id="identifier_0_261" class="footnote-link footnote-identifier-link" title="Bug">0</a></sup>های فساد حافظه<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_1_261" id="identifier_1_261" class="footnote-link footnote-identifier-link" title="Memory corruption">1</a></sup> است و حتی هر برنامه‌نویسی، احتمالاً خالی از سود نخواهد بود.</p>
<p>برنامه‌ای نوشته‌اید که ایراد داره. اون رو حسابی آزموده‌اید و هر ایراد منطقی<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_2_261" id="identifier_2_261" class="footnote-link footnote-identifier-link" title="Logical">2</a></sup> رو که فکر می‌کنید ممکن هست وجود داشته باشه بررسی و رفع کرده‌اید، ولی هنوز برنامه ایراد داره!<br />
برنامهٔ شما رفتارهای عجیبی از خودش نشون می‌ده. مثلاً اگر در حالت ایرادزدایی<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_3_261" id="identifier_3_261" class="footnote-link footnote-identifier-link" title="Debug">3</a></sup> بسازیدش<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_4_261" id="identifier_4_261" class="footnote-link footnote-identifier-link" title="Build">4</a></sup> کار می‌کنه، ولی در حالت انتشار<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_5_261" id="identifier_5_261" class="footnote-link footnote-identifier-link" title="Release">5</a></sup> یا اشتباه کار می‌کنه، یا کار نمی‌کنه و دچار سانحه<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_6_261" id="identifier_6_261" class="footnote-link footnote-identifier-link" title="Crash">6</a></sup> می‌شه. یا مثلاً با ورودی‌های مختلف، در جاهای کاملاً متفاوت و نسبتاً بی‌ربط از کد دچار سانحه می‌شه. یا مثلاً همیشه در پایان یک تابع<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_7_261" id="identifier_7_261" class="footnote-link footnote-identifier-link" title="Function">7</a></sup> بعد از همهٔ عملیات، ولی قبل از بازگشت (یعنی دقیقاً روی { !!!) دچار سانحه می‌شه.<br />
در چنین شرایطی هست که شما حدس می‌زنید برنامه‌تون دچار ایراد فساد حافظه<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_1_261" id="identifier_8_261" class="footnote-link footnote-identifier-link" title="Memory corruption">1</a></sup> شده.<br />
اگر برنامه همیشه در یک تابع خاص دچار سانحه می‌شه، حدس می‌زنیم که در یکی از متغیرهای محلی همون تابع خراب‌کاری شده و پشته<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_8_261" id="identifier_9_261" class="footnote-link footnote-identifier-link" title="Stack">8</a></sup> خراب شده؛ به همین دلیل در هنگام جمع کردن قاب پشتهٔ<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_9_261" id="identifier_10_261" class="footnote-link footnote-identifier-link" title="Stack frame">9</a></sup> تابع از روی پشته، به علت فساد نشانی بازگشت<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_10_261" id="identifier_11_261" class="footnote-link footnote-identifier-link" title="Return address">10</a></sup>، برنامه دچار سانحه می‌شه<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_11_261" id="identifier_12_261" class="footnote-link footnote-identifier-link" title="نوعی سرریز میان&zwnj;گیر (Buffer overflow)">11</a></sup>.<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_12_261" id="identifier_13_261" class="footnote-link footnote-identifier-link" title="البته این رفتار سانحه&zwnj;آمیز (!) بستگی به هم&zwnj;گردان داره، ولی هم&zwnj;گردان&zwnj;های جدید مثل GCCهای ۴ به بعد (و شاید بعضی قدیمی&zwnj;ترها)، به علت داشتن روش&zwnj;هایی برای مقابله با خرابی پشته، عمداً برنامه&zwnj;ای تولید می&zwnj;کنند که در این شرایط دچار سانحه بشه">12</a></sup> معمولاً با خوندن دقیق همون تابع، ایراد یافت و حل می‌شه. اگر نشد، متغیرهای محلی که روی پشته هستند رو به کومه<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_13_261" id="identifier_14_261" class="footnote-link footnote-identifier-link" title="Heap">13</a></sup> منتقل می‌کنیم (با استفاده از new یا malloc) و می‌ریم به سراغ روش‌های مربوط به فساد کومه که الان می‌خواهیم بگیم.<br />
اولین قدم برای یافتن ایرادهای فساد حافظهٔ کومه، استمداد از حضرت <a href="http://valgrind.kde.org">Valgrind</a> است (که در دبین<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_14_261" id="identifier_15_261" class="footnote-link footnote-identifier-link" title="Debian">14</a></sup> بسته‌اش valgrind است)):</p>
<div dir="ltr">

<div class="wp_syntax" dir="ltr"><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;">valgrind</span> <span style="color: #660033;">--leak-check</span>=full <span style="color: #660033;">--leak-resolution</span>=high .<span style="color: #000000; font-weight: bold;">/</span>buggy</pre></div></div>

</div>
<p>برنامه با سرعتی بسیار کم‌تر از حد معمول اجرا می‌شه و هر دست‌رسی به حافظهٔ کومه که خارج از حافظهٔ تخصیص‌یافته<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_15_261" id="identifier_16_261" class="footnote-link footnote-identifier-link" title="Allocated">15</a></sup> باشه، با نام تابع و (در حالت ایرادزدایی) شمارهٔ خط کد منبع<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_16_261" id="identifier_17_261" class="footnote-link footnote-identifier-link" title="Source code">16</a></sup> گزارش می‌شه. البته Valgrind بسیار جای حرف و معرفی و ستایش و غیره داره که از موضوع این مطلب خارجه!<br />
اگر Valgrind مشکل رو یافت و ایراد رفع شد که خدا رو شکر می‌کنیم! اما اگر نه، با یک مورد بدخیم (!) طرف هستیم. یعنی دست‌رسی‌هایی داریم که به رغم ایراد داشتنشون، داخل حافظهٔ تخصیص‌یافته قرار گرفته‌اند. مثلاً دو آرایهٔ ۱۰۰تایی پشت سر هم در کومه گرفته‌ایم و به عنصر ۱۲۵ام از آرایهٔ اول دست زده‌ایم! دست‌رسی هنوز داخل حافظهٔ پردازهٔ<sup><a href="http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/#footnote_17_261" id="identifier_18_261" class="footnote-link footnote-identifier-link" title="Process">17</a></sup> خودمان است، ولی نادرست و ایراددار. اگر کسی تا این جای مطلب رو خونده باشه تعجب می‌کنم! البته کسی به جز خودم!<br />
ان‌شاء الله در مطلب بعدی شیوه‌ای برای یافتن این موارد بدخیم معرفی خواهد شد که از یکی از هم‌کاران باتجربه‌ترم (حفظه الله) آموخته‌ام.</p>
<ol start="0" class="footnotes"><li id="footnote_0_261" class="footnote">Bug</li><li id="footnote_1_261" class="footnote">Memory corruption</li><li id="footnote_2_261" class="footnote">Logical</li><li id="footnote_3_261" class="footnote">Debug</li><li id="footnote_4_261" class="footnote">Build</li><li id="footnote_5_261" class="footnote">Release</li><li id="footnote_6_261" class="footnote">Crash</li><li id="footnote_7_261" class="footnote">Function</li><li id="footnote_8_261" class="footnote">Stack</li><li id="footnote_9_261" class="footnote">Stack frame</li><li id="footnote_10_261" class="footnote">Return address</li><li id="footnote_11_261" class="footnote"><span dir="rtl">نوعی سرریز میان‌گیر (Buffer overflow)</span></li><li id="footnote_12_261" class="footnote"><span dir="rtl">البته این رفتار سانحه‌آمیز (!) بستگی به هم‌گردان داره، ولی هم‌گردان‌های جدید مثل GCCهای ۴ به بعد (و شاید بعضی قدیمی‌ترها)، به علت داشتن روش‌هایی برای مقابله با خرابی پشته، عمداً برنامه‌ای تولید می‌کنند که در این شرایط دچار سانحه بشه</span></li><li id="footnote_13_261" class="footnote">Heap</li><li id="footnote_14_261" class="footnote">Debian</li><li id="footnote_15_261" class="footnote">Allocated</li><li id="footnote_16_261" class="footnote">Source code</li><li id="footnote_17_261" class="footnote">Process</li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.ebrahim.ir/1388/01/fighting-memory-corruption-bugs/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>احیای لوح سخت</title>
		<link>http://blog.ebrahim.ir/1388/01/reviving-hard-disk/</link>
		<comments>http://blog.ebrahim.ir/1388/01/reviving-hard-disk/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 22:52:59 +0000</pubDate>
		<dc:creator>ابراهیم</dc:creator>
				<category><![CDATA[رایانه]]></category>
		<category><![CDATA[PowerMax]]></category>
		<category><![CDATA[SMART]]></category>
		<category><![CDATA[آزمون]]></category>
		<category><![CDATA[ابزار]]></category>
		<category><![CDATA[اینترنت]]></category>
		<category><![CDATA[خرابی]]></category>
		<category><![CDATA[راه‌اندازی]]></category>
		<category><![CDATA[لوح سخت]]></category>
		<category><![CDATA[موعظه]]></category>
		<category><![CDATA[یخ‌زن]]></category>

		<guid isPermaLink="false">http://blog.ebrahim.ir/?p=242</guid>
		<description><![CDATA[این مطلب در مورد زنده کردن لوح‌های سخت‌شدهٔ دل‌هامون به کمک موعظه یا چیزی شبیه اون نیست! (البته متأسفانه) لوح سختی0 دارم که خراب شده بود. وقتی رایانه1 رو روشن می‌کردم، هی سعی می‌کرد راه بیفته ولی موفق نمی‌شد و اصلاً دور بر نمی‌داشت2. در نتیجه رایانه هم همون اول کار، توی مرحلهٔ شناسایی لوح‌های [...]]]></description>
			<content:encoded><![CDATA[<p><!--startnum=0--></p>
<p>این مطلب در مورد زنده کردن لوح‌های سخت‌شدهٔ دل‌هامون به کمک موعظه یا چیزی شبیه اون نیست! (البته متأسفانه)</p>
<p>لوح سختی<sup><a href="http://blog.ebrahim.ir/1388/01/reviving-hard-disk/#footnote_0_242" id="identifier_0_242" class="footnote-link footnote-identifier-link" title="Hard Disk">0</a></sup> دارم که خراب شده بود. وقتی رایانه<sup><a href="http://blog.ebrahim.ir/1388/01/reviving-hard-disk/#footnote_1_242" id="identifier_1_242" class="footnote-link footnote-identifier-link" title="Computer">1</a></sup> رو روشن می‌کردم، هی سعی می‌کرد راه بیفته ولی موفق نمی‌شد و اصلاً دور بر نمی‌داشت<sup><a href="http://blog.ebrahim.ir/1388/01/reviving-hard-disk/#footnote_2_242" id="identifier_2_242" class="footnote-link footnote-identifier-link" title="این&zwnj;ها رو با لمس کردن لوح سخت می&zwnj;شه فهمید">2</a></sup>. در نتیجه رایانه هم همون اول کار، توی مرحلهٔ شناسایی لوح‌های سخت، گیر می‌کرد و راه‌اندازی<sup><a href="http://blog.ebrahim.ir/1388/01/reviving-hard-disk/#footnote_3_242" id="identifier_3_242" class="footnote-link footnote-identifier-link" title="boot">3</a></sup> نمی‌شد. تقریباً ازش قطع امید کرده بودم.</p>
<p>طبق معمول قبل از هر گونه تصمیم‌گیری، سری به اینترنت زدم تا ببینم ملت در این باره چی گفته‌اند. بعد از کمی جست‌وجو، با راه‌کاری غیرمنتظره مواجه شدم: لوح سخت رو بگذارید تو یخ‌زن<sup><a href="http://blog.ebrahim.ir/1388/01/reviving-hard-disk/#footnote_4_242" id="identifier_4_242" class="footnote-link footnote-identifier-link" title="Freezer">4</a></sup>! بله، <a href="http://www.trap17.com/index.php/hard-drive-freezer-trick_t26193.html">گفته</a> <a href="http://geeksaresexy.blogspot.com/2006/01/freeze-your-hard-drive-to-recover-data.html">بودند</a> که بعد از سرد کردن لوح سخت، باید بلافاصله اون رو به رایانه بزنید. اگر قسمت باشه<sup><a href="http://blog.ebrahim.ir/1388/01/reviving-hard-disk/#footnote_5_242" id="identifier_5_242" class="footnote-link footnote-identifier-link" title="این تیکه&zwnj;اش رو اون&zwnj;ها این&zwnj;جوری نگفته بودند!">5</a></sup> چند دقیقه فرصت دارید تا داده‌های مهم‌ترتون رو بر دارید.</p>
<p>از اون جا که چیز زیادی برای از دست دادن نداشتم، و در ضمن از این جور انگولک‌کردن‌ها خوشم می‌آد، تصمیم گرفتم این کار رو بکنم. لوح سخت رو توی یک کیسه پیچیدم تا برفک نزنه و خیس نشه و بعد داخل یخ‌زن گذاشتم. بعد از چند ساعت که لوح سخت قصهٔ ما حسابی یخ زد، درش آوردم و سریع به رایانه وصلش کردم.</p>
<p>رایانه رو روشن کردم و در کمال ناباوری دیدم داره کار می‌کنه! با نرم‌افزار PowerMax آزمون سریع SMART<sup><a href="http://blog.ebrahim.ir/1388/01/reviving-hard-disk/#footnote_6_242" id="identifier_6_242" class="footnote-link footnote-identifier-link" title="Self-Monitoring, Analysis and Reporting Technology">6</a></sup> رو انجام دادم و دیدم واقعاً سالمه<sup><a href="http://blog.ebrahim.ir/1388/01/reviving-hard-disk/#footnote_7_242" id="identifier_7_242" class="footnote-link footnote-identifier-link" title="کلیدواژه&zwnj;ها رو برای خنده نمی&zwnj;دم! برای این می&zwnj;دم که بتونی باهاش جست&zwnj;وجو کنی">7</a></sup>. با خودم گفتم شاید اگر در حالت خاموش گرم بشه، دوباره به همون روز بیفته. برای همین، رایانه رو خاموش نکردم و گذاشتم لوح سخت دائماً کار کنه تا در حال چرخش گرم بشه، باشد که سالم بمونه. نمی‌دونم کار این فکر بود یا نه، ولی هر چی بود جواب داد! برای این که مطمئن بشم که لوح سخت برای طولانی‌مدت سالم شده، رایانه رو خاموش کردم تا لوح کمی خنک بشه و بعد دوباره روشنش کردم. دوباره آزمودمش و دیدم که سالمه.</p>
<p>برای اطمینان از سلامت داده‌ها، از توی سامانهٔ عامل<sup><a href="http://blog.ebrahim.ir/1388/01/reviving-hard-disk/#footnote_8_242" id="identifier_8_242" class="footnote-link footnote-identifier-link" title="Operating System">8</a></sup>، چند تا پرونده<sup><a href="http://blog.ebrahim.ir/1388/01/reviving-hard-disk/#footnote_9_242" id="identifier_9_242" class="footnote-link footnote-identifier-link" title="File">9</a></sup> رو خوندم و بررسی کردم که شکر خدا سالم بودند.</p>
<p>سپاس خدای راست <img src='http://blog.ebrahim.ir/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<ol start="0" class="footnotes"><li id="footnote_0_242" class="footnote">Hard Disk</li><li id="footnote_1_242" class="footnote">Computer</li><li id="footnote_2_242" class="footnote">این‌ها رو با لمس کردن لوح سخت می‌شه فهمید</li><li id="footnote_3_242" class="footnote">boot</li><li id="footnote_4_242" class="footnote">Freezer</li><li id="footnote_5_242" class="footnote"><span dir="rtl">این تیکه‌اش رو اون‌ها این‌جوری نگفته بودند!</span></li><li id="footnote_6_242" class="footnote">Self-Monitoring, Analysis and Reporting Technology</li><li id="footnote_7_242" class="footnote">کلیدواژه‌ها رو برای خنده نمی‌دم! برای این می‌دم که بتونی باهاش جست‌وجو کنی</li><li id="footnote_8_242" class="footnote">Operating System</li><li id="footnote_9_242" class="footnote">File</li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.ebrahim.ir/1388/01/reviving-hard-disk/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>بهینه‌سازی هدایت‌شده با سابقه</title>
		<link>http://blog.ebrahim.ir/1387/12/profile-guided-optimization/</link>
		<comments>http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 03:57:45 +0000</pubDate>
		<dc:creator>ابراهیم</dc:creator>
				<category><![CDATA[رایانه]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[C++‎]]></category>
		<category><![CDATA[CMake]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[PGO]]></category>
		<category><![CDATA[ابزار]]></category>
		<category><![CDATA[برنامه‌نویسی]]></category>
		<category><![CDATA[بهینه‌سازی]]></category>
		<category><![CDATA[سابقه‌گیری]]></category>
		<category><![CDATA[لینوکس]]></category>
		<category><![CDATA[هم‌گردان]]></category>
		<category><![CDATA[ویندوز]]></category>
		<category><![CDATA[کارآیی]]></category>

		<guid isPermaLink="false">http://blog.ebrahim.ir/?p=200</guid>
		<description><![CDATA[یکی از روش‌های نسبتاً متفاوت هم‌گردان0ها برای بهینه‌سازی1، روش «بهینه‌سازی هدایت‌شده با سابقه»2 است که گاهی اون رو کوتاهانه3 PGO هم می‌گویند. مؤثر بودن این روش رو می‌شه به چشم دید. مثلاً اگر از مرورگر Firefox هم در لینوکس4 و هم در ویندوز5 استفاده کرده باشید، حتماً تفاوت فاحش کارآیی6 رو حس کرده‌اید. دلیل این [...]]]></description>
			<content:encoded><![CDATA[<p><!--startnum=0--></p>
<p>یکی از روش‌های نسبتاً متفاوت هم‌گردان<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_0_200" id="identifier_0_200" class="footnote-link footnote-identifier-link" title="Compiler">0</a></sup>ها برای بهینه‌سازی<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_1_200" id="identifier_1_200" class="footnote-link footnote-identifier-link" title="Optimization">1</a></sup>، روش «بهینه‌سازی هدایت‌شده با سابقه»<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_2_200" id="identifier_2_200" class="footnote-link footnote-identifier-link" title="Profile-Guided Optimization">2</a></sup> است که گاهی اون رو کوتاهانه<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_3_200" id="identifier_3_200" class="footnote-link footnote-identifier-link" title="به یاد استاد روحانی رانکوهی!">3</a></sup> PGO هم می‌گویند.</p>
<p>مؤثر بودن این روش رو می‌شه به چشم دید. مثلاً اگر از مرورگر Firefox هم در لینوکس<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_4_200" id="identifier_4_200" class="footnote-link footnote-identifier-link" title="Linux">4</a></sup> و هم در ویندوز<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_5_200" id="identifier_5_200" class="footnote-link footnote-identifier-link" title="Windows">5</a></sup> استفاده کرده باشید، حتماً تفاوت فاحش کارآیی<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_6_200" id="identifier_6_200" class="footnote-link footnote-identifier-link" title="Performance">6</a></sup> رو حس کرده‌اید. دلیل این تفاوت فاحش، استفاده از PGO در ساخت<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_7_200" id="identifier_7_200" class="footnote-link footnote-identifier-link" title="Build">7</a></sup> پروندهٔ<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_8_200" id="identifier_8_200" class="footnote-link footnote-identifier-link" title="File">8</a></sup> اجرایی<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_9_200" id="identifier_9_200" class="footnote-link footnote-identifier-link" title="Executable">9</a></sup> ویندوز و عدم استفاده ازش در ساخت اجرایی لینوکس بیان شده.</p>
<p>خوب، حالا که به اندازهٔ کافی انگیزوندمتون (!)، ببینیم این روش اصلاً چی هست و چه‌جوری می‌تونیم ازش استفاده کنیم.</p>
<p>اساس این روش، استفاده از اطلاعات کسب‌شده در زمان اجرا<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_10_200" id="identifier_10_200" class="footnote-link footnote-identifier-link" title="Run-time">10</a></sup>ی برنامه، برای بهینه‌سازی در زمان هم‌گردانی<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_11_200" id="identifier_11_200" class="footnote-link footnote-identifier-link" title="Compile-time">11</a></sup> هست. پس هم‌گردانی با این روش، سه مرحله خواهد داشت:</p>
<p>۱. هم‌گردانی برای تولید اجرایی مخصوص جمع‌آوری اطلاعات مورد نیاز برای بهینه‌سازی<br />
۲. اجرای برنامهٔ تولیدشده در مرحلهٔ ۱ و استفاده از موارد کاربرد<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_12_200" id="identifier_12_200" class="footnote-link footnote-identifier-link" title="Use case">12</a></sup> مورد نظر برای بهینه‌سازی<br />
۳. هم‌گردانی با بهینه‌سازی به کمک اطلاعات جمع‌آوری‌شده در مرحلهٔ ۲</p>
<p>هم‌گردان‌ها برای مراحل ۱ و ۳ گزینه‌های مخصوصی دارند که این‌جا فقط GCC رو می‌بینیم.</p>
<p>درGCC برای مرحلهٔ ۱ از گزینهٔ ‎-fprofile-generate و برای مرحلهٔ ۳ از گزینهٔ ‎-fprofile-use استفاده می‌کنیم. دقت کنید که گزینهٔ ‎-fprofile-generate رو هم باید برای هم‌گردانی<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_13_200" id="identifier_13_200" class="footnote-link footnote-identifier-link" title="Compiling">13</a></sup> بدید، و هم برای پیوند<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_14_200" id="identifier_14_200" class="footnote-link footnote-identifier-link" title="Linking">14</a></sup>.</p>
<p>من که معمولاً از CMake به عنوان سامانهٔ ساخت<sup><a href="http://blog.ebrahim.ir/1387/12/profile-guided-optimization/#footnote_15_200" id="identifier_15_200" class="footnote-link footnote-identifier-link" title="Build System">15</a></sup> استفاده می‌کنم، برای به کارگیری این روش، این چند خط رو به CMakeLists.txt اضافه می‌کنم:</p>

<div class="wp_syntax" dir="ltr"><div class="code"><pre class="none" style="font-family:monospace;"># profile::generate
#set(CMAKE_C_FLAGS &quot;${CMAKE_C_FLAGS} --profile-generate&quot;)
#set(CMAKE_CXX_FLAGS &quot;${CMAKE_CXX_FLAGS} --profile-generate&quot;)
#set(CMAKE_EXE_LINKER_FLAGS &quot;${CMAKE_EXE_LINKER_FLAGS} --profile-generate&quot;)
# profile::use
#set(CMAKE_C_FLAGS &quot;${CMAKE_C_FLAGS} --profile-use&quot;)
#set(CMAKE_CXX_FLAGS &quot;${CMAKE_CXX_FLAGS} --profile-use&quot;)
#set(CMAKE_EXE_LINKER_FLAGS &quot;${CMAKE_EXE_LINKER_FLAGS} --profile-use&quot;)</pre></div></div>

<p>برای مرحلهٔ ۱، سه تا set اول و برای مرحلهٔ ۳، سه تا set دوم رو فعال می‌کنم. راستی دقت کردید که به جای ‎-fprofile-folan می‌شه از  ‎-profile-folan- استفاده کرد؟!</p>
<ol start="0" class="footnotes"><li id="footnote_0_200" class="footnote">Compiler</li><li id="footnote_1_200" class="footnote">Optimization</li><li id="footnote_2_200" class="footnote">Profile-Guided Optimization</li><li id="footnote_3_200" class="footnote"><span dir="rtl">به یاد استاد روحانی رانکوهی!</span></li><li id="footnote_4_200" class="footnote">Linux</li><li id="footnote_5_200" class="footnote">Windows</li><li id="footnote_6_200" class="footnote">Performance</li><li id="footnote_7_200" class="footnote">Build</li><li id="footnote_8_200" class="footnote">File</li><li id="footnote_9_200" class="footnote">Executable</li><li id="footnote_10_200" class="footnote">Run-time</li><li id="footnote_11_200" class="footnote">Compile-time</li><li id="footnote_12_200" class="footnote">Use case</li><li id="footnote_13_200" class="footnote">Compiling</li><li id="footnote_14_200" class="footnote">Linking</li><li id="footnote_15_200" class="footnote">Build System</li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.ebrahim.ir/1387/12/profile-guided-optimization/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>نقش برنامه‌نویس‌ها در گرمایش زمین</title>
		<link>http://blog.ebrahim.ir/1387/12/programmers-and-global-warming/</link>
		<comments>http://blog.ebrahim.ir/1387/12/programmers-and-global-warming/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 13:40:39 +0000</pubDate>
		<dc:creator>ابراهیم</dc:creator>
				<category><![CDATA[رایانه]]></category>
		<category><![CDATA[کلمات قصار]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[C++‎]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[ابزار]]></category>
		<category><![CDATA[برنامه‌نویسی]]></category>
		<category><![CDATA[زمین]]></category>
		<category><![CDATA[طبیعت]]></category>
		<category><![CDATA[گرمایش]]></category>
		<category><![CDATA[‎.NET]]></category>

		<guid isPermaLink="false">http://blog.ebrahim.ir/?p=197</guid>
		<description><![CDATA[با پرهیز از Java و ‎.NET (در مقابل C++‎ و C) در روند گرمایش زمین سهم کم‌تری داشته باشیم.]]></description>
			<content:encoded><![CDATA[<p>با پرهیز از Java و ‎.NET (در مقابل C++‎ و C) در روند گرمایش زمین سهم کم‌تری داشته باشیم.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ebrahim.ir/1387/12/programmers-and-global-warming/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>اندر کرامات حضرت دبیَن</title>
		<link>http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/</link>
		<comments>http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 06:37:15 +0000</pubDate>
		<dc:creator>ابراهیم</dc:creator>
				<category><![CDATA[رایانه]]></category>
		<category><![CDATA[APT]]></category>
		<category><![CDATA[Darwin]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Hurd]]></category>
		<category><![CDATA[KDE]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NetBSD]]></category>
		<category><![CDATA[Nexenta]]></category>
		<category><![CDATA[OpenSolaris]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[VirtualBox]]></category>
		<category><![CDATA[ZFS]]></category>
		<category><![CDATA[ابزار]]></category>
		<category><![CDATA[تحریم]]></category>
		<category><![CDATA[سامانهٔ عامل]]></category>
		<category><![CDATA[سامانهٔ پرونده]]></category>
		<category><![CDATA[لینوکس]]></category>
		<category><![CDATA[نرم‌افزار آزاد]]></category>

		<guid isPermaLink="false">http://blog.ebrahim.ir/?p=171</guid>
		<description><![CDATA[دبیَن0 سامانهٔ عامل1 محبوب من هست. موج زدن روح آزادی نرم‌افزار رو توی دبین حس می‌کنم. بخش عظیمی از همهٔ نرم‌افزارهای آزاد دنیا رو می‌شه توی مخزن2های دبین، آمادهٔ نصب پیدا کرد؛ الان حدود ۲۰۰۰۰ تا بسته3 در مخازن رسمی4 هست. سامانهٔ مدیریت بسته‌هاش5، به نام APT (مخفف «ابزار بسته‌بندی پیش‌رفته»6)، بسیار تمیز و خوش‌دست [...]]]></description>
			<content:encoded><![CDATA[<p><!--startnum=0--></p>
<p><a href="http://www.debian.org/">دبیَن</a><sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_0_171" id="identifier_0_171" class="footnote-link footnote-identifier-link" title="Debian">0</a></sup> سامانهٔ عامل<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_1_171" id="identifier_1_171" class="footnote-link footnote-identifier-link" title="Operating System">1</a></sup> محبوب من هست.</p>
<p>موج زدن روح آزادی نرم‌افزار رو توی دبین حس می‌کنم.</p>
<p>بخش عظیمی از همهٔ نرم‌افزارهای آزاد دنیا رو می‌شه توی مخزن<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_2_171" id="identifier_2_171" class="footnote-link footnote-identifier-link" title="Repository">2</a></sup>های دبین، آمادهٔ نصب پیدا کرد؛ الان حدود ۲۰۰۰۰ تا بسته<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_3_171" id="identifier_3_171" class="footnote-link footnote-identifier-link" title="Package">3</a></sup> در مخازن رسمی<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_4_171" id="identifier_4_171" class="footnote-link footnote-identifier-link" title="Official">4</a></sup> هست.</p>
<p>سامانهٔ مدیریت بسته‌هاش<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_5_171" id="identifier_5_171" class="footnote-link footnote-identifier-link" title="Package Management">5</a></sup>، به نام <a href="http://en.wikipedia.org/wiki/Advanced_Packaging_Tool">APT</a> (مخفف «ابزار بسته‌بندی پیش‌رفته»<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_6_171" id="identifier_6_171" class="footnote-link footnote-identifier-link" title="Advanced Packaging Tool">6</a></sup>)، بسیار تمیز و خوش‌دست هست.</p>
<p>اگر سامانه‌ای حقیقتاً پایدار<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_7_171" id="identifier_7_171" class="footnote-link footnote-identifier-link" title="Stable">7</a></sup> بخوام، دبین stable رو نصب می‌کنم. اگر پایداری برام کم‌تر از به‌روز<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_8_171" id="identifier_8_171" class="footnote-link footnote-identifier-link" title="Up-to-date">8</a></sup> بودن نرم‌افزارها مهم باشه (مثلاً برای رایانهٔ منزل)، دبین unstable + experimental رو نصب می‌کنم. اگر روی سامانهٔ پایدارم آخرین نسخهٔ بسته‌های خاصی رو بخوام هم به سادگی می‌تونم بسته‌های deb رو جدا بگیرم و نصب کنم، یا با تنظیم ‎/etc/apt/preferences کار رو به دست استاد APT بسپارم (به man apt_preferences مراجعه کنید).</p>
<p>قبل از این که خبر انتشار KDE 4.2 توی پایگاه رسمی KDE اعلام بشه، بسته‌های KDE 4.2 توی مخزن دبین experimental بود و داشتم نصبش می‌کردم!</p>
<p>نرم‌افزارهای دوست‌داشتنی‌ای مثل <a href="http://www.virtualbox.org/">VirtualBox</a> رو که هم ویرایش آزاد دارند، و هم ویرایش غیرآزاد، و البته گاهی در پایگاه<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_9_171" id="identifier_9_171" class="footnote-link footnote-identifier-link" title="Site">9</a></sup> رسمیشون ایران عزیز رو تحریم کرده‌اند، از مخازن دبین به راحتی نصب می‌کنم بدون این که نگران تحریم و یا آلوده شدن رایانه‌ام به نسخهٔ غیرآزادشون باشم. همهٔ نرم‌افزارهای بخش<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_10_171" id="identifier_10_171" class="footnote-link footnote-identifier-link" title="Section">10</a></sup> main، آزاد هستند و به هیچ نرم‌افزار غیرآزادی وابستگی<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_11_171" id="identifier_11_171" class="footnote-link footnote-identifier-link" title="Dependency">11</a></sup> ندارند.</p>
<p>بعضی نرم‌افزارهای غیرآزاد مثل افزونهٔ<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_12_171" id="identifier_12_171" class="footnote-link footnote-identifier-link" title="Plugin">12</a></sup> Flash، که ناچار از استفاده‌شون هستم رو می‌تونم بدون به هم زدن یک‌پارچگی سامانه‌ام نصب کنم. بخش‌های contrib و non-free حاوی بعضی از نرم‌افزارهای غیرآزاد پراستفاده هستند.</p>
<p>یادم نره بگم که دبین برای تعداد زیادی معماری<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_13_171" id="identifier_13_171" class="footnote-link footnote-identifier-link" title="Architecture">13</a></sup> مختلف رایانه وجود داره. از x86 و AMD64 بگیر تا MIPS و ARM و PowerPC و SPARC و Alpha و &#8230; (برای فهرست کاملش http://www.debian.org/ports/‎ رو ببینید)</p>
<p>با دبین به هستهٔ لینوکس<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_14_171" id="identifier_14_171" class="footnote-link footnote-identifier-link" title="Linux">14</a></sup> محدود نیستم؛ می‌شه دبین رو با هستهٔ<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_15_171" id="identifier_15_171" class="footnote-link footnote-identifier-link" title="Kernel">15</a></sup> FreeBSD<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_16_171" id="identifier_16_171" class="footnote-link footnote-identifier-link" title="Debian GNU/kFreeBSD">16</a></sup> یا NetBSD<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_17_171" id="identifier_17_171" class="footnote-link footnote-identifier-link" title="Debian GNU/NetBSD">17</a></sup> یا Hurd<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_18_171" id="identifier_18_171" class="footnote-link footnote-identifier-link" title="Debian GNU/Hurd">18</a></sup> یا OpenSolaris<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_19_171" id="identifier_19_171" class="footnote-link footnote-identifier-link" title="Nexenta">19</a></sup> یا حتی<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_20_171" id="identifier_20_171" class="footnote-link footnote-identifier-link" title="GNU-Darwin">20</a></sup> Darwin/XNU (هستهٔ Mac OS X) استفاده کرد! شما رو نمی‌دونم، ولی این برای من خیلی مهم و هم‌چنین خیلی هیجان‌انگیزه! مثلاً به این فکر کنید که می‌تونید توی محیط آشنا و دوست‌داشتنی دبین، به کامل‌ترین پیاده‌سازی سامانهٔ پروندهٔ<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_21_171" id="identifier_21_171" class="footnote-link footnote-identifier-link" title="File System">21</a></sup> قدرت‌مند <a href="http://en.wikipedia.org/wiki/ZFS">ZFS</a> که توی OpenSolaris هست دست‌رسی داشته باشید.</p>
<p>راستی یادمون نره که اوبونتو<sup><a href="http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/#footnote_22_171" id="identifier_22_171" class="footnote-link footnote-identifier-link" title="Ubuntu">22</a></sup> بچهٔ دبین هست.</p>
<p>این‌جوری‌هاست که بهش می‌گم حضرت دبین!</p>
<ol start="0" class="footnotes"><li id="footnote_0_171" class="footnote">Debian</li><li id="footnote_1_171" class="footnote">Operating System</li><li id="footnote_2_171" class="footnote">Repository</li><li id="footnote_3_171" class="footnote">Package</li><li id="footnote_4_171" class="footnote">Official</li><li id="footnote_5_171" class="footnote">Package Management</li><li id="footnote_6_171" class="footnote">Advanced Packaging Tool</li><li id="footnote_7_171" class="footnote">Stable</li><li id="footnote_8_171" class="footnote">Up-to-date</li><li id="footnote_9_171" class="footnote">Site</li><li id="footnote_10_171" class="footnote">Section</li><li id="footnote_11_171" class="footnote">Dependency</li><li id="footnote_12_171" class="footnote">Plugin</li><li id="footnote_13_171" class="footnote">Architecture</li><li id="footnote_14_171" class="footnote">Linux</li><li id="footnote_15_171" class="footnote">Kernel</li><li id="footnote_16_171" class="footnote"><a href="http://www.debian.org/ports/kfreebsd-gnu/">Debian GNU/kFreeBSD</a></li><li id="footnote_17_171" class="footnote"><a href="http://www.debian.org/ports/netbsd/">Debian GNU/NetBSD</a></li><li id="footnote_18_171" class="footnote"><a href="http://www.debian.org/ports/hurd/">Debian GNU/Hurd</a></li><li id="footnote_19_171" class="footnote"><a href="http://www.nexenta.org/">Nexenta</a></li><li id="footnote_20_171" class="footnote"><a href="http://proclus.gnu-darwin.org/debian.html">GNU-Darwin</a></li><li id="footnote_21_171" class="footnote">File System</li><li id="footnote_22_171" class="footnote">Ubuntu</li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.ebrahim.ir/1387/11/about-magneficence-of-the-great-debian/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>میمون چرب؛ دوست روباه آتشین</title>
		<link>http://blog.ebrahim.ir/1387/09/grease-monkey-a-friend-of-fire-fox/</link>
		<comments>http://blog.ebrahim.ir/1387/09/grease-monkey-a-friend-of-fire-fox/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 22:50:36 +0000</pubDate>
		<dc:creator>ابراهیم</dc:creator>
				<category><![CDATA[رایانه]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Greasemonkey]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ابزار]]></category>
		<category><![CDATA[برنامه‌نویسی]]></category>
		<category><![CDATA[تار]]></category>
		<category><![CDATA[دست‌نوشته]]></category>
		<category><![CDATA[فارسی]]></category>
		<category><![CDATA[مرورگر]]></category>
		<category><![CDATA[نرم‌افزار آزاد]]></category>

		<guid isPermaLink="false">http://blog.ebrahim.ir/?p=123</guid>
		<description><![CDATA[از وقتی با Greasemonkey آشنا شده‌ام توقعم از تار1 خیلی بالا رفته. با این افزونهٔ Firefox می‌شه در طرف مخدوم2، به هر صفحه‌ای کدهای JavaScript دل‌خواه رو اضافه کرد. علاوه بر کلی دست‌نوشتهٔ3 آماده که توی http://userscripts.org براش وجود داره، خودمون هم می‌تونیم به راحتی براش دست‌نوشته بنویسیم. حالا اگر قدرت JavaScript رو بیاری تو [...]]]></description>
			<content:encoded><![CDATA[<p>از وقتی با <a href="https://addons.mozilla.org/firefox/748/">Greasemonkey</a> آشنا شده‌ام توقعم از تار<sup><a href="http://blog.ebrahim.ir/1387/09/grease-monkey-a-friend-of-fire-fox/#footnote_0_123" id="identifier_0_123" class="footnote-link footnote-identifier-link" title="Web">1</a></sup> خیلی بالا رفته.</p>
<p>با این افزونهٔ Firefox می‌شه در طرف مخدوم<sup><a href="http://blog.ebrahim.ir/1387/09/grease-monkey-a-friend-of-fire-fox/#footnote_1_123" id="identifier_1_123" class="footnote-link footnote-identifier-link" title="Client Side">2</a></sup>، به هر صفحه‌ای کدهای JavaScript دل‌خواه رو اضافه کرد. علاوه بر کلی دست‌نوشتهٔ<sup><a href="http://blog.ebrahim.ir/1387/09/grease-monkey-a-friend-of-fire-fox/#footnote_2_123" id="identifier_2_123" class="footnote-link footnote-identifier-link" title="Script">3</a></sup> آماده که توی <a href="http://userscripts.org/">http://userscripts.org</a> براش وجود داره، خودمون هم می‌تونیم به راحتی براش دست‌نوشته بنویسیم. حالا اگر قدرت JavaScript رو بیاری تو ذهنت می‌بینی که چه کارها می‌شه به کمک این میمون چرب (!) کرد.</p>
<p>برای شروع ماجراجویی، کمی از <a href="http://diveintogreasemonkey.org/">http://diveintogreasemonkey.org</a> رو خوندم. نقطهٔ شروع بسیار خوبی بود.</p>
<p>یک دست‌نوشته به نام <a href="http://userscripts.org/scripts/show/38610">فارسنده یا Persianizer</a> که به شیوهٔ بِکَن-بچسبون<sup><a href="http://blog.ebrahim.ir/1387/09/grease-monkey-a-friend-of-fire-fox/#footnote_3_123" id="identifier_3_123" class="footnote-link footnote-identifier-link" title="Copy-Paste">4</a></sup> ساخته‌ام، همهٔ رقم‌های انگلیسی و «ي» و «ك»های عربی توی صفحهٔ بارگذاری شده رو به معادل فارسیشون تبدیل می‌کنه. بس که اون صفحه‌های فارسی پر از «ي» حالم رو بد می‌کنه! فقط موقع استفاده حواست باشه پایگاه‌هایی که قراره فارسنده روشون کار بکنه رو خوب انتخاب کنی؛ پیش‌فرض‌هاش خوب نیستند.</p>
<p>البته یکی از شرایط من (و خیلی‌های دیگر) برای استفاده از یک فن‌آوری، انحصاری نبودنش هست که خوش‌بختانه افزونه‌هایی سازگار با Greasemonkey برای مرورگرهای مهم دیگه (از جمله Konqueror) هم وجود داره.</p>
<p>نکتهٔ پایانی این که اگر کاربر Greasemonkey باشی، افزونهٔ <a href="https://addons.mozilla.org/firefox/addon/8352">Greasefire</a> هم احتمالاً برات جالب هست.</p>
<p>این هم فهرست دست‌نوشته‌های محبوب من:<br />
<a href="http://userscripts.org/users/73214/favorites">http://userscripts.org/users/73214/favorites</a></p>
<ol class="footnotes"><li id="footnote_0_123" class="footnote">Web</li><li id="footnote_1_123" class="footnote">Client Side</li><li id="footnote_2_123" class="footnote">Script</li><li id="footnote_3_123" class="footnote">Copy-Paste</li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.ebrahim.ir/1387/09/grease-monkey-a-friend-of-fire-fox/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>از پیغام‌های خطای STL نجات یافتم</title>
		<link>http://blog.ebrahim.ir/1387/09/got-rid-of-stl-error-messages/</link>
		<comments>http://blog.ebrahim.ir/1387/09/got-rid-of-stl-error-messages/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 21:51:30 +0000</pubDate>
		<dc:creator>ابراهیم</dc:creator>
				<category><![CDATA[رایانه]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[C++‎]]></category>
		<category><![CDATA[STL]]></category>
		<category><![CDATA[ابزار]]></category>
		<category><![CDATA[برنامه‌نویسی]]></category>
		<category><![CDATA[دست‌نوشته]]></category>
		<category><![CDATA[نرم‌افزار آزاد]]></category>
		<category><![CDATA[هم‌گردان]]></category>

		<guid isPermaLink="false">http://blog.ebrahim.ir/?p=70</guid>
		<description><![CDATA[اگر برنامه‌نویس C++‎ باشی، حتماً تا حالا مورد آزار و اذیت پیغام‌های خطای سرسام‌آور هم‌گردان0 در مورد STL قرار گرفته‌ای. مثلاً این: testmm2.cpp:31: error: no matching function for call to ‘std::multimap&#60;int*, int, std::less&#60;int*&#62;, std::allocator&#60;std::pair&#60;int* const, int&#62; &#62; &#62;::insert(int)’ /usr/include/c++/4.3/bits/stl_multimap.h:407: note: candidates are: typename std::_Rb_tree&#60;_Key, std::pair&#60;const _Key, _Tp&#62;, std::_Select1st&#60;std::pair&#60;const_Key, _Tp&#62; &#62;, _Compare, typename _Alloc::rebind&#60;std::pair&#60;const _Key, _Tp&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><!--startnum=0--></p>
<p>اگر برنامه‌نویس C++‎ باشی، حتماً تا حالا مورد آزار و اذیت پیغام‌های خطای سرسام‌آور هم‌گردان<sup><a href="http://blog.ebrahim.ir/1387/09/got-rid-of-stl-error-messages/#footnote_0_70" id="identifier_0_70" class="footnote-link footnote-identifier-link" title="Compiler">0</a></sup> در مورد STL قرار گرفته‌ای. مثلاً این:</p>

<div class="wp_syntax" dir="ltr"><div class="code"><pre class="none" style="font-family:monospace;">testmm2.cpp:31: error: no matching function for call to ‘std::multimap&lt;int*, int, std::less&lt;int*&gt;, std::allocator&lt;std::pair&lt;int* const, int&gt; &gt; &gt;::insert(int)’
/usr/include/c++/4.3/bits/stl_multimap.h:407: note: candidates are: typename std::_Rb_tree&lt;_Key, std::pair&lt;const _Key, _Tp&gt;, std::_Select1st&lt;std::pair&lt;const_Key, _Tp&gt; &gt;, _Compare, typename _Alloc::rebind&lt;std::pair&lt;const _Key, _Tp&gt; &gt;::other&gt;::iterator std::multimap&lt;_Key, _Tp, _Compare, _Alloc&gt;::insert(const std::pair&lt;const _Key, _Tp&gt;&amp;) [with _Key = int*, _Tp = int, _Compare = std::less&lt;int*&gt;, _Alloc = std::allocator&lt;std::pair&lt;int* const, int&gt; &gt;]
/usr/include/c++/4.3/bits/stl_multimap.h:431: note:                 typename std::_Rb_tree&lt;_Key, std::pair&lt;const _Key, _Tp&gt;, std::_Select1st&lt;std::pair&lt;const _Key, _Tp&gt; &gt;, _Compare, typename _Alloc::rebind&lt;std::pair&lt;const _Key, _Tp&gt; &gt;::other&gt;::iterator std::multimap&lt;_Key, _Tp, _Compare, _Alloc&gt;::insert(typename std::_Rb_tree&lt;_Key, std::pair&lt;const _Key, _Tp&gt;, std::_Select1st&lt;std::pair&lt;const _Key, _Tp&gt; &gt;, _Compare, typename _Alloc::rebind&lt;std::pair&lt;const _Key, _Tp&gt; &gt;::other&gt;::iterator, const std::pair&lt;const _Key, _Tp&gt;&amp;) [with _Key = int*, _Tp = int, _Compare = std::less&lt;int*&gt;, _Alloc = std::allocator&lt;std::pair&lt;int* const, int&gt; &gt;]</pre></div></div>

<p>‎<br />
حالا این یکی بود. وقتی ده-پونزده تا از این‌ها یک‌جا رخ می‌ده، خیلی افتضاح می‌شه.</p>
<p>مدت‌ها با این مشکل کنار اومده بودم و دردش رو تحمل می‌کردم. اما اخیراً یک راه نجات یافتم: ابزاری  به نام <a href="http://www.bdsoft.com/tools/stlfilt.html">STLFilt</a>. یک نرم‌افزار آزاد هست که خروجی هم‌گردان C++‎ رو می‌گیره و اون پیغام‌های وحشت‌ناک رو مهربون می‌کنه. مثلاً پیغام بالا رو تبدیل می‌کنه به این:</p>

<div class="wp_syntax" dir="ltr"><div class="code"><pre class="none" style="font-family:monospace;">testmm2.cpp:31: error: No match for ‘multimap&lt;int *, int&gt;::insert(int)’
stl_multimap.h:407: candidates are: map&lt;int *, int&gt;::iter multimap&lt;int *, int&gt;
    ::insert(const pair&lt;const int *, int&gt; &amp;)
stl_multimap.h:431: map&lt;
        int *, int
    &gt;::iter multimap&lt;
        int *, int
    &gt;::insert(map&lt;int *, int&gt;::iter, const pair&lt;const int *, int&gt; &amp;)</pre></div></div>

<p>آخش! حالا می‌شه خوندش!</p>
<p>برای استفاده از STLFilt اول باید بستهٔ مربوط به هم‌گردانت رو بگیری. مثلاً gstlfilt.zip برای G++‎. توش کلی پرونده هست که همه رو بی‌خیال می‌شی به جز gSTLFilt.pl که اصل کار رو انجام می‌ده. از stdin می‌خونه و توی stdout می‌نویسه. کاری که من کردم این بود<sup><a href="http://blog.ebrahim.ir/1387/09/got-rid-of-stl-error-messages/#footnote_1_70" id="identifier_1_70" class="footnote-link footnote-identifier-link" title="مثل همیشه نقل به مضمون و آزمایش&zwnj;نشده">1</a></sup>:</p>

<div class="wp_syntax" dir="ltr"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span>
<span style="color: #007800;">F</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>stlfilt.pl
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'#!/usr/bin/perl'</span> <span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #007800;">$F</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> gSTLFilt.pl <span style="color: #000000; font-weight: bold;">&gt;&gt;</span><span style="color: #007800;">$F</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #007800;">$F</span></pre></div></div>

<p>و برای استفاده:</p>

<div class="wp_syntax" dir="ltr"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> stlfilt.pl</pre></div></div>

<p>برای این که هر بار نخوام stderr دستور ساخت<sup><a href="http://blog.ebrahim.ir/1387/09/got-rid-of-stl-error-messages/#footnote_2_70" id="identifier_2_70" class="footnote-link footnote-identifier-link" title="Build">2</a></sup> (مثلاً make)  رو به stdoutش redirect<sup><a href="http://blog.ebrahim.ir/1387/09/got-rid-of-stl-error-messages/#footnote_3_70" id="identifier_3_70" class="footnote-link footnote-identifier-link" title="معادل خوبی براش داری بگو">3</a></sup> کنم، دست‌نوشتهٔ<sup><a href="http://blog.ebrahim.ir/1387/09/got-rid-of-stl-error-messages/#footnote_4_70" id="identifier_4_70" class="footnote-link footnote-identifier-link" title="Script">4</a></sup> <code>/usr/local/bin/stlfilt</code> رو با این محتوا ساختم:</p>

<div class="wp_syntax" dir="ltr"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #ff0000;">&quot;$@&quot;</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> stlfilt.pl</pre></div></div>

<p>و <code>chmod +x</code> هم یادم نره. <img src='http://blog.ebrahim.ir/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
حالا این‌جوری استفاده می‌شه:</p>

<div class="wp_syntax" dir="ltr"><div class="code"><pre class="bash" style="font-family:monospace;">stlfilt <span style="color: #c20cb9; font-weight: bold;">make</span></pre></div></div>

<p>با دست‌نوشته‌ها زندگی زیباتره! <img src='http://blog.ebrahim.ir/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>ویرایش: امید آن می‌رود که با معرفی «مفهوم»<sup><a href="http://blog.ebrahim.ir/1387/09/got-rid-of-stl-error-messages/#footnote_5_70" id="identifier_5_70" class="footnote-link footnote-identifier-link" title="Concept">5</a></sup>ها در C++0x (به زودی!) کل مشکل از بیخ حل بشه و دیگه نیازی به ابزار اضافی نباشه.</p>
<ol start="0" class="footnotes"><li id="footnote_0_70" class="footnote">Compiler</li><li id="footnote_1_70" class="footnote">مثل همیشه نقل به مضمون و آزمایش‌نشده</li><li id="footnote_2_70" class="footnote">Build</li><li id="footnote_3_70" class="footnote">معادل خوبی براش داری بگو</li><li id="footnote_4_70" class="footnote">Script</li><li id="footnote_5_70" class="footnote">Concept</li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.ebrahim.ir/1387/09/got-rid-of-stl-error-messages/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)

Served from: blog.ebrahim.ir @ 2012-02-07 00:09:27 -->
