-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patharchitecture.html
64 lines (63 loc) · 3.48 KB
/
architecture.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<title>ruby-prof</title>
<link rel="stylesheet" type="text/css" href="assets/styles.css">
</head>
<body>
<div class="header"><img src="./assets/ruby-prof-logo-white.svg"></div>
<div class="grid-container">
<nav role="navigation">
<ul>
<li><a href="#overview">Overview</a></li>
<li><a href="#api-documentation">API Documentation</a></li>
<li><a href="#license"></a><a href="#license">License</a></li>
<li><a href="#development">Development</a></li>
</ul>
</nav>
<div class="main">
<h1>Architecuture<span> </span></h1>
<p><a href="https://travis-ci.org/ruby-prof/ruby-prof"><img src="https://travis-ci.org/ruby-prof/ruby-prof.png?branch=master"
alt="Build Status"></a></p>
<h2><a id="overview">Overview</a></h2>
<p>ruby-prof is a profiler for MRI Ruby. Its built as a C extension and
therefore many times faster than the standard Ruby profiler. The image
below shows the main classes that make up ruby-prof:</p>
<p><br>
</p>
<img src="assets/class_diagram.png" alt="Class Diagram" title="Class Diagram">
<p><br>
</p>
The top level class is Profile, which is returned by a profiling run:
<pre class="ruby"><span class="ruby-identifier">profile = RubyProf.profile do </span><br> ..
<span style="color: navajowhite;"> end</span></pre>
<p>A profile owns a hash of threads, and threads in turn own the methods
called in that thread as well as call trees which record how the
methods were called.</p>
<h2><a id="memory">Memory Management</a></h2>
<p>The master object is the Profile object. Each Profile object is
responsible for managing the memory of its child objects which are C
structures. When the Profile object goes out of scope, it recursively
frees all its objects. In the class diagram, this can bee seen
via the composition relationships. The owning object is denoted with a
filled in black diamond. Thus a Profile frees its threads, Threads
free their CallTrees and Methods, etc.</p>
<p>You should always keep a reference to a Profile object so that you can generate profiling
reports. However, RubyProf will keep a Profile object alive, even if it has no direct references,
as long as there are live references to either a MethodInfo object or a CallTree object. This is
done via the GC mark phase. CallTree instances mark their associated MethodInfo instances, and MethodInfo
instances in turn mark their owning Profile instance.
</p>
<p>Starting with version 1.5 it is possible to create new instances of the
Thread, CallTree and MethodInfo classes from Ruby. In general you won't need to use this
functionality - it was added to make it easier to write tests. However, this functionality does
complicate memory management because some objects are now owned by the C extension while others are
owned by Ruby. To track this information an internal ownership flag was added to instances of these classes.
RubyProf automatically handles this, but it is important to understand if you are reading or
modifying the C code.</p>
</p>
</div>
</div>
</body>
</html>