https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112012-11-29T05:06:49ZRuby Issue Tracking SystemRuby master - Feature #7457: GC.stat to return "allocated object count" and "freed object count"https://bugs.ruby-lang.org/issues/7457?journal_id=340952012-11-29T05:06:49Zbitsweat (Jeremy Daer)jeremydaer@gmail.com
<ul></ul><p>Yes!! A million times yes. Tracking <em>total</em> allocations makes it possible to profile Ruby code by object creation instead of time. This is very useful, often more so than profiling process time, because reducing excessive object creation will massively speed up GC and reduce the max # of heaps the VM needs, so lower memory for the process, all due to less object churn.</p>
<p>The ruby-prof gem supports object allocation profiling for 1.8.x (REE patches). The REE patches provide rb_os_allocated_objects and ObjectSpace.allocated_objects. Ideally, we would have a simple reader method like this to avoid creating lots of <code>GC.stat</code> Hash objects.</p>
<p>Even better, the benchmark.rb stdlib could then support benchmarking by objects created and objects created per second in addition to process time!</p> Ruby master - Feature #7457: GC.stat to return "allocated object count" and "freed object count"https://bugs.ruby-lang.org/issues/7457?journal_id=341012012-11-29T08:53:11ZauthorNari (Narihiro Nakamura)authorNari@gmail.com
<ul></ul><p>Could you commit it?</p>
<p>Thanks!</p> Ruby master - Feature #7457: GC.stat to return "allocated object count" and "freed object count"https://bugs.ruby-lang.org/issues/7457?journal_id=341182012-11-29T13:59:09Zko1 (Koichi Sasada)
<ul></ul><p>(2012/11/29 5:06), bitsweat (Jeremy Kemper) wrote:</p>
<blockquote>
<p>The ruby-prof gem supports object allocation profiling for 1.8.x (REE patches). The REE patches provide rb_os_allocated_objects and ObjectSpace.allocated_objects. Ideally, we would have a simple reader method like this to avoid creating lots of <code>GC.stat</code> Hash objects.</p>
</blockquote>
<p>You can avoid to create Hash object using 1st parameter.</p>
<p>h = {}<br>
r = 10.times.map{<br>
GC.stat(h); h[:heap_total_allocated_num]<br>
}<br>
p r #=> [2422, 2423, 2423, 2423, 2423, 2423, 2423, 2423, 2423, 2423]</p>
<p>--<br>
// SASADA Koichi at atdot dot net</p> Ruby master - Feature #7457: GC.stat to return "allocated object count" and "freed object count"https://bugs.ruby-lang.org/issues/7457?journal_id=341192012-11-29T14:10:32Zko1 (Koichi Sasada)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Finally, I introduce two keys.</p>
<pre><code> * total_allocated_object: total allocated object number.
* total_freed_object: total freed object number.
</code></pre>
<p>I remove "heap_" prefix because this information is not about current "heap_".</p>
<p>Give us comments.</p>
<p>Thanks,<br>
Koichi</p>