Skip to content

Commit d8b1432

Browse files
committed
1 parent cb9aacc commit d8b1432

File tree

14 files changed

+679
-126
lines changed

14 files changed

+679
-126
lines changed

404.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,33 @@
334334

335335

336336

337+
<li class="md-nav__item">
338+
<a href="/best-practices.md" class="md-nav__link">
339+
340+
341+
342+
<span class="md-ellipsis">
343+
344+
345+
Best Practices
346+
347+
348+
349+
</span>
350+
351+
352+
353+
</a>
354+
</li>
355+
356+
357+
358+
359+
360+
361+
362+
363+
337364
<li class="md-nav__item">
338365
<a href="/profiling-rails/" class="md-nav__link">
339366

advanced-usage/index.html

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,33 @@
509509

510510

511511

512+
<li class="md-nav__item">
513+
<a href="../best-practices.md" class="md-nav__link">
514+
515+
516+
517+
<span class="md-ellipsis">
518+
519+
520+
Best Practices
521+
522+
523+
524+
</span>
525+
526+
527+
528+
</a>
529+
</li>
530+
531+
532+
533+
534+
535+
536+
537+
538+
512539
<li class="md-nav__item">
513540
<a href="../profiling-rails/" class="md-nav__link">
514541

@@ -800,7 +827,7 @@
800827

801828

