RubyRun_CE 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/LICENSE +13 -0
  2. data/README +75 -0
  3. data/Rakefile +241 -0
  4. data/bin/confgure +2 -0
  5. data/docs/RubyRunCE_09.htm +6346 -0
  6. data/docs/RubyRunCE_09.pdf +0 -0
  7. data/docs/RubyRunCE_09_files/colorschememapping.xml +2 -0
  8. data/docs/RubyRunCE_09_files/filelist.xml +29 -0
  9. data/docs/RubyRunCE_09_files/header.htm +142 -0
  10. data/docs/RubyRunCE_09_files/image001.jpg +0 -0
  11. data/docs/RubyRunCE_09_files/image002.jpg +0 -0
  12. data/docs/RubyRunCE_09_files/image003.jpg +0 -0
  13. data/docs/RubyRunCE_09_files/image004.jpg +0 -0
  14. data/docs/RubyRunCE_09_files/image005.jpg +0 -0
  15. data/docs/RubyRunCE_09_files/image006.jpg +0 -0
  16. data/docs/RubyRunCE_09_files/image007.jpg +0 -0
  17. data/docs/RubyRunCE_09_files/image008.jpg +0 -0
  18. data/docs/RubyRunCE_09_files/image009.jpg +0 -0
  19. data/docs/RubyRunCE_09_files/image010.jpg +0 -0
  20. data/docs/RubyRunCE_09_files/image011.jpg +0 -0
  21. data/docs/RubyRunCE_09_files/image012.jpg +0 -0
  22. data/docs/RubyRunCE_09_files/image013.jpg +0 -0
  23. data/docs/RubyRunCE_09_files/image014.jpg +0 -0
  24. data/docs/RubyRunCE_09_files/image015.jpg +0 -0
  25. data/docs/RubyRunCE_09_files/image016.jpg +0 -0
  26. data/docs/RubyRunCE_09_files/image017.png +0 -0
  27. data/docs/RubyRunCE_09_files/image018.jpg +0 -0
  28. data/docs/RubyRunCE_09_files/image019.jpg +0 -0
  29. data/docs/RubyRunCE_09_files/image020.jpg +0 -0
  30. data/docs/RubyRunCE_09_files/image021.jpg +0 -0
  31. data/docs/RubyRunCE_09_files/image022.png +0 -0
  32. data/docs/RubyRunCE_09_files/themedata.thmx +0 -0
  33. data/etc/rubyrun_opts.yml +132 -0
  34. data/ext/extconf.rb +4 -0
  35. data/ext/rubyrunnative__.bundle +0 -0
  36. data/ext/rubyrunnative__.c +154 -0
  37. data/ext/rubyrunnative__.def +2 -0
  38. data/ext/rubyrunnative__.h +36 -0
  39. data/ext/rubyrunnative__.so +0 -0
  40. data/ext/rubyrunnative__linux.so +0 -0
  41. data/html/classes/Module.html +174 -0
  42. data/html/classes/Object.html +151 -0
  43. data/html/classes/RubyRunBufferMgr__.html +182 -0
  44. data/html/classes/RubyRunCommander__.html +578 -0
  45. data/html/classes/RubyRunDad__.html +144 -0
  46. data/html/classes/RubyRunGlobals.html +248 -0
  47. data/html/classes/RubyRunHTMLWriter.html +186 -0
  48. data/html/classes/RubyRunHTMLWriter/RubyRunHTMLDevice.html +157 -0
  49. data/html/classes/RubyRunHTML__.html +198 -0
  50. data/html/classes/RubyRunInitializer__.html +821 -0
  51. data/html/classes/RubyRunInstrumentor__.html +576 -0
  52. data/html/classes/RubyRunMonitor__.html +298 -0
  53. data/html/classes/RubyRunRSS.html +302 -0
  54. data/html/classes/RubyRunReport__.html +294 -0
  55. data/html/classes/RubyRunTracer__.html +253 -0
  56. data/html/classes/RubyRunUtils__.html +376 -0
  57. data/html/created.rid +1 -0
  58. data/html/files/LICENSE.html +119 -0
  59. data/html/files/README.html +196 -0
  60. data/html/files/lib/rubyrun/rubyrun_buffer_mgr___rb.html +101 -0
  61. data/html/files/lib/rubyrun/rubyrun_commander___rb.html +101 -0
  62. data/html/files/lib/rubyrun/rubyrun_dad___rb.html +101 -0
  63. data/html/files/lib/rubyrun/rubyrun_globals_rb.html +101 -0
  64. data/html/files/lib/rubyrun/rubyrun_html___rb.html +101 -0
  65. data/html/files/lib/rubyrun/rubyrun_html_writer___rb.html +108 -0
  66. data/html/files/lib/rubyrun/rubyrun_initializer___rb.html +112 -0
  67. data/html/files/lib/rubyrun/rubyrun_instrumentor___rb.html +116 -0
  68. data/html/files/lib/rubyrun/rubyrun_monitor___rb.html +116 -0
  69. data/html/files/lib/rubyrun/rubyrun_rb.html +121 -0
  70. data/html/files/lib/rubyrun/rubyrun_report___rb.html +101 -0
  71. data/html/files/lib/rubyrun/rubyrun_rss___rb.html +108 -0
  72. data/html/files/lib/rubyrun/rubyrun_tracer___rb.html +110 -0
  73. data/html/files/lib/rubyrun/rubyrun_utils___rb.html +108 -0
  74. data/html/files/lib/rubyrunm_rb.html +116 -0
  75. data/html/fr_class_index.html +42 -0
  76. data/html/fr_file_index.html +43 -0
  77. data/html/fr_method_index.html +96 -0
  78. data/html/index.html +24 -0
  79. data/html/rdoc-style.css +208 -0
  80. data/lib/rubyrun/rubyrun.rb +78 -0
  81. data/lib/rubyrun/rubyrun_buffer_mgr__.rb +49 -0
  82. data/lib/rubyrun/rubyrun_commander__.rb +196 -0
  83. data/lib/rubyrun/rubyrun_dad__.rb +35 -0
  84. data/lib/rubyrun/rubyrun_globals.rb +51 -0
  85. data/lib/rubyrun/rubyrun_html__.rb +136 -0
  86. data/lib/rubyrun/rubyrun_html_writer__.rb +64 -0
  87. data/lib/rubyrun/rubyrun_initializer__.rb +286 -0
  88. data/lib/rubyrun/rubyrun_instrumentor__.rb +226 -0
  89. data/lib/rubyrun/rubyrun_monitor__.rb +237 -0
  90. data/lib/rubyrun/rubyrun_report__.rb +109 -0
  91. data/lib/rubyrun/rubyrun_rss__.rb +97 -0
  92. data/lib/rubyrun/rubyrun_tracer__.rb +79 -0
  93. data/lib/rubyrun/rubyrun_utils__.rb +98 -0
  94. data/lib/rubyrunm.rb +10 -0
  95. metadata +148 -0
