Skip to content

Commit d76a0d3

Browse files
committed
Updates based on GC handling changes.
1 parent 40cd784 commit d76a0d3

File tree

1 file changed

+62
-53
lines changed

1 file changed

+62
-53
lines changed

architecture.html

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,62 @@
1-
<!DOCTYPE html>
2-
<html>
3-
<head>
4-
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
5-
<title>ruby-prof</title>
6-
<link rel="stylesheet" type="text/css" href="assets/styles.css">
7-
</head>
8-
<body>
9-
<div class="header"><img src="./assets/ruby-prof-logo-white.svg"></div>
10-
<div class="grid-container">
11-
<nav role="navigation">
12-
<ul>
13-
<li><a href="#overview">Overview</a></li>
14-
<li><a href="#api-documentation">API Documentation</a></li>
15-
<li><a href="#license"></a><a href="#license">License</a></li>
16-
<li><a href="#development">Development</a></li>
17-
</ul>
18-
</nav>
19-
<div class="main">
20-
<h1>Architecuture<span> </span></h1>
21-
<p><a href="https://travis-ci.org/ruby-prof/ruby-prof"><img src="https://travis-ci.org/ruby-prof/ruby-prof.png?branch=master"
22-
alt="Build Status"></a></p>
23-
<h2><a id="overview">Overview</a></h2>
24-
<p>ruby-prof is a profiler for MRI Ruby. Its built as a C extension and
25-
therefore many times faster than the standard Ruby profiler. The image
26-
below shows the main classes that make up ruby-prof:</p>
27-
<p><br>
28-
</p>
29-
<img src="assets/class_diagram.png" alt="Class Diagram" title="Class Diagram">
30-
<p><br>
31-
</p>
32-
The top level class is Profile, which is returned by a profiling run:
33-
<pre class="ruby"><span class="ruby-identifier">profile = RubyProf.profile do </span><br> ..
34-
<span style="color: navajowhite;"> end</span></pre>
35-
<p>A profile owns a hash of threads, and threads in turn own the methods
36-
called in that thread as well as call trees which record how the
37-
methods were called.</p>
38-
<h2><a id="memory">Memory Management</a></h2>
39-
<p>The master object is the Profile object. Each Profile object is
40-
responsible for managing the memory of its child objects which are C
41-
structures. When the Profile object goes out of scope, it recursively
42-
frees all its objects.&nbsp; In the class diagram, this can bee seen
43-
by the composition relationships. The owning object is denoted with a
44-
filled in black diamond. Thus a Profile frees its threads, Threads
45-
free their Methods, etc.</p>
46-
<p><br>
47-
</p>
48-
<p><br>
49-
</p>
50-
</div>
51-
</div>
52-
</body>
53-
</html>
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
5+
<title>ruby-prof</title>
6+
<link rel="stylesheet" type="text/css" href="assets/styles.css">
7+
</head>
8+
<body>
9+
<div class="header"><img src="./assets/ruby-prof-logo-white.svg"></div>
10+
<div class="grid-container">
11+
<nav role="navigation">
12+
<ul>
13+
<li><a href="#overview">Overview</a></li>
14+
<li><a href="#api-documentation">API Documentation</a></li>
15+
<li><a href="#license"></a><a href="#license">License</a></li>
16+
<li><a href="#development">Development</a></li>
17+
</ul>
18+
</nav>
19+
<div class="main">
20+
<h1>Architecuture<span> </span></h1>
21+
<p><a href="https://travis-ci.org/ruby-prof/ruby-prof"><img src="https://travis-ci.org/ruby-prof/ruby-prof.png?branch=master"
22+
23+
alt="Build Status"></a></p>
24+
<h2><a id="overview">Overview</a></h2>
25+
<p>ruby-prof is a profiler for MRI Ruby. Its built as a C extension and
26+
therefore many times faster than the standard Ruby profiler. The image
27+
below shows the main classes that make up ruby-prof:</p>
28+
<p><br>
29+
</p>
30+
<img src="assets/class_diagram.png" alt="Class Diagram" title="Class Diagram">
31+
<p><br>
32+
</p>
33+
The top level class is Profile, which is returned by a profiling run:
34+
<pre class="ruby"><span class="ruby-identifier">profile = RubyProf.profile do </span><br> ..
35+
<span style="color: navajowhite;"> end</span></pre>
36+
<p>A profile owns a hash of threads, and threads in turn own the methods
37+
called in that thread as well as call trees which record how the
38+
methods were called.</p>
39+
<h2><a id="memory">Memory Management</a></h2>
40+
<p>The master object is the Profile object. Each Profile object is
41+
responsible for managing the memory of its child objects which are C
42+
structures. When the Profile object goes out of scope, it recursively
43+
frees all its objects.&nbsp; In the class diagram, this can bee seen
44+
via the composition relationships. The owning object is denoted with a
45+
filled in black diamond. Thus a Profile frees its threads, Threads
46+
free their CallTrees and Methods, etc.</p>
47+
<p>You should always keep a reference to a Profile object so that you can generate profiling
48+
reports. However, RubyProf will keep a Profile object alive, even if it has no direct references,
49+
as long as there are live references to either a MethodInfo object or a CallTree object. This is
50+
done via the GC mark phase. CallTree instances mark their associated MethodInfo instances, and MethodInfo
51+
instances in turn mark their owning Profile instance.
52+
</p>
53+
<p>Previous versions of RubyProf (before 1.3) would not keep the top level Profile instance alive and instead
54+
would detect when the underlying Ruby object was freed. However, this approach could result in
55+
crashes if a GC happened just at the wrong time. Specifically, when trying to expose an object such as
56+
a CallTree Ruby performs a memory allocation. This allocation could trigger a GC, freeing the top level
57+
Profile instance and its associated CallTree. Thus the returned CallTree instance would be invalid.
58+
</p>
59+
</div>
60+
</div>
61+
</body>
62+
</html>

0 commit comments

Comments
 (0)