802829
<h1 id="advanced-usage">Advanced Usage<a class="headerlink" href="#advanced-usage" title="Permanent link">&para;</a></h1>
803-
<p>This section describes advanced usage of ruby-prof. Additional documentation for every class is also <a href="../#api-documentation">available</a>.</p>
830+
<p>This section describes advanced usage of ruby-prof. Additional documentation for every class is also <a href="../#api-documentation">available</a>. For workflow guidance, see <a href="../best-practices/">Best Practices</a>.</p>
804831
<h2 id="profiling-options">Profiling Options<a class="headerlink" href="#profiling-options" title="Permanent link">&para;</a></h2>
805832
<p>ruby-prof understands the following options when profiling code:</p>
806833
<p><strong>measure_mode</strong> - What ruby-prof should measure. For more information see the <a href="#measurement-mode">Measurement Mode</a> section.</p>
@@ -831,13 +858,13 @@ <h2 id="allocation-tracking">Allocation Tracking<a class="headerlink" href="#all
831858
<p>ruby-prof also has the ability to track object allocations. This functionality can be turned on via the track_allocations option:</p>
832859
<div class="language-ruby highlight"><pre><span></span><code><span id="__span-2-1"><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a><span class="nb">require</span><span class="w"> </span><span class="s1">&#39;ruby-prof&#39;</span>
833860
</span><span id="__span-2-2"><a id="__codelineno-2-2" name="__codelineno-2-2" href="#__codelineno-2-2"></a>
834-
</span><span id="__span-2-3"><a id="__codelineno-2-3" name="__codelineno-2-3" href="#__codelineno-2-3"></a><span class="no">RubyProf</span><span class="o">::</span><span class="no">Profile</span><span class="o">.</span><span class="n">profile</span><span class="p">(</span><span class="ss">:track_allocations</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="kp">true</span><span class="p">)</span><span class="w"> </span><span class="k">do</span>
861+
</span><span id="__span-2-3"><a id="__codelineno-2-3" name="__codelineno-2-3" href="#__codelineno-2-3"></a><span class="no">RubyProf</span><span class="o">::</span><span class="no">Profile</span><span class="o">.</span><span class="n">profile</span><span class="p">(</span><span class="ss">track_allocations</span><span class="p">:</span><span class="w"> </span><span class="kp">true</span><span class="p">)</span><span class="w"> </span><span class="k">do</span>
835862
</span><span id="__span-2-4"><a id="__codelineno-2-4" name="__codelineno-2-4" href="#__codelineno-2-4"></a><span class="w"> </span><span class="o">...</span>
836863
</span><span id="__span-2-5"><a id="__codelineno-2-5" name="__codelineno-2-5" href="#__codelineno-2-5"></a><span class="k">end</span>
837864
</span></code></pre></div>
838-
<p>Note the <code>RubyProf::ALLOCATIONS</code> measure mode is slightly different than tracking allocations. The measurement mode provides high level information about the number of allocations performed in each method. In contrast, tracking allocations provides detailed information about the type, number, memory usage and location of each allocation. Currently, to see allocations results you must use the <code>RubyProf::GraphHtmlPrinter</code>.</p>
865+
<p>Note the <code>RubyProf::ALLOCATIONS</code> measure mode is slightly different than tracking allocations. The measurement mode provides high level information about the number of allocations performed in each method. In contrast, tracking allocations provides detailed information about allocation type, count, and source location. Currently, to see allocations results you must use the <code>RubyProf::GraphHtmlPrinter</code>.</p>
839866
<h2 id="thread-inclusionexclusion">Thread Inclusion/Exclusion<a class="headerlink" href="#thread-inclusionexclusion" title="Permanent link">&para;</a></h2>
840-
<p>ruby-prof can profile multiple threads. Sometimes this can be overwhelming. For example, assume you want to determine why your tests are running slowly. If you are using minitest, it will run your tests in parallel by spawning tens of worker threads (note to tell minitest to use a single thread set the N environmental variable like this ENV = 0). Thus, ruby-prof provides two options to specify which threads should be profiled:</p>
867+
<p>ruby-prof can profile multiple threads. Sometimes this can be overwhelming. For example, assume you want to determine why your tests are running slowly. If you are using minitest, it can run tests in parallel by spawning worker threads (to force a single worker, set <code>N=0</code> when running tests). Thus, ruby-prof provides two options to specify which threads should be profiled:</p>
841868
<p><strong>exclude_threads</strong> - Array of threads which should not be profiled.</p>
842869
<p><strong>include_threads</strong> - Array of threads which should be profiled. All other threads will be ignored.</p>
843870
<h2 id="method-exclusion">Method Exclusion<a class="headerlink" href="#method-exclusion" title="Permanent link">&para;</a></h2>
@@ -861,7 +888,7 @@ <h2 id="merging-threads-and-fibers">Merging Threads and Fibers<a class="headerli
861888
</span><span id="__span-5-4"><a id="__codelineno-5-4" name="__codelineno-5-4" href="#__codelineno-5-4"></a><span class="n">profile</span><span class="o">.</span><span class="n">merge!</span>
862889
</span></code></pre></div>
863890
<p>This is also supported in the Rack adapter via the <code>merge_fibers</code> option:</p>
864-
<div class="language-ruby highlight"><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="n">config</span><span class="o">.</span><span class="n">middleware</span><span class="o">.</span><span class="n">use</span><span class="w"> </span><span class="no">Rack</span><span class="o">::</span><span class="no">RubyProf</span><span class="p">,</span><span class="w"> </span><span class="ss">path</span><span class="p">:</span><span class="w"> </span><span class="s1">&#39;./tmp/profile&#39;</span><span class="p">,</span><span class="w"> </span><span class="ss">merge_fibers</span><span class="p">:</span><span class="w"> </span><span class="kp">true</span>
891+
<div class="language-ruby highlight"><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="n">config</span><span class="o">.</span><span class="n">middleware</span><span class="o">.</span><span class="n">use</span><span class="w"> </span><span class="no">Rack</span><span class="o">::</span><span class="no">RubyProf</span><span class="p">,</span><span class="w"> </span><span class="ss">path</span><span class="p">:</span><span class="w"> </span><span class="no">Rails</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s2">&quot;tmp/profile&quot;</span><span class="p">),</span><span class="w"> </span><span class="ss">merge_fibers</span><span class="p">:</span><span class="w"> </span><span class="kp">true</span>
865892
</span></code></pre></div>
866893
<h2 id="saving-results">Saving Results<a class="headerlink" href="#saving-results" title="Permanent link">&para;</a></h2>
867894
<p>It can be helpful to save the results of a profiling run for later analysis. Results can be saved using Ruby's <a href="https://docs.ruby-lang.org/en/master/Marshal.html">marshal</a> library.</p>

