https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112011-09-07T14:53:08ZRuby Issue Tracking SystemRuby master - Feature #5291: Enabling GC Profiler GC_PROFILE_MORE_DETAIL and CALC_EXACT_MALLOC_SIZEhttps://redmine.ruby-lang.org/issues/5291?journal_id=206512011-09-07T14:53:08Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>Charlie Savage <a href="mailto:cfis@savagexi.com" class="email">cfis@savagexi.com</a> wrote:</p>
<blockquote>
<p>#define CALC_EXACT_MALLOC_SIZE 0</p>
</blockquote>
<p>I tried flipping this a few months back in trunk but didn't have time to<br>
investigate what went wrong when I did. I'm not sure how much people<br>
care for it or if it's even maintained/tested by anyone (I'm not sure<br>
I care).</p>
<p>I have found (and helped fix at least one) 3rd-party extensions that had<br>
an issue with this (due to a x*alloc() paired with a regular free() or<br>
vice-versa). So I suspect this is a common (but currently non-fatal)<br>
bug in other extensions, too.</p>
<p>Anyways, several (most?) malloc implementations support<br>
malloc_usable_size() (or similar) and have various hooks that could be<br>
used to instrument malloc. Unfortunately the various extensions I know<br>
of aren't compatible with each other (dlmalloc/ptmalloc, tcmalloc,<br>
jemalloc).</p> Ruby master - Feature #5291: Enabling GC Profiler GC_PROFILE_MORE_DETAIL and CALC_EXACT_MALLOC_SIZEhttps://redmine.ruby-lang.org/issues/5291?journal_id=206522011-09-07T15:04:09Zcfis (Charlie Savage)
<ul></ul><p>FYI, pairing a xalloc with a free can be fatal on windows depending on how Ruby is built (mingw is safe, VC++ isn't) and what runtime c libaries are used. See the "Caution" note at the bottom of:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/2kzt1wy3%28v=vs.71%29.aspx" class="external">http://msdn.microsoft.com/en-us/library/2kzt1wy3%28v=vs.71%29.aspx</a></p>
<p>Thanks for fixing them!</p> Ruby master - Feature #5291: Enabling GC Profiler GC_PROFILE_MORE_DETAIL and CALC_EXACT_MALLOC_SIZEhttps://redmine.ruby-lang.org/issues/5291?journal_id=206812011-09-09T00:59:07Zko1 (Koichi Sasada)
<ul></ul><p>(2011/09/06 23:04), Charlie Savage wrote:</p>
<blockquote>
<p>FYI, pairing a xalloc with a free can be fatal on windows depending on how Ruby is built (mingw is safe, VC++ isn't) and what runtime c libaries are used. See the "Caution" note at the bottom of:</p>
</blockquote>
<p>Good point. This measurements can check such errors :P</p>
<p>--<br>
// SASADA Koichi at atdot dot net</p> Ruby master - Feature #5291: Enabling GC Profiler GC_PROFILE_MORE_DETAIL and CALC_EXACT_MALLOC_SIZEhttps://redmine.ruby-lang.org/issues/5291?journal_id=206822011-09-09T00:59:07Zko1 (Koichi Sasada)
<ul></ul><p>(2011/09/06 22:05), Charlie Savage wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Enabling GC Profiler GC_PROFILE_MORE_DETAIL and CALC_EXACT_MALLOC_SIZE (Closed)" href="https://redmine.ruby-lang.org/issues/5291">#5291</a> has been reported by Charlie Savage.</p>
<hr>
<p>Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Enabling GC Profiler GC_PROFILE_MORE_DETAIL and CALC_EXACT_MALLOC_SIZE (Closed)" href="https://redmine.ruby-lang.org/issues/5291">#5291</a>: Enabling GC Profiler GC_PROFILE_MORE_DETAIL and CALC_EXACT_MALLOC_SIZE<br>
<a href="http://redmine.ruby-lang.org/issues/5291" class="external">http://redmine.ruby-lang.org/issues/5291</a></p>
<p>Author: Charlie Savage<br>
Status: Open<br>
Priority: Normal<br>
Assignee:<br>
Category: core<br>
Target version: 1.9.3</p>
<p>I would like to hook ruby-prof into the new GC profiler. However, by default a lot of the profile stats are disabled by these two defines in gcc.c.</p>
<p>#define GC_PROFILE_MORE_DETAIL 0<br>
#define CALC_EXACT_MALLOC_SIZE 0</p>
<p>To turn on these stats, you have to modify the ruby source code! That is a high barrier for most people.</p>
<p>So would it be possible to:</p>
<ul>
<li>Set them to 1 by default. Or would this be too much of a performance hit?</li>
</ul>
<ul>
<li>or -</li>
</ul>
<ul>
<li>Remove the lines entirely and then change the logic in the file from this:</li>
</ul>
<p>#if GC_PROFILE_MORE_DETAIL</p>
<p>To this:</p>
<p>#if defined?(GC_PROFILE_MORE_DETAIL)</p>
<p>Then when buildig Ruby you could tell the compiler to define the symbols (-DGC_PROFILE_MORE_DETAIL).</p>
<ul>
<li>or -</li>
</ul>
<ul>
<li>Add these two defines to the ./configure script so they end up in config.h. That would make it easy for users to enable them if they wish, and would be also allow ruby-prof to use them too.</li>
</ul>
<p>Would a patch be accepted to do this?</p>
</blockquote>
<p>How about it?</p>
<a name="Index-gcc"></a>
<h1 >Index: gc.c<a href="#Index-gcc" class="wiki-anchor">¶</a></h1>
<p>--- gc.c (revision 33165)<br>
+++ gc.c (working copy)<br>
@@ -93,7 +93,10 @@<br>
int ruby_gc_debug_indent = 0;</p>
<p>/* for GC profile */<br>
+#ifndef GC_PROFILE_MORE_DETAIL<br>
#define GC_PROFILE_MORE_DETAIL 0<br>
+#endif<br>
+<br>
typedef struct gc_profile_record {<br>
double gc_time;<br>
double gc_mark_time;<br>
@@ -309,7 +312,9 @@<br>
struct gc_list *next;<br>
};</p>
<p>+#ifndef CALC_EXACT_MALLOC_SIZE<br>
#define CALC_EXACT_MALLOC_SIZE 0<br>
+#endif</p>
<p>typedef struct rb_objspace {<br>
struct {</p>
<p>--<br>
// SASADA Koichi at atdot dot net</p> Ruby master - Feature #5291: Enabling GC Profiler GC_PROFILE_MORE_DETAIL and CALC_EXACT_MALLOC_SIZEhttps://redmine.ruby-lang.org/issues/5291?journal_id=206832011-09-09T02:41:47Zcfis (Charlie Savage)
<ul></ul><p>Yes, that would be much better. Is it too late for this to be part of 1.9.3?</p>
<p>Thank you!</p>
<p>Charlie</p> Ruby master - Feature #5291: Enabling GC Profiler GC_PROFILE_MORE_DETAIL and CALC_EXACT_MALLOC_SIZEhttps://redmine.ruby-lang.org/issues/5291?journal_id=207072011-09-10T08:34:05Zko1 (Koichi Sasada)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r33243.<br>
Charlie, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<ul>
<li>gc.c (GC_PROFILE_MORE_DETAIL, CALC_EXACT_MALLOC_SIZE):<br>
define macros only if they are not defined.<br>
fixes: [Ruby 1.9 - Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Enabling GC Profiler GC_PROFILE_MORE_DETAIL and CALC_EXACT_MALLOC_SIZE (Closed)" href="https://redmine.ruby-lang.org/issues/5291">#5291</a>]</li>
</ul>