  
<div id="snippet_276" class="snippet">
  <h2><a href="/snippets/276-How-to-create-a-separate-development-profile-for-Firefox" title="How to create a separate development profile for Firefox - Shell Script (Bash) - firefox, development, profile, mode">How to create a separate development profile for Firefox</a></h2>
  <div class="details">
    <a style="background-color: #FFFF94;" href="http://snippets.aktagon.com/languages/131-Shell-Script-Bash-">
      Shell Script (Bash)</a> posted about 1 year ago by christian
          
  </div>

  <div class="body">
    <p>Extensions slow down Firefox so I prefer disabling all but the most important Firefox extensions when coding.</p>
<p>Here&#8217;s how to do it:</p>
<ol>
	<li>First, create a development profile following these instructions <a href="http://support.mozilla.com/en-US/kb/Managing+profiles">http://support.mozilla.com/en-US/kb/Managing+profiles</a></li>
</ol>
<ol>
	<li>Next, create a shortcut that starts Firefox in development mode:</li>
</ol>
<p><pre class="active4d"><span class="line-numbers">   1 </span> <span class="LineComment"><span class="LineComment">#</span> Mac OSX</span>
<span class="line-numbers">   2 </span> /Applications/Firefox.app/Contents/MacOS/firefox-bin -P development -no-remote
<span class="line-numbers">   3 </span> 
<span class="line-numbers">   4 </span> <span class="LineComment"><span class="LineComment">#</span> Linux</span>
<span class="line-numbers">   5 </span> /usr/lib/firefox/firefox-bin -P development -no-remote
<span class="line-numbers">   6 </span> 
<span class="line-numbers">   7 </span> <span class="LineComment"><span class="LineComment">#</span> Windblows</span>
<span class="line-numbers">   8 </span> <span class="String"><span class="String">&quot;</span>C:\Program Files\Mozilla Firefox\firefox.exe<span class="String">&quot;</span></span> -P development -no-remote
</pre></p>
  </div>

  <div style="font-size: 0.8em;margin:0.5em;">
    
      Tagged <a href="/tags/289-firefox">firefox</a>, <a href="/tags/424-development">development</a>, <a href="/tags/581-profile">profile</a>, <a href="/tags/612-mode">mode</a>
    
    
  </div>
</div>



  
<div id="snippet_255" class="snippet">
  <h2><a href="/snippets/255-How-to-profile-your-Rails-and-Ruby-applications-with-ruby-prof" title="How to profile your Rails and Ruby applications with ruby-prof - Ruby - ruby-prof, rails, gem, profiling, benchmark, profile, kcachegrind">How to profile your Rails and Ruby applications with ruby-prof</a></h2>
  <div class="details">
    <a style="background-color: #FFFF94;" href="http://snippets.aktagon.com/languages/124-Ruby">
      Ruby</a> posted about 1 year ago by christian
          
  </div>

  <div class="body">
    <h2>Installing ruby-prof</h2>