alternatives/index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,33 @@
345345

346346

347347

348+
<li class="md-nav__item">
349+
<a href="../best-practices.md" class="md-nav__link">
350+
351+
352+
353+
<span class="md-ellipsis">
354+
355+
356+
Best Practices
357+
358+
359+
360+
</span>
361+
362+
363+
364+
</a>
365+
</li>
366+
367+
368+
369+
370+
371+
372+
373+
374+
348375
<li class="md-nav__item">
349376
<a href="../profiling-rails/" class="md-nav__link">
350377

architecture/index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,33 @@
345345

346346

347347

348+
<li class="md-nav__item">
349+
<a href="../best-practices.md" class="md-nav__link">
350+
351+
352+
353+
<span class="md-ellipsis">
354+
355+
356+
Best Practices
357+
358+
359+
360+
</span>
361+
362+
363+
364+
</a>
365+
</li>
366+
367+
368+
369+
370+
371+
372+
373+
374+
348375
<li class="md-nav__item">
349376
<a href="../profiling-rails/" class="md-nav__link">
350377

changelog/index.html

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,33 @@
343343

344344

345345

346+
<li class="md-nav__item">
347+
<a href="../best-practices.md" class="md-nav__link">
348+
349+
350+
351+
<span class="md-ellipsis">
352+
353+
354+
Best Practices
355+
356+
357+
358+
</span>
359+
360+
361+
362+
</a>
363+
</li>
364+
365+
366+
367+
368+
369+
370+
371+
372+
346373
<li class="md-nav__item">
347374
<a href="../profiling-rails/" class="md-nav__link">
348375

@@ -513,15 +540,15 @@
513540
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
514541

515542
<li class="md-nav__item">
516-
<a href="#200-2026-02-11" class="md-nav__link">
543+
<a href="#200-2026-02-12" class="md-nav__link">
517544
<span class="md-ellipsis">
518545

519-
2.0.0 (2026-02-11)
546+
2.0.0 (2026-02-12)
520547

521548
</span>
522549
</a>
523550

524-
<nav class="md-nav" aria-label="2.0.0 (2026-02-11)">
551+
<nav class="md-nav" aria-label="2.0.0 (2026-02-12)">
525552
<ul class="md-nav__list">
526553

527554
<li class="md-nav__item">
@@ -1614,15 +1641,15 @@
16141641
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
16151642

16161643
<li class="md-nav__item">
1617-
<a href="#200-2026-02-11" class="md-nav__link">
1644+
<a href="#200-2026-02-12" class="md-nav__link">
16181645
<span class="md-ellipsis">
16191646

1620-
2.0.0 (2026-02-11)
1647+
2.0.0 (2026-02-12)
16211648

16221649
</span>
16231650
</a>
16241651

1625-
<nav class="md-nav" aria-label="2.0.0 (2026-02-11)">
1652+
<nav class="md-nav" aria-label="2.0.0 (2026-02-12)">
16261653
<ul class="md-nav__list">
16271654

16281655
<li class="md-nav__item">
@@ -2698,7 +2725,7 @@
26982725

26992726

