Skip to content

Commit 3333596

Browse files
authored
Merge pull request #5 from jairosoto05/update-convenience-api-doc
Update 'Convenience API' examples in Getting Started guide
2 parents 24bc25c + d51b43c commit 3333596

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

assets/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ color: rgba(255, 255, 255, 0.6);
116116
.ruby-comment { color: #dc0000; background: transparent; }
117117
.ruby-regexp { color: #ffa07a; background: transparent; }
118118
.ruby-value { color: #7fffd4; background: transparent; }
119+
.ruby-object { color: #80a9cd; background: transparent; }
119120

120121

121122
.grid-container {

doc/css/rdoc.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ pre {
608608
.ruby-comment { color: #dc0000; background: transparent; }
609609
.ruby-regexp { color: #ffa07a; background: transparent; }
610610
.ruby-value { color: #7fffd4; background: transparent; }
611+
.ruby-object { color: #80a9cd; background: transparent; }
611612

612613
/* @end */
613614

index.html

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ <h2><a id="getting-started">Getting Started</a></h2>
107107
<li>convenience API</li>
108108
<li>core API</li>
109109
</ul>
110+
<!-- Command Line -->
110111
<h3><a id="command-line">Command Line </a></h3>
111112
<p>The easiest way to use ruby-prof is via the command line, which
112113
requires no modifications to your program.&nbsp; The basic usage is:</p>
@@ -116,15 +117,23 @@ <h3><a id="command-line">Command Line </a></h3>
116117
<p>For a full list of options, see <a href="doc/RubyProf/Cmd.html">RubyProf::Cmd</a>
117118
documentation or execute the following command:</p>
118119
<pre>ruby-prof -h</pre>
120+
121+
<!-- Convenience API -->
119122
<h3>Convenience API<span></span></h3>
120123
<p>The second way to use ruby-prof is via its convenience API. This
121124
requires small modifications to the program you want to profile:</p>
122125
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'ruby-prof'</span>
123126

127+
<span class="ruby-identifier">profile</span> = <span class="ruby-constant">RubyProf</span><span
128+
129+
class="ruby-operator">::</span><span class="ruby-constant">Profile</span>.<span
130+
131+
class="ruby-identifier">new</span>
132+
124133
<span class="ruby-comment"># profile the code</span>
125-
<span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">start</span>
134+
<span class="ruby-object">profile</span>.<span class="ruby-identifier">start</span>
126135
<span class="ruby-comment"># ... code to profile ...</span>
127-
<span class="ruby-identifier">result</span> = <span class="ruby-constant">RubyProf</span>.<span
136+
<span class="ruby-identifier">result</span> = <span class="ruby-object">profile</span>.<span
128137

129138
class="ruby-identifier">stop</span>
130139

@@ -133,16 +142,18 @@ <h3>Convenience API<span></span></h3>
133142

134143
class="ruby-operator">::</span><span class="ruby-constant">FlatPrinter</span>.<span
135144

136-
class="ruby-identifier">new</span>(<span class="ruby-identifier">result</span>)
137-
<span class="ruby-identifier">printer</span>.<span class="ruby-identifier">print</span>(<span
145+
class="ruby-identifier">new</span>(<span class="ruby-object">result</span>)
146+
<span class="ruby-object">printer</span>.<span class="ruby-identifier">print</span>(<span
138147

139148
class="ruby-constant">STDOUT</span>)
140149
</pre>
141150
<p>Alternatively, you can use a block to tell ruby-prof what to profile:</p>
142151
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'ruby-prof'</span>
143152

144153
<span class="ruby-comment"># profile the code</span>
145-
<span class="ruby-identifier">result</span> = <span class="ruby-constant">RubyProf</span>.<span
154+
<span class="ruby-identifier">result</span> = <span class="ruby-constant">RubyProf</span><span
155+
156+
class="ruby-operator">::</span><span class="ruby-constant">Profile</span>.<span
146157

147158
class="ruby-identifier">profile</span> <span class="ruby-keyword">do</span>
148159
<span class="ruby-comment"># ... code to profile ...</span>
@@ -153,38 +164,58 @@ <h3>Convenience API<span></span></h3>
153164

154165
class="ruby-operator">::</span><span class="ruby-constant">GraphPrinter</span>.<span
155166

156-
class="ruby-identifier">new</span>(<span class="ruby-identifier">result</span>)
157-
<span class="ruby-identifier">printer</span>.<span class="ruby-identifier">print</span>(<span
167+
class="ruby-identifier">new</span>(<span class="ruby-object">result</span>)
168+
<span class="ruby-object">printer</span>.<span class="ruby-identifier">print</span>(<span
158169

159170
class="ruby-constant">STDOUT</span>, {})
160171
</pre>
161172
ruby-prof also supports pausing and resuming profiling runs.
162173
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'ruby-prof'</span>
163174

175+
<span class="ruby-identifier">profile</span> = <span class="ruby-constant">RubyProf</span><span
176+
177+
class="ruby-operator">::</span><span class="ruby-constant">Profile</span>.<span
178+
179+
class="ruby-identifier">new</span>
180+
164181
<span class="ruby-comment"># profile the code</span>
165-
<span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">start</span>
182+
<span class="ruby-object">profile</span>.<span class="ruby-identifier">start</span>
166183
<span class="ruby-comment"># ... code to profile ...</span>
167184

168-
<span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">pause</span>
185+
<span class="ruby-object">profile</span>.<span class="ruby-identifier">pause</span>
169186
<span class="ruby-comment"># ... other code ...</span>
170187

171-
<span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">resume</span>
188+
<span class="ruby-object">profile</span>.<span class="ruby-identifier">resume</span>
172189
<span class="ruby-comment"># ... code to profile ...</span>
173-
<span class="ruby-identifier">result</span> = <span class="ruby-constant">RubyProf</span>.<span
190+
191+
<span class="ruby-identifier">result</span> = <span class="ruby-object">profile</span>.<span
174192

175193
class="ruby-identifier">stop</span>
176194
</pre>
177195
<p>Note that resume will only work if start has been called previously.
178196
In addition, resume can also take a block:</p>
179197
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'ruby-prof'</span>
180198

181-
<span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">resume</span> <span
199+
<span class="ruby-identifier">profile</span> = <span class="ruby-constant">RubyProf</span><span
200+
201+
class="ruby-operator">::</span><span class="ruby-constant">Profile</span>.<span
202+
203+
class="ruby-identifier">new</span>
204+
205+
<span class="ruby-comment"># profile the code</span>
206+
<span class="ruby-object">profile</span>.<span class="ruby-identifier">start</span>
207+
<span class="ruby-comment"># ... code to profile ...</span>
208+
209+
<span class="ruby-object">profile</span>.<span class="ruby-identifier">pause</span>
210+
<span class="ruby-comment"># ... other code ...</span>
211+
212+
<span class="ruby-object">profile</span>.<span.<span class="ruby-identifier">resume</span> <span
182213

183214
class="ruby-keyword">do</span>
184215
<span class="ruby-comment"># ... code to profile...</span>
185216
<span class="ruby-keyword">end</span>
186217

187-
<span class="ruby-identifier">result</span> = <span class="ruby-constant">RubyProf</span>.<span
218+
<span class="ruby-identifier">result</span> = <span class="ruby-object">profile</span>.<span
188219

189220
class="ruby-identifier">stop</span>
190221
</pre>
@@ -193,6 +224,8 @@ <h3>Convenience API<span></span></h3>
193224
<p>The <code>RubyProf.profile</code> method can take various options,
194225
which are described in the <a href="#profiling-options">Profiling
195226
Options</a> below. </p>
227+
228+
<!-- Core API -->
196229
<h3>Core API</h3>
197230
<p>The convenience API is a wrapper around the the <code>Ruby::Profile</code>
198231
class. Using the Profile class directly provides addition

0 commit comments

Comments
 (0)