<p>First install <a href="http://ruby-prof.rubyforge.org/">ruby-prof</a>:</p>
<p><pre class="active4d"><span class="line-numbers">   1 </span> git clone git<span class="UserDefinedConstant"><span class="UserDefinedConstant">:</span>/</span><span class="Operator">/</span>github.<span class="FunctionName">com</span><span class="Operator">/</span>jeremy<span class="Operator">/</span>ruby<span class="Operator">-</span>prof.<span class="FunctionName">git</span>
<span class="line-numbers">   2 </span> cd ruby<span class="Operator">-</span>prof<span class="Operator">/</span>
<span class="line-numbers">   3 </span> rake gem
<span class="line-numbers">   4 </span> sudo gem install pkg<span class="Operator">/</span>ruby<span class="Operator">-</span>prof<span class="Operator">-</span><span class="Number">0.6</span>.<span class="Number">1</span>.<span class="FunctionName">gem</span>
</pre></p>
<p>Note that version 0.6.0 doesn&#8217;t work, at least not with Rails 2.1.1. With 0.6.0 I got this message:</p>
<p><pre class="active4d"><span class="line-numbers">   1 </span> <span class="String"><span class="String">`</span>gem install ruby-prof<span class="String">`</span></span> to use the profiler
</pre></p>
<h2>Setting up a new environment for profiling</h2>
<p>Create <strong>config/environments/profiling.rb</strong>:</p>
<p><pre class="active4d"><span class="line-numbers">   1 </span> config.<span class="FunctionName">cache_classes</span> <span class="Operator">=</span> <span class="BuiltInConstant">true</span>
<span class="line-numbers">   2 </span> config.<span class="FunctionName">action_controller</span>.<span class="FunctionName">consider_all_requests_local</span> <span class="Operator">=</span> <span class="BuiltInConstant">false</span>
<span class="line-numbers">   3 </span> config.<span class="FunctionName">action_controller</span>.<span class="FunctionName">perform_caching</span>             <span class="Operator">=</span> <span class="BuiltInConstant">true</span>
<span class="line-numbers">   4 </span> config.<span class="FunctionName">action_view</span>.<span class="FunctionName">cache_template_loading</span>            <span class="Operator">=</span> <span class="BuiltInConstant">true</span>
<span class="line-numbers">   5 </span> 
<span class="line-numbers">   6 </span> <span class="LineComment"><span class="LineComment">#</span>config.log_level = :debug</span>
</pre></p>
<p>Add the new environment to database.yml. You might want to reuse the development database.</p>
<h2>Creating a profiling script</h2>
<p>Next we&#8217;ll create a script that simply fetches the homepage, save the following code in <strong>profiling/homepage.rb</strong>:</p>
<p><pre class="active4d"><span class="line-numbers">   1 </span> get <span class="String"><span class="String">'</span>/<span class="String">'</span></span>
<span class="line-numbers">   2 </span> say <span class="String"><span class="String">&quot;</span>GET / =&gt; <span class="String"><span class="String">#{</span>path<span class="String">}</span></span><span class="String">&quot;</span></span>
</pre></p>
<h2>Run the script</h2>
<p>Now run the script 100 times:</p>
<p><pre class="active4d"><span class="line-numbers">   1 </span> <span class="Variable">RAILS_ENV</span><span class="Operator">=</span>profiling .<span class="Operator">/</span>script<span class="Operator">/</span>performance<span class="Operator">/</span>request <span class="Operator">-</span>n <span class="Number">100</span> profiling<span class="Operator">/</span>homepage.<span class="FunctionName">rb</span>
</pre></p>
<h2>Profiling plain Ruby applications</h2>
<p>You can also profile a block of code by <a href="http://ruby-prof.rubyforge.org/">calling RubyProf from your code</a>:</p>
<p><pre class="active4d"><span class="line-numbers">   1 </span> <span class="Keyword">require</span> <span class="String"><span class="String">'</span>ruby-prof<span class="String">'</span></span>
<span class="line-numbers">   2 </span> 
<span class="line-numbers">   3 </span> <span class="LineComment"><span class="LineComment">#</span> Profile the code</span>
<span class="line-numbers">   4 </span> <span class="LibraryClassType">RubyProf</span>.<span class="FunctionName">start</span>
<span class="line-numbers">   5 </span> ...
<span class="line-numbers">   6 </span> [code to profile]
<span class="line-numbers">   7 </span> ...
<span class="line-numbers">   8 </span> results <span class="Operator">=</span> <span class="LibraryClassType">RubyProf</span>.<span class="FunctionName">stop</span>
<span class="line-numbers">   9 </span> 
<span class="line-numbers">  10 </span> <span class="LibraryClassType">File</span>.<span class="FunctionName">open</span> <span class="String"><span class="String">&quot;</span><span class="String"><span class="String">#{</span><span class="Variable">RAILS_ROOT</span><span class="String">}</span></span>/tmp/profile-graph.html<span class="String">&quot;</span></span>, <span class="String"><span class="String">'</span>w<span class="String">'</span></span> <span class="Keyword">do </span>|<span class="Variable">file</span>|
<span class="line-numbers">  11 </span>   <span class="LibraryClassType">RubyProf</span>::<span class="FunctionName">GraphHtmlPrinter</span>.<span class="FunctionName">new</span>(results).<span class="FunctionName">print</span>(file)
<span class="line-numbers">  12 </span> <span class="Keyword">end</span>
<span class="line-numbers">  13 </span> 
<span class="line-numbers">  14 </span> <span class="LibraryClassType">File</span>.<span class="FunctionName">open</span> <span class="String"><span class="String">&quot;</span><span class="String"><span class="String">#{</span><span class="Variable">RAILS_ROOT</span><span class="String">}</span></span>/tmp/profile-flat.txt<span class="String">&quot;</span></span>, <span class="String"><span class="String">'</span>w<span class="String">'</span></span> <span class="Keyword">do </span>|<span class="Variable">file</span>|
<span class="line-numbers">  15 </span>   <span class="LibraryClassType">RubyProf</span>::<span class="FunctionName">FlatPrinter</span>.<span class="FunctionName">new</span>(results).<span class="FunctionName">print</span>(file)
<span class="line-numbers">  16 </span> <span class="Keyword">end</span>
<span class="line-numbers">  17 </span> 
<span class="line-numbers">  18 </span> <span class="LibraryClassType">File</span>.<span class="FunctionName">open</span> <span class="String"><span class="String">&quot;</span><span class="String"><span class="String">#{</span><span class="Variable">RAILS_ROOT</span><span class="String">}</span></span>/tmp/profile-tree.prof<span class="String">&quot;</span></span>, <span class="String"><span class="String">'</span>w<span class="String">'</span></span> <span class="Keyword">do </span>|<span class="Variable">file</span>|
<span class="line-numbers">  19 </span>   <span class="LibraryClassType">RubyProf</span>::<span class="FunctionName">CallTreePrinter</span>.<span class="FunctionName">new</span>(results).<span class="FunctionName">print</span>(file)
<span class="line-numbers">  20 </span> <span class="Keyword">end</span>
</pre></p>
<h2>Analyzing results</h2>
<p>I prefer to use the RubyProf::CallTreePrinter to output data that <a href="http://kcachegrind.sourceforge.net/">kcachegrind</a> can read. The <span class="caps">HTML</span> and text data is difficult to read so kcachegrind will definitely make your life easier.</p>
<p>On <span class="caps">OSX</span> you can install kcachegrind with <a href="http://www.finkproject.org/download/index.php?phpLang=en">Fink</a> (or DarwinPorts):</p>
<p><pre class="active4d"><span class="line-numbers">   1 </span> sudo apt<span class="Operator">-</span>get update ; sudo apt<span class="Operator">-</span>get install fink
<span class="line-numbers">   2 </span> sudo apt<span class="Operator">-</span>get install kcachegrind
</pre></p>
<p>There&#8217;s also WinCacheGrind and MacCacheGrind, but I haven&#8217;t tried those.</p>
  </div>

  <div style="font-size: 0.8em;margin:0.5em;">
    
      Tagged <a href="/tags/579-ruby-prof">ruby-prof</a>, <a href="/tags/9-rails">rails</a>, <a href="/tags/325-gem">gem</a>, <a href="/tags/580-profiling">profiling</a>, <a href="/tags/192-benchmark">benchmark</a>, <a href="/tags/581-profile">profile</a>, <a href="/tags/619-kcachegrind">kcachegrind</a>
    
    
  </div>
</div>



  
<div id="snippet_261" class="snippet">
  <h2><a href="/snippets/261-How-to-start-Firefox-with-a-different-profile-on-OSX" title="How to start Firefox with a different profile on OSX - Plain Text - osx, firefox, profile">How to start Firefox with a different profile on OSX</a></h2>
  <div class="details">
    <a style="background-color: #FFFF94;" href="http://snippets.aktagon.com/languages/103-Plain-Text">
      Plain Text</a> posted about 1 year ago by christian
          
  </div>

  <div class="body">
    <p><pre class="active4d"><span class="line-numbers">   1 </span> # Start the development profile
<span class="line-numbers">   2 </span> /Applications/Firefox.app/Contents/MacOS/firefox-bin -P 'development'
<span class="line-numbers">   3 </span> # Choose the profile manually
<span class="line-numbers">   4 </span> /Applications/Firefox.app/Contents/MacOS/firefox-bin -ProfileManager
</pre></p>
  </div>

  <div style="font-size: 0.8em;margin:0.5em;">
    
      Tagged <a href="/tags/198-osx">osx</a>, <a href="/tags/289-firefox">firefox</a>, <a href="/tags/581-profile">profile</a>
    
    
  </div>
</div>