27002727
<h1 id="changelog">Changelog<a class="headerlink" href="#changelog" title="Permanent link">&para;</a></h1>
2701-
<h2 id="200-2026-02-11">2.0.0 (2026-02-11)<a class="headerlink" href="#200-2026-02-11" title="Permanent link">&para;</a></h2>
2728+
<h2 id="200-2026-02-12">2.0.0 (2026-02-12)<a class="headerlink" href="#200-2026-02-12" title="Permanent link">&para;</a></h2>
27022729
<h3 id="features">Features<a class="headerlink" href="#features" title="Permanent link">&para;</a></h3>
27032730
<ul>
27042731
<li>Ruby 4.0 support.</li>
@@ -2712,7 +2739,7 @@ <h3 id="features">Features<a class="headerlink" href="#features" title="Permanen
27122739
<h3 id="backwards-incompatible-changes">Backwards Incompatible Changes<a class="headerlink" href="#backwards-incompatible-changes" title="Permanent link">&para;</a></h3>
27132740
<ul>
27142741
<li>Removed <code>RubyProf::MEMORY</code> measurement mode (no longer works on Ruby 4.0+)</li>
2715-
<li>Finally remove compatibility API that was scheduled for removal in 2023</li>
2742+
<li>Finally removed compatibility API that was scheduled for removal in 2023</li>
27162743
<li>Printer options now use keyword arguments instead of an options hash. For example:
27172744
<div class="language-ruby highlight"><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="c1"># Before:</span>
27182745
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="n">printer</span><span class="o">.</span><span class="n">print</span><span class="p">(</span><span class="no">STDOUT</span><span class="p">,</span><span class="w"> </span><span class="ss">:min_percent</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="ss">:sort_method</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="ss">:self_time</span><span class="p">)</span>

getting-started/index.html

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,33 @@
426426

427427

428428

429+
<li class="md-nav__item">
430+
<a href="../best-practices.md" class="md-nav__link">
431+
432+
433+
434+
<span class="md-ellipsis">
435+
436+
437+
Best Practices
438+
439+
440+
441+
</span>
442+
443+
444+
445+
</a>
446+
</li>
447+
448+
449+
450+
451+
452+
453+
454+
455+
429456
<li class="md-nav__item">
430457
<a href="../profiling-rails/" class="md-nav__link">
431458

@@ -717,16 +744,17 @@ <h2 id="core-api">Core API<a class="headerlink" href="#core-api" title="Permanen
717744
<p>To create a new profile:</p>
718745
<div class="language-ruby highlight"><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="nb">require</span><span class="w"> </span><span class="s1">&#39;ruby-prof&#39;</span>
719746
</span><span id="__span-6-2"><a id="__codelineno-6-2" name="__codelineno-6-2" href="#__codelineno-6-2"></a>
720-
</span><span id="__span-6-3"><a id="__codelineno-6-3" name="__codelineno-6-3" href="#__codelineno-6-3"></a><span class="n">profile</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="no">RubyProf</span><span class="o">::</span><span class="no">Profile</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">options</span><span class="p">)</span>
747+
</span><span id="__span-6-3"><a id="__codelineno-6-3" name="__codelineno-6-3" href="#__codelineno-6-3"></a><span class="n">profile</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="no">RubyProf</span><span class="o">::</span><span class="no">Profile</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="ss">measure_mode</span><span class="p">:</span><span class="w"> </span><span class="no">RubyProf</span><span class="o">::</span><span class="no">WALL_TIME</span><span class="p">)</span>
721748
</span><span id="__span-6-4"><a id="__codelineno-6-4" name="__codelineno-6-4" href="#__codelineno-6-4"></a><span class="n">result</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">profile</span><span class="o">.</span><span class="n">profile</span><span class="w"> </span><span class="k">do</span>
722749
</span><span id="__span-6-5"><a id="__codelineno-6-5" name="__codelineno-6-5" href="#__codelineno-6-5"></a><span class="w"> </span><span class="o">...</span>
723750
</span><span id="__span-6-6"><a id="__codelineno-6-6" name="__codelineno-6-6" href="#__codelineno-6-6"></a><span class="w"> </span><span class="k">end</span>
724751
</span></code></pre></div>
725-
<p>Once a profile is completed, you can either generate a <a href="../reports/">report</a> via a printer or <a href="../advanced-usage/#saving-results">save</a> the results for later analysis. For a list of profiling options, please see the <a href="../advanced-usage/#profiling-options">Profiling Options</a> section.</p>
752+
<p>Once a profile is completed, you can either generate a <a href="../reports/">report</a> via a printer or <a href="../advanced-usage/#saving-results">save</a> the results for later analysis. For a list of profiling options, please see the <a href="../advanced-usage/#profiling-options">Profiling Options</a> section.
753+
If you are unsure which report to generate first, see <a href="../reports/#choosing-a-report">Choosing a Report</a>.</p>
726754
<p>However, using ruby-prof also comes with two caveats:</p>
727755
<ul>
728756
<li>To use ruby-prof you generally need to include a few lines of extra code in your program (although see <a href="../getting-started/#command-line">command line usage</a>)</li>
729-
<li>Using ruby-prof will cause your program to run slower (see <a href="#performance">Performance</a> section)</li>
757+
<li>Using ruby-prof will cause your program to run slower (see <a href="../#performance">Performance</a> section)</li>
730758
</ul>
731759
<p>Most of the time, these two caveats are acceptable. But if you need to determine why a program running in production is slow or hung, a sampling profiler will be a better choice. Excellent choices include <a href="https://github.com/tmm1/stackprof">stackprof</a> or <a href="https://rbspy.github.io/">rbspy</a>.</p>
732760
<p>If you are just interested in memory usage, you may also want to checkout the <a href="https://github.com/SamSaffron/memory_profiler">memory_profiler</a> gem (although ruby-prof provides similar information).</p>

