File: C:/Ruby27-x64/share/doc/ruby/html/GC/Profiler.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>module GC::Profiler - RDoc Documentation</title>
<script type="text/javascript">
var rdoc_rel_prefix = "../";
var index_rel_prefix = "../";
</script>
<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>
<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/rdoc.css" rel="stylesheet">
<body id="top" role="document" class="module">
<nav role="navigation">
<div id="project-navigation">
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
<h2>
<a href="../index.html" rel="home">Home</a>
</h2>
<div id="table-of-contents-navigation">
<a href="../table_of_contents.html#pages">Pages</a>
<a href="../table_of_contents.html#classes">Classes</a>
<a href="../table_of_contents.html#methods">Methods</a>
</div>
</div>
<div id="search-section" role="search" class="project-section initially-hidden">
<form action="#" method="get" accept-charset="utf-8">
<div id="search-field-wrapper">
<input id="search-field" role="combobox" aria-label="Search"
aria-autocomplete="list" aria-controls="search-results"
type="text" name="search" placeholder="Search" spellcheck="false"
title="Type to search, Up and Down to navigate, Enter to load">
</div>
<ul id="search-results" aria-label="Search Results"
aria-busy="false" aria-expanded="false"
aria-atomic="false" class="initially-hidden"></ul>
</form>
</div>
</div>
<div id="class-metadata">
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
<h3>Methods</h3>
<ul class="link-list" role="directory">
<li ><a href="#method-c-clear">::clear</a>
<li ><a href="#method-c-disable">::disable</a>
<li ><a href="#method-c-enable">::enable</a>
<li ><a href="#method-c-enabled-3F">::enabled?</a>
<li ><a href="#method-c-raw_data">::raw_data</a>
<li ><a href="#method-c-report">::report</a>
<li ><a href="#method-c-result">::result</a>
<li ><a href="#method-c-total_time">::total_time</a>
</ul>
</div>
</div>
</nav>
<main role="main" aria-labelledby="module-GC::Profiler">
<h1 id="module-GC::Profiler" class="module">
module GC::Profiler
</h1>
<section class="description">
<p>The <a href="../GC.html"><code>GC</code></a> profiler provides access to information on <a href="../GC.html"><code>GC</code></a> runs including time, length and object space size.</p>
<p>Example:</p>
<pre class="ruby"><span class="ruby-constant">GC</span><span class="ruby-operator">::</span><span class="ruby-constant">Profiler</span>.<span class="ruby-identifier">enable</span>
<span class="ruby-identifier">require</span> <span class="ruby-string">'rdoc/rdoc'</span>
<span class="ruby-constant">GC</span><span class="ruby-operator">::</span><span class="ruby-constant">Profiler</span>.<span class="ruby-identifier">report</span>
<span class="ruby-constant">GC</span><span class="ruby-operator">::</span><span class="ruby-constant">Profiler</span>.<span class="ruby-identifier">disable</span>
</pre>
<p>See also <a href="../GC.html#method-c-count"><code>GC.count</code></a>, <a href="../GC.html#method-c-malloc_allocated_size"><code>GC.malloc_allocated_size</code></a> and <a href="../GC.html#method-c-malloc_allocations"><code>GC.malloc_allocations</code></a></p>
</section>
<section id="5Buntitled-5D" class="documentation-section">
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Class Methods</h3>
</header>
<div id="method-c-clear" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
GC::Profiler.clear → nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Clears the <a href="../GC.html"><code>GC</code></a> profiler data.</p>
<div class="method-source-code" id="clear-source">
<pre>static VALUE
gc_profile_clear(VALUE _)
{
rb_objspace_t *objspace = &rb_objspace;
void *p = objspace->profile.records;
objspace->profile.records = NULL;
objspace->profile.size = 0;
objspace->profile.next_index = 0;
objspace->profile.current_record = 0;
if (p) {
free(p);
}
return Qnil;
}</pre>
</div>
</div>
</div>
<div id="method-c-disable" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
GC::Profiler.disable → nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Stops the <a href="../GC.html"><code>GC</code></a> profiler.</p>
<div class="method-source-code" id="disable-source">
<pre>static VALUE
gc_profile_disable(VALUE _)
{
rb_objspace_t *objspace = &rb_objspace;
objspace->profile.run = FALSE;
objspace->profile.current_record = 0;
return Qnil;
}</pre>
</div>
</div>
</div>
<div id="method-c-enable" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
GC::Profiler.enable → nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Starts the <a href="../GC.html"><code>GC</code></a> profiler.</p>
<div class="method-source-code" id="enable-source">
<pre>static VALUE
gc_profile_enable(VALUE _)
{
rb_objspace_t *objspace = &rb_objspace;
objspace->profile.run = TRUE;
objspace->profile.current_record = 0;
return Qnil;
}</pre>
</div>
</div>
</div>
<div id="method-c-enabled-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
GC::Profiler.enabled? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>The current status of <a href="../GC.html"><code>GC</code></a> profile mode.</p>
<div class="method-source-code" id="enabled-3F-source">
<pre>static VALUE
gc_profile_enable_get(VALUE self)
{
rb_objspace_t *objspace = &rb_objspace;
return objspace->profile.run ? Qtrue : Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-c-raw_data" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
GC::Profiler.raw_data → [Hash, ...]
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns an <a href="../Array.html"><code>Array</code></a> of individual raw profile data Hashes ordered from earliest to latest by <code>:GC_INVOKE_TIME</code>.</p>
<p>For example:</p>
<pre class="ruby">[
{
<span class="ruby-value">:GC_TIME</span><span class="ruby-operator">=></span><span class="ruby-value">1.3000000000000858e-05</span>,
<span class="ruby-value">:GC_INVOKE_TIME</span><span class="ruby-operator">=></span><span class="ruby-value">0.010634999999999999</span>,
<span class="ruby-value">:HEAP_USE_SIZE</span><span class="ruby-operator">=></span><span class="ruby-value">289640</span>,
<span class="ruby-value">:HEAP_TOTAL_SIZE</span><span class="ruby-operator">=></span><span class="ruby-value">588960</span>,
<span class="ruby-value">:HEAP_TOTAL_OBJECTS</span><span class="ruby-operator">=></span><span class="ruby-value">14724</span>,
<span class="ruby-value">:GC_IS_MARKED</span><span class="ruby-operator">=></span><span class="ruby-keyword">false</span>
},
<span class="ruby-comment"># ...</span>
]
</pre>
<p>The keys mean:</p>
<dl class="rdoc-list note-list"><dt><code>:GC_TIME</code>
<dd>
<p><a href="../Time.html"><code>Time</code></a> elapsed in seconds for this <a href="../GC.html"><code>GC</code></a> run</p>
</dd><dt><code>:GC_INVOKE_TIME</code>
<dd>
<p><a href="../Time.html"><code>Time</code></a> elapsed in seconds from startup to when the <a href="../GC.html"><code>GC</code></a> was invoked</p>
</dd><dt><code>:HEAP_USE_SIZE</code>
<dd>
<p>Total bytes of heap used</p>
</dd><dt><code>:HEAP_TOTAL_SIZE</code>
<dd>
<p>Total size of heap in bytes</p>
</dd><dt><code>:HEAP_TOTAL_OBJECTS</code>
<dd>
<p>Total number of objects</p>
</dd><dt><code>:GC_IS_MARKED</code>
<dd>
<p>Returns <code>true</code> if the <a href="../GC.html"><code>GC</code></a> is in mark phase</p>
</dd></dl>
<p>If ruby was built with <code>GC_PROFILE_MORE_DETAIL</code>, you will also have access to the following hash keys:</p>
<dl class="rdoc-list note-list"><dt><code>:GC_MARK_TIME</code>
<dt><code>:GC_SWEEP_TIME</code>
<dt><code>:ALLOCATE_INCREASE</code>
<dt><code>:ALLOCATE_LIMIT</code>
<dt><code>:HEAP_USE_PAGES</code>
<dt><code>:HEAP_LIVE_OBJECTS</code>
<dt><code>:HEAP_FREE_OBJECTS</code>
<dt><code>:HAVE_FINALIZE</code>
<dd></dd></dl>
<div class="method-source-code" id="raw_data-source">
<pre>static VALUE
gc_profile_record_get(VALUE _)
{
VALUE prof;
VALUE gc_profile = rb_ary_new();
size_t i;
rb_objspace_t *objspace = (&rb_objspace);
if (!objspace->profile.run) {
return Qnil;
}
for (i =0; i < objspace->profile.next_index; i++) {
gc_profile_record *record = &objspace->profile.records[i];
prof = rb_hash_new();
rb_hash_aset(prof, ID2SYM(rb_intern("GC_FLAGS")), gc_info_decode(0, rb_hash_new(), record->flags));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_TIME")), DBL2NUM(record->gc_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_INVOKE_TIME")), DBL2NUM(record->gc_invoke_time));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_SIZE")), SIZET2NUM(record->heap_use_size));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")), SIZET2NUM(record->heap_total_size));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")), SIZET2NUM(record->heap_total_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_IS_MARKED")), Qtrue);
#if GC_PROFILE_MORE_DETAIL
rb_hash_aset(prof, ID2SYM(rb_intern("GC_MARK_TIME")), DBL2NUM(record->gc_mark_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_SWEEP_TIME")), DBL2NUM(record->gc_sweep_time));
rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_INCREASE")), SIZET2NUM(record->allocate_increase));
rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_LIMIT")), SIZET2NUM(record->allocate_limit));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_PAGES")), SIZET2NUM(record->heap_use_pages));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_LIVE_OBJECTS")), SIZET2NUM(record->heap_live_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_FREE_OBJECTS")), SIZET2NUM(record->heap_free_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("REMOVING_OBJECTS")), SIZET2NUM(record->removing_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("EMPTY_OBJECTS")), SIZET2NUM(record->empty_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("HAVE_FINALIZE")), (record->flags & GPR_FLAG_HAVE_FINALIZE) ? Qtrue : Qfalse);
#endif
#if RGENGC_PROFILE > 0
rb_hash_aset(prof, ID2SYM(rb_intern("OLD_OBJECTS")), SIZET2NUM(record->old_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("REMEMBERED_NORMAL_OBJECTS")), SIZET2NUM(record->remembered_normal_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("REMEMBERED_SHADY_OBJECTS")), SIZET2NUM(record->remembered_shady_objects));
#endif
rb_ary_push(gc_profile, prof);
}
return gc_profile;
}</pre>
</div>
</div>
</div>
<div id="method-c-report" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
GC::Profiler.report
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
GC::Profiler.report(io)
</span>
</div>
<div class="method-description">
<p>Writes the <a href="Profiler.html#method-c-result"><code>GC::Profiler.result</code></a> to <code>$stdout</code> or the given <a href="../IO.html"><code>IO</code></a> object.</p>
<div class="method-source-code" id="report-source">
<pre>static VALUE
gc_profile_report(int argc, VALUE *argv, VALUE self)
{
VALUE out;
out = (!rb_check_arity(argc, 0, 1) ? rb_stdout : argv[0]);
gc_profile_dump_on(out, rb_io_write);
return Qnil;
}</pre>
</div>
</div>
</div>
<div id="method-c-result" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
GC::Profiler.result → String
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a profile data report such as:</p>
<pre>GC 1 invokes.
Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC time(ms)
1 0.012 159240 212940 10647 0.00000000000001530000</pre>
<div class="method-source-code" id="result-source">
<pre>static VALUE
gc_profile_result(VALUE _)
{
VALUE str = rb_str_buf_new(0);
gc_profile_dump_on(str, rb_str_buf_append);
return str;
}</pre>
</div>
</div>
</div>
<div id="method-c-total_time" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
GC::Profiler.total_time → float
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>The total time used for garbage collection in seconds</p>
<div class="method-source-code" id="total_time-source">
<pre>static VALUE
gc_profile_total_time(VALUE self)
{
double time = 0;
rb_objspace_t *objspace = &rb_objspace;
if (objspace->profile.run && objspace->profile.next_index > 0) {
size_t i;
size_t count = objspace->profile.next_index;
for (i = 0; i < count; i++) {
time += objspace->profile.records[i].gc_time;
}
}
return DBL2NUM(time);
}</pre>
</div>
</div>
</div>
</section>
</section>
</main>
<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1.
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>