@@ -0,0 +1,576 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: RubyRunInstrumentor__</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">RubyRunInstrumentor__</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/rubyrun/rubyrun_instrumentor___rb.html">
59
+ lib/rubyrun/rubyrun_instrumentor__.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+
76
+
77
+ </div>
78
+
79
+ <div id="method-list">
80
+ <h3 class="section-bar">Methods</h3>
81
+
82
+ <div class="name-list">
83
+ <a href="#M000044">collect_method_data</a>&nbsp;&nbsp;
84
+ <a href="#M000042">insert_code_to_instance_method</a>&nbsp;&nbsp;
85
+ <a href="#M000043">insert_code_to_singleton_method</a>&nbsp;&nbsp;
86
+ <a href="#M000039">instrument_it?</a>&nbsp;&nbsp;
87
+ <a href="#M000041">instrument_target</a>&nbsp;&nbsp;
88
+ <a href="#M000045">instrument_thread_new</a>&nbsp;&nbsp;
89
+ <a href="#M000040">is_non_negotiably_excluded?</a>&nbsp;&nbsp;
90
+ <a href="#M000046">new</a>&nbsp;&nbsp;
91
+ </div>
92
+ </div>
93
+
94
+ </div>
95
+
96
+
97
+ <!-- if includes -->
98
+ <div id="includes">
99
+ <h3 class="section-bar">Included Modules</h3>
100
+
101
+ <div id="includes-list">
102
+ <span class="include-name"><a href="RubyRunGlobals.html">RubyRunGlobals</a></span>
103
+ <span class="include-name"><a href="RubyRunUtils__.html">RubyRunUtils__</a></span>
104
+ <span class="include-name"><a href="RubyRunMonitor__.html">RubyRunMonitor__</a></span>
105
+ <span class="include-name"><a href="RubyRunTracer__.html">RubyRunTracer__</a></span>
106
+ <span class="include-name"><a href="RubyRunDad__.html">RubyRunDad__</a></span>
107
+ <span class="include-name"><a href="RubyRunHTML__.html">RubyRunHTML__</a></span>
108
+ </div>
109
+ </div>
110
+
111
+ <div id="section">
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+ <!-- if method_list -->
121
+ <div id="methods">
122
+ <h3 class="section-bar">Public Instance methods</h3>
123
+
124
+ <div id="method-M000044" class="method-detail">
125
+ <a name="M000044"></a>
126
+
127
+ <div class="method-heading">
128
+ <a href="#M000044" class="method-signature">
129
+ <span class="method-name">collect_method_data</span><span class="method-args">(obj, klass, mid, *args) {|| ...}</span>
130
+ </a>
131
+ </div>
132
+
133
+ <div class="method-description">
134
+ <p>
135
+ This is the piece of code that actually executed under the application
136
+ thread during runtime and is not executed during instrumentation time
137
+ </p>
138
+ <ol>
139
+ <li>Create a equivalent thread local storage to store request performance
140
+
141
+ </li>
142
+ </ol>
143
+ <p>
144
+ metrics but only if this class is a Rails Active Controller class
145
+ </p>
146
+ <ol>
147
+ <li>Trace pre and post execution of the original method which has been aliased
148
+
149
+ </li>
150
+ </ol>
151
+ <p>
152
+ The original method is invoked via &#8216;yield&#8216;
153
+ </p>
154
+ <ol>
155
+ <li>When a method ends, report the timings to the response time component but
156
+
157
+ </li>
158
+ </ol>
159
+ <p>
160
+ only if a thread local exists
161
+ </p>
162
+ <p><a class="source-toggle" href="#"
163
+ onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
164
+ <div class="method-source-code" id="M000044-source">
165
+ <pre>
166
+ <span class="ruby-comment cmt"># File lib/rubyrun/rubyrun_instrumentor__.rb, line 184</span>
167
+ 184: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">collect_method_data</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">mid</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
168
+ 185: <span class="ruby-identifier">tid</span> = <span class="ruby-identifier">get_thread_id</span>
169
+ 186: <span class="ruby-identifier">create_thread_local</span>(<span class="ruby-identifier">tid</span>, <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">request</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">mid</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">is_rails_controller?</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">mid</span>)
170
+ 187: <span class="ruby-identifier">rubyrun_trace</span> = <span class="ruby-identifier">is_in?</span>(<span class="ruby-identifier">$rubyrun_trace_hash</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">mid</span>)
171
+ 188: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">rubyrun_trace</span>
172
+ 189: <span class="ruby-identifier">invoker</span> = <span class="ruby-identifier">get_caller_detail</span>
173
+ 190: <span class="ruby-identifier">enter_trace</span>(<span class="ruby-identifier">tid</span>, <span class="ruby-value str">&quot; Entry&quot;</span>, <span class="ruby-identifier">obj</span>, <span class="ruby-identifier">invoker</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">mid</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
174
+ 191: <span class="ruby-keyword kw">end</span>
175
+ 192: <span class="ruby-identifier">t1</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>
176
+ 193: <span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">yield</span>
177
+ 194: <span class="ruby-identifier">t2</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>
178
+ 195: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">rubyrun_trace</span>
179
+ 196: (<span class="ruby-identifier">t2</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">t1</span>) <span class="ruby-operator">&gt;=</span> <span class="ruby-constant">RUBYRUN_HIGHLIGHT_THRESHOLD</span> <span class="ruby-value">? </span>(<span class="ruby-identifier">type</span> = <span class="ruby-node">&quot;* #{sprintf(&quot;%6.2f&quot;, t2-t1)} Exit &quot;</span>) <span class="ruby-operator">:</span> (<span class="ruby-identifier">type</span> = <span class="ruby-node">&quot; #{sprintf(&quot;%6.2f&quot;, t2-t1)} Exit &quot;</span>)
180
+ 197: <span class="ruby-identifier">enter_trace</span>(<span class="ruby-identifier">tid</span>, <span class="ruby-identifier">type</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">mid</span>, <span class="ruby-keyword kw">nil</span>)
181
+ 198: <span class="ruby-keyword kw">end</span>
182
+ 199: <span class="ruby-identifier">report_rails_timing</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">mid</span>, <span class="ruby-identifier">t2</span>, <span class="ruby-identifier">t1</span>, <span class="ruby-identifier">tid</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$rubyrun_thread_local</span>[<span class="ruby-identifier">tid</span>] <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">t2</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">t1</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
183
+ 200: <span class="ruby-identifier">result</span>
184
+ 201: <span class="ruby-keyword kw">end</span>
185
+ </pre>
186
+ </div>
187
+ </div>
188
+ </div>
189
+
190
+ <div id="method-M000042" class="method-detail">
191
+ <a name="M000042"></a>
192
+
193
+ <div class="method-heading">
194
+ <a href="#M000042" class="method-signature">
195
+ <span class="method-name">insert_code_to_instance_method</span><span class="method-args">(klass, mid)</span>
196
+ </a>
197
+ </div>
198
+
199
+ <div class="method-description">
200
+ <p>
201
+ To instrument an instance method of a class, a method proxy is used:
202
+ </p>
203
+ <ol>
204
+ <li>Alias the method to one with a prefix rubyrun_ (i.e., copy the method and
205
+
206
+ </li>
207
+ </ol>
208
+ <p>
209
+ create another one with a <a
210
+ href="RubyRunInstrumentor__.html#M000046">new</a> name)
211
+ </p>
212
+ <ol>
213
+ <li>Create a <a href="RubyRunInstrumentor__.html#M000046">new</a> method with
214
+ the original name. This is the method proxy.
215
+
216
+ </li>
217
+ <li>Preserve the intended visibility of the original method in the proxy
218
+
219
+ </li>
220
+ <li>This proxy method essentially adds pre and post wrapper code to
221
+
222
+ </li>
223
+ </ol>
224
+ <p>
225
+ the original code. This wrapper code is embodied in <a
226
+ href="RubyRunInstrumentor__.html#M000044">collect_method_data</a>
227
+ </p>
228
+ <ol>
229
+ <li>All these must be done in the context of the class
230
+
231
+ </li>
232
+ </ol>
233
+ <p><a class="source-toggle" href="#"
234
+ onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
235
+ <div class="method-source-code" id="M000042-source">
236
+ <pre>
237
+ <span class="ruby-comment cmt"># File lib/rubyrun/rubyrun_instrumentor__.rb, line 140</span>
238
+ 140: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">insert_code_to_instance_method</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">mid</span>)
239
+ 141: <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">class_eval</span> {
240
+ 142: <span class="ruby-identifier">alias_method</span> <span class="ruby-node">&quot;#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}&quot;</span>, <span class="ruby-identifier">mid</span>.<span class="ruby-identifier">id2name</span>
241
+ 143: <span class="ruby-identifier">eval</span> <span class="ruby-value str">&quot;def \#{mid.id2name} (*args, &amp;blk)\nRubyRunInstrumentor__.collect_method_data(self, \#{klass}, '\#{mid}', *args) {self.send(\&quot;\#{RubyRunGlobals::RUBYRUN_PREFIX}_\#{mid.id2name}\&quot;, *args, &amp;blk)}\nend\n&quot;</span>
242
+ 144: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">private_instance_methods</span>(<span class="ruby-keyword kw">false</span>).<span class="ruby-identifier">include?</span>(<span class="ruby-node">&quot;#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}&quot;</span>)
243
+ 145: <span class="ruby-identifier">private</span> <span class="ruby-identifier">mid</span>
244
+ 146: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">protected_instance_methods</span>(<span class="ruby-keyword kw">false</span>).<span class="ruby-identifier">include?</span>(<span class="ruby-node">&quot;#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}&quot;</span>)
245
+ 147: <span class="ruby-identifier">protected</span> <span class="ruby-identifier">mid</span>
246
+ 148: <span class="ruby-keyword kw">end</span>
247
+ 149: }
248
+ 150: <span class="ruby-keyword kw">end</span>
249
+ </pre>
250
+ </div>
251
+ </div>
252
+ </div>
253
+
254
+ <div id="method-M000043" class="method-detail">
255
+ <a name="M000043"></a>
256
+
257
+ <div class="method-heading">
258
+ <a href="#M000043" class="method-signature">
259
+ <span class="method-name">insert_code_to_singleton_method</span><span class="method-args">(klass, mid)</span>
260
+ </a>
261
+ </div>
262
+
263
+ <div class="method-description">
264
+ <p>
265
+ Same as <a
266
+ href="RubyRunInstrumentor__.html#M000042">insert_code_to_instance_method</a>
267
+ </p>
268
+ <p><a class="source-toggle" href="#"
269
+ onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
270
+ <div class="method-source-code" id="M000043-source">
271
+ <pre>
272
+ <span class="ruby-comment cmt"># File lib/rubyrun/rubyrun_instrumentor__.rb, line 158</span>
273
+ 158: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">insert_code_to_singleton_method</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">mid</span>)
274
+ 159: (<span class="ruby-keyword kw">class</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">klass</span>; <span class="ruby-keyword kw">self</span>; <span class="ruby-keyword kw">end</span>).<span class="ruby-identifier">class_eval</span> {
275
+ 160: <span class="ruby-identifier">alias_method</span> <span class="ruby-node">&quot;#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}&quot;</span>, <span class="ruby-identifier">mid</span>.<span class="ruby-identifier">id2name</span>
276
+ 161: <span class="ruby-identifier">eval</span> <span class="ruby-value str">&quot;def \#{mid.id2name} (*args, &amp;blk)\nRubyRunInstrumentor__.collect_method_data(self, \#{klass}, '\#{mid}', *args) {self.send(\&quot;\#{RubyRunGlobals::RUBYRUN_PREFIX}_\#{mid.id2name}\&quot;, *args, &amp;blk)}\nend\n&quot;</span>
277
+ 162: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">private_instance_methods</span>(<span class="ruby-keyword kw">false</span>).<span class="ruby-identifier">include?</span>(<span class="ruby-node">&quot;#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}&quot;</span>)
278
+ 163: <span class="ruby-identifier">private</span> <span class="ruby-identifier">mid</span>
279
+ 164: <span class="ruby-keyword kw">elsif</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">protected_instance_methods</span>(<span class="ruby-keyword kw">false</span>).<span class="ruby-identifier">include?</span>(<span class="ruby-node">&quot;#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}&quot;</span>)
280
+ 165: <span class="ruby-identifier">protected</span> <span class="ruby-identifier">mid</span>
281
+ 166: <span class="ruby-keyword kw">end</span>
282
+ 167: }
283
+ 168: <span class="ruby-keyword kw">end</span>
284
+ </pre>
285
+ </div>
286
+ </div>
287
+ </div>
288
+
289
+ <div id="method-M000039" class="method-detail">
290
+ <a name="M000039"></a>
291
+
292
+ <div class="method-heading">
293
+ <a href="#M000039" class="method-signature">
294
+ <span class="method-name">instrument_it?</span><span class="method-args">(type, klass, id)</span>
295
+ </a>
296
+ </div>
297
+
298
+ <div class="method-description">
299
+ <p>
300
+ Invoked by the traps set up in rubyrun.rb. This indicates that a file has
301
+ been required/loaded such that the methods within are being added to the
302
+ process. Each method being added will go through the following process to
303
+ determine if it should be intrumented.
304
+ </p>
305
+ <ol>
306
+ <li>Through APP_PATHS a stream of class names whose methods are
307
+
308
+ </li>
309
+ </ol>
310
+ <p>
311
+ identified as candiates for instrumnetation in RubyRunIntializer__. This
312
+ process forms the initial INCLUDE_HASH which states ALL methods belonging
313
+ to these classes/methods should be instrumented
314
+ </p>
315
+ <ol>
316
+ <li>Through additional INCLUDE_HASH in rubyrun_opts a stream of
317
+
318
+ </li>
319
+ </ol>
320
+ <p>
321
+ class =&gt; methods hash entries provide further candidates for
322
+ instrumentation.
323
+ </p>
324
+ <ol>
325
+ <li>Thru EXCLUDE_HASH the exclusion logic is then applied to reduce the scope
326
+
327
+ </li>
328
+ </ol>
329
+ <p>
330
+ of instrumentation.
331
+ </p>
332
+ <ol>
333
+ <li>Some classes and methods are never instrumented regarldess. These
334
+
335
+ </li>
336
+ </ol>
337
+ <p>
338
+ are identifed in constants FIREWALL_HASH.
339
+ </p>
340
+ <p><a class="source-toggle" href="#"
341
+ onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
342
+ <div class="method-source-code" id="M000039-source">
343
+ <pre>
344
+ <span class="ruby-comment cmt"># File lib/rubyrun/rubyrun_instrumentor__.rb, line 53</span>
345
+ 53: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">instrument_it?</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>)
346
+ 54: <span class="ruby-identifier">get_dad</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>)
347
+ 55: <span class="ruby-identifier">instrument_target</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>) \
348
+ 56: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">is_non_negotiably_excluded?</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>)) <span class="ruby-operator">&amp;&amp;</span>
349
+ 57: <span class="ruby-operator">!</span><span class="ruby-identifier">is_in?</span>(<span class="ruby-identifier">$rubyrun_exclude_hash</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>, <span class="ruby-value str">'strict'</span>) <span class="ruby-operator">&amp;&amp;</span>
350
+ 58: <span class="ruby-identifier">is_in?</span>(<span class="ruby-identifier">$rubyrun_include_hash</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>, <span class="ruby-value str">'strict'</span>)
351
+ 59: <span class="ruby-keyword kw">end</span>
352
+ </pre>
353
+ </div>
354
+ </div>
355
+ </div>
356
+
357
+ <div id="method-M000041" class="method-detail">
358
+ <a name="M000041"></a>
359
+
360
+ <div class="method-heading">
361
+ <a href="#M000041" class="method-signature">
362
+ <span class="method-name">instrument_target</span><span class="method-args">(type, klass, id)</span>
363
+ </a>
364
+ </div>
365
+
366
+ <div class="method-description">
367
+ <p>
368
+ First layer of code performing instrummentation on a class.method The
369
+ injecting code is different depending on whether the method is an instance
370
+ method, or singleton(static method of a class, specific method added to an
371
+ object).
372
+ </p>
373
+ <p>
374
+ If this class is a Rails active controller class, create a hash entry if it
375
+ does not already exist. This hash is used to keep track of performance
376
+ metrics by action by controller.
377
+ </p>
378
+ <p>
379
+ If we fail to instrument for whatever reason, log the errors and leave the
380
+ method alone.
381
+ </p>
382
+ <p>
383
+ Also, create metrics hash for a RAILS controller class if it doesn&#8216;t
384
+ exist
385
+ </p>
386
+ <p><a class="source-toggle" href="#"
387
+ onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
388
+ <div class="method-source-code" id="M000041-source">
389
+ <pre>
390
+ <span class="ruby-comment cmt"># File lib/rubyrun/rubyrun_instrumentor__.rb, line 112</span>
391
+ 112: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">instrument_target</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>)
392
+ 113: <span class="ruby-identifier">$rubyrun_logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;instrumenting #{klass.to_s}.#{id.id2name}.&quot;</span>
393
+ 114: <span class="ruby-identifier">create_metrics_hash</span>(<span class="ruby-identifier">klass</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">is_rails_controller?</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>)
394
+ 115: <span class="ruby-keyword kw">begin</span>
395
+ 116: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">type</span>
396
+ 117: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'i'</span>
397
+ 118: <span class="ruby-identifier">insert_code_to_instance_method</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>)
398
+ 119: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'s'</span>
399
+ 120: <span class="ruby-identifier">insert_code_to_singleton_method</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>)
400
+ 121: <span class="ruby-keyword kw">else</span>
401
+ 122: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;undefined instrumentation type&quot;</span>
402
+ 123: <span class="ruby-keyword kw">end</span>
403
+ 124: <span class="ruby-identifier">$rubyrun_logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;#{klass.to_s}.#{id.id2name} instrumented.&quot;</span>
404
+ 125: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
405
+ 126: <span class="ruby-identifier">$rubyrun_logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Class #{klass.to_s}.#{id.id2name} failed to instrument&quot;</span>
406
+ 127: <span class="ruby-identifier">$rubyrun_logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;\n&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>)
407
+ 128: <span class="ruby-keyword kw">end</span>
408
+ 129: <span class="ruby-keyword kw">end</span>
409
+ </pre>
410
+ </div>
411
+ </div>
412
+ </div>
413
+
414
+ <div id="method-M000045" class="method-detail">
415
+ <a name="M000045"></a>
416
+
417
+ <div class="method-heading">
418
+ <a href="#M000045" class="method-signature">
419
+ <span class="method-name">instrument_thread_new</span><span class="method-args">()</span>
420
+ </a>
421
+ </div>
422
+
423
+ <div class="method-description">
424
+ <p>
425
+ Instrument Thread.new by wrapping target proc with a begin-rescue clause
426
+ around the application block. When the thread monitor shoot the thread via
427
+ thr.raise the rescue clause will catch the interrupt and collect the stack
428
+ entries in $@ and store them in a global hash, later on printed in rubyrun
429
+ log by thread id. If the thread dies naturally, print the stack trace on
430
+ the rubyrun log
431
+ </p>
432
+ <p><a class="source-toggle" href="#"
433
+ onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
434
+ <div class="method-source-code" id="M000045-source">
435
+ <pre>
436
+ <span class="ruby-comment cmt"># File lib/rubyrun/rubyrun_instrumentor__.rb, line 210</span>
437
+ 210: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">instrument_thread_new</span>
438
+ 211: (<span class="ruby-keyword kw">class</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Thread</span>; <span class="ruby-keyword kw">self</span>; <span class="ruby-keyword kw">end</span>).<span class="ruby-identifier">class_eval</span> {
439
+ 212: <span class="ruby-identifier">alias_method</span> <span class="ruby-node">&quot;#{RubyRunGlobals::RUBYRUN_PREFIX}_new&quot;</span>, <span class="ruby-value str">&quot;new&quot;</span>
440
+ 213: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">rubyrun_args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">rubyrun_apps_block</span>)
441
+ 214: <span class="ruby-identifier">rubyrun_proc</span> = <span class="ruby-identifier">lambda</span> {
442
+ 215: <span class="ruby-keyword kw">begin</span>
443
+ 216: <span class="ruby-identifier">rubyrun_apps_block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">rubyrun_args</span>)
444
+ 217: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
445
+ 218: <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span> <span class="ruby-operator">==</span> <span class="ruby-constant">RUBYRUN_KILL_3_STRING</span> <span class="ruby-value">? </span>
446
+ 219: <span class="ruby-identifier">$@</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">$rubyrun_thread_stack</span>[<span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>] <span class="ruby-operator">||=</span> []) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">line</span>} <span class="ruby-operator">:</span>
447
+ 220: <span class="ruby-identifier">$@</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-identifier">$rubyrun_logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;#{line}&quot;</span>}
448
+ 221: <span class="ruby-keyword kw">end</span>
449
+ 222: }
450
+ 223: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{RubyRunGlobals::RUBYRUN_PREFIX}_new&quot;</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">rubyrun_args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">rubyrun_proc</span>)
451
+ 224: <span class="ruby-keyword kw">end</span>
452
+ 225: }
453
+ 226: <span class="ruby-keyword kw">end</span>
454
+ </pre>
455
+ </div>
456
+ </div>
457
+ </div>
458
+
459
+ <div id="method-M000040" class="method-detail">
460
+ <a name="M000040"></a>
461
+
462
+ <div class="method-heading">
463
+ <a href="#M000040" class="method-signature">
464
+ <span class="method-name">is_non_negotiably_excluded?</span><span class="method-args">(type, klass, id)</span>
465
+ </a>
466
+ </div>
467
+
468
+ <div class="method-description">
469
+ <p>
470
+ Never instrument the following classes/methods to avoid recursion
471
+ </p>
472
+ <ol>
473
+ <li>Exclude classes and methods that the instrumentation code uses
474
+
475
+ </li>
476
+ <li>Exclude method=
477
+
478
+ </li>
479
+ <li>Exclude method aliased by rubyrun instrumentation code
480
+
481
+ </li>
482
+ <li>Exclude method re-defined by rubyrun instrumentation code
483
+
484
+ </li>
485
+ <li>Exclude inherited instances, private, protected, and singleton methods.
486
+
487
+ </li>
488
+ </ol>
489
+ <p>
490
+ The way this works is that if m is one of these non-inherited instance
491
+ methods or singleton methods then it should NOT be excluded. Otherwise it
492
+ is assumed it is an inherited one and hence excluded.
493
+ </p>
494
+ <p><a class="source-toggle" href="#"
495
+ onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
496
+ <div class="method-source-code" id="M000040-source">
497
+ <pre>
498
+ <span class="ruby-comment cmt"># File lib/rubyrun/rubyrun_instrumentor__.rb, line 70</span>
499
+ 70: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_non_negotiably_excluded?</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>)
500
+ 71: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">is_in?</span>(<span class="ruby-constant">RUBYRUN_FIREWALL_HASH</span>, <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">id</span>)
501
+ 72: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">id2name</span>[<span class="ruby-value">-1</span>,<span class="ruby-value">1</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'='</span>
502
+ 73: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">id2name</span>[<span class="ruby-value">0</span>, <span class="ruby-constant">RUBYRUN_PREFIX_LENGTH</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">RUBYRUN_PREFIX</span>
503
+ 74: <span class="ruby-identifier">$rubyrun_prev_method</span> = <span class="ruby-identifier">id</span>.<span class="ruby-identifier">id2name</span>
504
+ 75: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
505
+ 76: <span class="ruby-keyword kw">end</span>
506
+ 77: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">$rubyrun_prev_method</span> <span class="ruby-operator">||=</span><span class="ruby-value str">&quot;&quot;</span>).<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">id</span>.<span class="ruby-identifier">id2name</span>)
507
+ 78: <span class="ruby-identifier">$rubyrun_prev_method</span> = <span class="ruby-keyword kw">nil</span>
508
+ 79: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
509
+ 80: <span class="ruby-keyword kw">end</span>
510
+ 81: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'i'</span>
511
+ 82: <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">instance_methods</span>(<span class="ruby-keyword kw">false</span>).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span>
512
+ 83: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">id2name</span>
513
+ 84: }
514
+ 85: <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">private_instance_methods</span>(<span class="ruby-keyword kw">false</span>).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span>
515
+ 86: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">id2name</span>
516
+ 87: }
517
+ 88: <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">protected_instance_methods</span>(<span class="ruby-keyword kw">false</span>).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span>
518
+ 89: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">id2name</span>
519
+ 90: }
520
+ 91: <span class="ruby-keyword kw">else</span>
521
+ 92: <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">singleton_methods</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span>
522
+ 93: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">id2name</span>
523
+ 94: }
524
+ 95: <span class="ruby-keyword kw">end</span>
525
+ 96: <span class="ruby-keyword kw">true</span>
526
+ 97: <span class="ruby-keyword kw">end</span>
527
+ </pre>
528
+ </div>
529
+ </div>
530
+ </div>
531
+
532
+ <div id="method-M000046" class="method-detail">
533
+ <a name="M000046"></a>
534
+
535
+ <div class="method-heading">
536
+ <a href="#M000046" class="method-signature">
537
+ <span class="method-name">new</span><span class="method-args">(*rubyrun_args, &amp;rubyrun_apps_block)</span>
538
+ </a>
539
+ </div>
540
+
541
+ <div class="method-description">
542
+ <p><a class="source-toggle" href="#"
543
+ onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
544
+ <div class="method-source-code" id="M000046-source">
545
+ <pre>
546
+ <span class="ruby-comment cmt"># File lib/rubyrun/rubyrun_instrumentor__.rb, line 213</span>
547
+ 213: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">rubyrun_args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">rubyrun_apps_block</span>)
548
+ 214: <span class="ruby-identifier">rubyrun_proc</span> = <span class="ruby-identifier">lambda</span> {
549
+ 215: <span class="ruby-keyword kw">begin</span>
550
+ 216: <span class="ruby-identifier">rubyrun_apps_block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">rubyrun_args</span>)
551
+ 217: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
552
+ 218: <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span> <span class="ruby-operator">==</span> <span class="ruby-constant">RUBYRUN_KILL_3_STRING</span> <span class="ruby-value">? </span>
553
+ 219: <span class="ruby-identifier">$@</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">$rubyrun_thread_stack</span>[<span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>] <span class="ruby-operator">||=</span> []) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">line</span>} <span class="ruby-operator">:</span>
554
+ 220: <span class="ruby-identifier">$@</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-identifier">$rubyrun_logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;#{line}&quot;</span>}
555
+ 221: <span class="ruby-keyword kw">end</span>
556
+ 222: }
557
+ 223: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{RubyRunGlobals::RUBYRUN_PREFIX}_new&quot;</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">rubyrun_args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">rubyrun_proc</span>)
558
+ 224: <span class="ruby-keyword kw">end</span>
559
+ </pre>
560
+ </div>
561
+ </div>
562
+ </div>
563
+
564
+
565
+ </div>
566
+
567
+
568
+ </div>
569
+
570
+
571
+ <div id="validator-badges">
572
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
573
+ </div>
574
+
575
+ </body>
576
+ </html>