history/index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,33 @@
345345

346346

347347

348+
<li class="md-nav__item">
349+
<a href="../best-practices.md" class="md-nav__link">
350+
351+
352+
353+
<span class="md-ellipsis">
354+
355+
356+
Best Practices
357+
358+
359+
360+
</span>
361+
362+
363+
364+
</a>
365+
</li>
366+
367+
368+
369+
370+
371+
372+
373+
374+
348375
<li class="md-nav__item">
349376
<a href="../profiling-rails/" class="md-nav__link">
350377

index.html

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,33 @@
468468

469469

470470

471+
<li class="md-nav__item">
472+
<a href="./best-practices.md" class="md-nav__link">
473+
474+
475+
476+
<span class="md-ellipsis">
477+
478+
479+
Best Practices
480+
481+
482+
483+
</span>
484+
485+
486+
487+
</a>
488+
</li>
489+
490+
491+
492+
493+
494+
495+
496+
497+
471498
<li class="md-nav__item">
472499
<a href="./profiling-rails/" class="md-nav__link">
473500

@@ -720,7 +747,7 @@
720747

721748

722749
<h1 id="ruby-prof">ruby-prof<a class="headerlink" href="#ruby-prof" title="Permanent link">&para;</a></h1>
723-
<p>ruby-prof is a <a href="./comparison/#tracing-vs-sampling">tracing</a> profiler for MRI Ruby with a long <a href="./history/">history</a> that dates back to 2005! Its features include:</p>
750+
<p>ruby-prof is a <a href="./alternatives/#tracing-vs-sampling">tracing</a> profiler for MRI Ruby with a long <a href="./history/">history</a> that dates back to 2005! Its features include:</p>
724751
<ul>
725752
<li>Measurement Modes - ruby-prof can measure program <a href="advanced-usage/#wall-time">wall time</a>, <a href="advanced-usage/#process-time">process time</a> and <a href="advanced-usage/#object-allocations">object allocations</a>.</li>
726753
<li>Reports - ruby-prof can generate <a href="reports/#flat">flat</a>, <a href="reports/#graph-text">graph (text)</a>, <a href="reports/#graph-html">graph (HTML)</a>, <a href="reports/#flame-graph">flame graph</a>, <a href="reports/#call-stack">call stack</a>, <a href="reports/#graphviz">graphviz</a>, <a href="reports/#cachegrind">cachegrind</a>, and <a href="reports/#call-info-report">call info</a> reports.</li>

0 commit comments

Comments
 (0)