ghazel-newrelic_rpm 3.1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. data/CHANGELOG +525 -0
  2. data/LICENSE +37 -0
  3. data/README.rdoc +179 -0
  4. data/bin/mongrel_rpm +33 -0
  5. data/bin/newrelic +13 -0
  6. data/bin/newrelic_cmd +5 -0
  7. data/cert/cacert.pem +118 -0
  8. data/cert/oldsite.pem +28 -0
  9. data/cert/site.pem +27 -0
  10. data/install.rb +9 -0
  11. data/lib/conditional_vendored_dependency_detection.rb +3 -0
  12. data/lib/conditional_vendored_metric_parser.rb +5 -0
  13. data/lib/new_relic/agent.rb +423 -0
  14. data/lib/new_relic/agent/agent.rb +1040 -0
  15. data/lib/new_relic/agent/beacon_configuration.rb +61 -0
  16. data/lib/new_relic/agent/browser_monitoring.rb +83 -0
  17. data/lib/new_relic/agent/busy_calculator.rb +91 -0
  18. data/lib/new_relic/agent/chained_call.rb +13 -0
  19. data/lib/new_relic/agent/error_collector.rb +203 -0
  20. data/lib/new_relic/agent/instrumentation.rb +9 -0
  21. data/lib/new_relic/agent/instrumentation/active_merchant.rb +21 -0
  22. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +62 -0
  23. data/lib/new_relic/agent/instrumentation/authlogic.rb +13 -0
  24. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +413 -0
  25. data/lib/new_relic/agent/instrumentation/data_mapper.rb +232 -0
  26. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +44 -0
  27. data/lib/new_relic/agent/instrumentation/memcache.rb +56 -0
  28. data/lib/new_relic/agent/instrumentation/merb/controller.rb +36 -0
  29. data/lib/new_relic/agent/instrumentation/merb/errors.rb +23 -0
  30. data/lib/new_relic/agent/instrumentation/metric_frame.rb +326 -0
  31. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +84 -0
  32. data/lib/new_relic/agent/instrumentation/net.rb +23 -0
  33. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +34 -0
  34. data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
  35. data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
  36. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +83 -0
  37. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +36 -0
  38. data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +108 -0
  39. data/lib/new_relic/agent/instrumentation/rails/errors.rb +36 -0
  40. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +60 -0
  41. data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +112 -0
  42. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +31 -0
  43. data/lib/new_relic/agent/instrumentation/sinatra.rb +54 -0
  44. data/lib/new_relic/agent/instrumentation/sunspot.rb +23 -0
  45. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +16 -0
  46. data/lib/new_relic/agent/method_tracer.rb +422 -0
  47. data/lib/new_relic/agent/sampler.rb +50 -0
  48. data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
  49. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +40 -0
  50. data/lib/new_relic/agent/samplers/memory_sampler.rb +144 -0
  51. data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
  52. data/lib/new_relic/agent/shim_agent.rb +29 -0
  53. data/lib/new_relic/agent/stats_engine.rb +24 -0
  54. data/lib/new_relic/agent/stats_engine/metric_stats.rb +182 -0
  55. data/lib/new_relic/agent/stats_engine/samplers.rb +89 -0
  56. data/lib/new_relic/agent/stats_engine/transactions.rb +184 -0
  57. data/lib/new_relic/agent/transaction_sample_builder.rb +101 -0
  58. data/lib/new_relic/agent/transaction_sampler.rb +378 -0
  59. data/lib/new_relic/agent/worker_loop.rb +81 -0
  60. data/lib/new_relic/collection_helper.rb +69 -0
  61. data/lib/new_relic/command.rb +85 -0
  62. data/lib/new_relic/commands/deployments.rb +105 -0
  63. data/lib/new_relic/commands/install.rb +91 -0
  64. data/lib/new_relic/control.rb +48 -0
  65. data/lib/new_relic/control/class_methods.rb +47 -0
  66. data/lib/new_relic/control/configuration.rb +157 -0
  67. data/lib/new_relic/control/frameworks/external.rb +16 -0
  68. data/lib/new_relic/control/frameworks/merb.rb +30 -0
  69. data/lib/new_relic/control/frameworks/rails.rb +151 -0
  70. data/lib/new_relic/control/frameworks/rails3.rb +70 -0
  71. data/lib/new_relic/control/frameworks/ruby.rb +42 -0
  72. data/lib/new_relic/control/frameworks/sinatra.rb +23 -0
  73. data/lib/new_relic/control/instance_methods.rb +154 -0
  74. data/lib/new_relic/control/instrumentation.rb +81 -0
  75. data/lib/new_relic/control/logging_methods.rb +88 -0
  76. data/lib/new_relic/control/profiling.rb +25 -0
  77. data/lib/new_relic/control/server_methods.rb +104 -0
  78. data/lib/new_relic/data_serialization.rb +84 -0
  79. data/lib/new_relic/delayed_job_injection.rb +38 -0
  80. data/lib/new_relic/histogram.rb +91 -0
  81. data/lib/new_relic/local_environment.rb +391 -0
  82. data/lib/new_relic/merbtasks.rb +6 -0
  83. data/lib/new_relic/metric_data.rb +46 -0
  84. data/lib/new_relic/metric_spec.rb +73 -0
  85. data/lib/new_relic/metrics.rb +9 -0
  86. data/lib/new_relic/noticed_error.rb +24 -0
  87. data/lib/new_relic/rack/browser_monitoring.rb +68 -0
  88. data/lib/new_relic/rack/developer_mode.rb +267 -0
  89. data/lib/new_relic/rack/metric_app.rb +65 -0
  90. data/lib/new_relic/rack/mongrel_rpm.ru +28 -0
  91. data/lib/new_relic/rack/newrelic.yml +27 -0
  92. data/lib/new_relic/rack_app.rb +6 -0
  93. data/lib/new_relic/recipes.rb +73 -0
  94. data/lib/new_relic/stats.rb +378 -0
  95. data/lib/new_relic/timer_lib.rb +27 -0
  96. data/lib/new_relic/transaction_analysis.rb +76 -0
  97. data/lib/new_relic/transaction_analysis/segment_summary.rb +47 -0
  98. data/lib/new_relic/transaction_sample.rb +272 -0
  99. data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
  100. data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
  101. data/lib/new_relic/transaction_sample/segment.rb +251 -0
  102. data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
  103. data/lib/new_relic/url_rule.rb +14 -0
  104. data/lib/new_relic/version.rb +55 -0
  105. data/lib/newrelic_rpm.rb +49 -0
  106. data/lib/tasks/all.rb +4 -0
  107. data/lib/tasks/install.rake +7 -0
  108. data/lib/tasks/tests.rake +19 -0
  109. data/newrelic.yml +265 -0
  110. data/newrelic_rpm.gemspec +330 -0
  111. data/recipes/newrelic.rb +6 -0
  112. data/test/active_record_fixtures.rb +77 -0
  113. data/test/config/newrelic.yml +48 -0
  114. data/test/config/test_control.rb +48 -0
  115. data/test/new_relic/agent/agent/connect_test.rb +316 -0
  116. data/test/new_relic/agent/agent/start_test.rb +340 -0
  117. data/test/new_relic/agent/agent/start_worker_thread_test.rb +155 -0
  118. data/test/new_relic/agent/agent_test.rb +173 -0
  119. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  120. data/test/new_relic/agent/agent_test_controller_test.rb +366 -0
  121. data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
  122. data/test/new_relic/agent/beacon_configuration_test.rb +104 -0
  123. data/test/new_relic/agent/browser_monitoring_test.rb +274 -0
  124. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  125. data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
  126. data/test/new_relic/agent/error_collector_test.rb +168 -0
  127. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +522 -0
  128. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +36 -0
  129. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
  130. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +179 -0
  131. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
  132. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
  133. data/test/new_relic/agent/instrumentation/queue_time_test.rb +387 -0
  134. data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
  135. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
  136. data/test/new_relic/agent/memcache_instrumentation_test.rb +107 -0
  137. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
  138. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
  139. data/test/new_relic/agent/method_tracer_test.rb +386 -0
  140. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  141. data/test/new_relic/agent/rpm_agent_test.rb +149 -0
  142. data/test/new_relic/agent/sampler_test.rb +19 -0
  143. data/test/new_relic/agent/shim_agent_test.rb +20 -0
  144. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
  145. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +81 -0
  146. data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
  147. data/test/new_relic/agent/stats_engine_test.rb +185 -0
  148. data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
  149. data/test/new_relic/agent/transaction_sampler_test.rb +945 -0
  150. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  151. data/test/new_relic/collection_helper_test.rb +127 -0
  152. data/test/new_relic/command/deployments_test.rb +68 -0
  153. data/test/new_relic/control/class_methods_test.rb +62 -0
  154. data/test/new_relic/control/logging_methods_test.rb +157 -0
  155. data/test/new_relic/control_test.rb +195 -0
  156. data/test/new_relic/data_serialization_test.rb +70 -0
  157. data/test/new_relic/local_environment_test.rb +72 -0
  158. data/test/new_relic/metric_data_test.rb +125 -0
  159. data/test/new_relic/metric_spec_test.rb +95 -0
  160. data/test/new_relic/rack/all_test.rb +11 -0
  161. data/test/new_relic/rack/browser_monitoring_test.rb +84 -0
  162. data/test/new_relic/rack/developer_mode_test.rb +43 -0
  163. data/test/new_relic/stats_test.rb +426 -0
  164. data/test/new_relic/transaction_analysis/segment_summary_test.rb +77 -0
  165. data/test/new_relic/transaction_analysis_test.rb +121 -0
  166. data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
  167. data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
  168. data/test/new_relic/transaction_sample/segment_test.rb +454 -0
  169. data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
  170. data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
  171. data/test/new_relic/transaction_sample_test.rb +170 -0
  172. data/test/new_relic/version_number_test.rb +89 -0
  173. data/test/test_contexts.rb +29 -0
  174. data/test/test_helper.rb +144 -0
  175. data/ui/helpers/developer_mode_helper.rb +351 -0
  176. data/ui/helpers/google_pie_chart.rb +49 -0
  177. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  178. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  179. data/ui/views/newrelic/_sample.rhtml +20 -0
  180. data/ui/views/newrelic/_segment.rhtml +28 -0
  181. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  182. data/ui/views/newrelic/_segment_row.rhtml +12 -0
  183. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  184. data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
  185. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  186. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  187. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  188. data/ui/views/newrelic/_table.rhtml +12 -0
  189. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  190. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  191. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  192. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  193. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  194. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  195. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  196. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  197. data/ui/views/newrelic/file/images/textmate.png +0 -0
  198. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  199. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  200. data/ui/views/newrelic/file/stylesheets/style.css +490 -0
  201. data/ui/views/newrelic/index.rhtml +71 -0
  202. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  203. data/ui/views/newrelic/show_sample.rhtml +80 -0
  204. data/ui/views/newrelic/show_source.rhtml +3 -0
  205. data/ui/views/newrelic/threads.rhtml +53 -0
  206. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +19 -0
  207. data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
  208. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +57 -0
  209. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
  210. data/vendor/gems/metric_parser-0.1.0.pre1/LICENSE +0 -0
  211. data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -0
  212. data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
  213. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
  214. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
  215. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
  216. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
  217. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
  218. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
  219. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
  220. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
  221. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
  222. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
  223. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
  224. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
  225. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
  226. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
  227. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
  228. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
  229. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
  230. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
  231. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
  232. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
  233. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
  234. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
  235. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
  236. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
  237. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +122 -0
  238. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
  239. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
  240. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
  241. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
  242. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
  243. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
  244. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
  245. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
  246. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
  247. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
  248. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
  249. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
  250. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
  251. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +66 -0
  252. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
  253. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
  254. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
  255. metadata +399 -0
@@ -0,0 +1,232 @@
1
+ ## NewRelic instrumentation for DataMapper
2
+ #
3
+ # Instrumenting DM has different key challenges versus AR:
4
+ #
5
+ # 1. The hooking of SQL logging in DM is decoupled from any knowledge of the
6
+ # Model#method that invoked it. But on the positive side, the duration is
7
+ # already calculated for you (and it happens inside the C-based DO code, so
8
+ # it's faster than a Ruby equivalent).
9
+ #
10
+ # 2. There are a lot more entry points that need to be hooked in order to
11
+ # understand call flow: DM::Model (model class) vs. DM::Resource (model
12
+ # instance) vs. DM::Collection (collection of model instances). And
13
+ # others.
14
+ #
15
+ # 3. Strategic Eager Loading (SEL) combined with separately-grouped
16
+ # lazy-loaded attributes presents a unique problem for tying resulting
17
+ # SEL-invoked SQL calls to their proper scope.
18
+ #
19
+ # NOTE: On using "Database" versus "ActiveRecord" as base metric name
20
+ #
21
+ # Using "Database" as the metric name base seems to properly identify methods
22
+ # as being DB-related in call graphs, but certain New Relic views that show
23
+ # aggregations of DB CPM, etc still seem to rely solely on "ActiveRecord"
24
+ # being the base name, thus AFAICT "Database" calls to this are lost. (Though
25
+ # I haven't yet tested "Database/SQL/{find/save/destroy/all}" yet, as it seems
26
+ # like an intuitively good name to use.)
27
+ #
28
+ # So far I think these are the rules:
29
+ #
30
+ # - ActiveRecord/{find/save/destroy} populates "Database Throughput" and
31
+ # "Database Response Time" in the Database tab. [non-scoped]
32
+ #
33
+ # - ActiveRecord/all populates the main Overview tab of DB time. (still
34
+ # unsure about this one). [non-scoped]
35
+ #
36
+ # These metrics are represented as :push_scope => false or included as the
37
+ # non-first metric in trace_execution_scoped() (docs say only first counts
38
+ # towards scope) so they don't show up ine normal call graph/trace.
39
+
40
+ DependencyDetection.defer do
41
+ depends_on do
42
+ defined?(::DataMapper)
43
+ end
44
+
45
+ depends_on do
46
+ defined?(DataMapper::Model)
47
+ end
48
+
49
+ depends_on do
50
+ defined?(DataMapper::Resource)
51
+ end
52
+
53
+ depends_on do
54
+ defined?(DataMapper::Collection)
55
+ end
56
+
57
+ executes do
58
+ DataMapper::Model.class_eval do
59
+ add_method_tracer :get, 'ActiveRecord/#{self.name}/get'
60
+ add_method_tracer :first, 'ActiveRecord/#{self.name}/first'
61
+ add_method_tracer :last, 'ActiveRecord/#{self.name}/last'
62
+ add_method_tracer :all, 'ActiveRecord/#{self.name}/all'
63
+
64
+ add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
65
+ add_method_tracer :create!, 'ActiveRecord/#{self.name}/create'
66
+ add_method_tracer :update, 'ActiveRecord/#{self.name}/update'
67
+ add_method_tracer :update!, 'ActiveRecord/#{self.name}/update'
68
+ add_method_tracer :destroy, 'ActiveRecord/#{self.name}/destroy'
69
+ add_method_tracer :destroy!, 'ActiveRecord/#{self.name}/destroy'
70
+
71
+ # For dm-aggregates and partial dm-ar-finders support:
72
+ for method in [ :aggregate, :find, :find_by_sql ] do
73
+ next unless method_defined? method
74
+ add_method_tracer(method, 'ActiveRecord/#{self.name}/' + method.to_s)
75
+ end
76
+
77
+ end
78
+ end
79
+
80
+ executes do
81
+ DataMapper::Resource.class_eval do
82
+ add_method_tracer :update, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/update'
83
+ add_method_tracer :update!, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/update'
84
+ add_method_tracer :save, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/save'
85
+ add_method_tracer :save!, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/save'
86
+ add_method_tracer :destroy, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/destroy'
87
+ add_method_tracer :destroy!, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/destroy'
88
+
89
+ end
90
+ end
91
+
92
+ executes do
93
+ DataMapper::Collection.class_eval do
94
+ # DM's Collection instance methods
95
+ add_method_tracer :get, 'ActiveRecord/#{self.name}/get'
96
+ add_method_tracer :first, 'ActiveRecord/#{self.name}/first'
97
+ add_method_tracer :last, 'ActiveRecord/#{self.name}/last'
98
+ add_method_tracer :all, 'ActiveRecord/#{self.name}/all'
99
+
100
+ add_method_tracer :lazy_load, 'ActiveRecord/#{self.name}/lazy_load'
101
+
102
+ add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
103
+ add_method_tracer :create!, 'ActiveRecord/#{self.name}/create'
104
+ add_method_tracer :update, 'ActiveRecord/#{self.name}/update'
105
+ add_method_tracer :update!, 'ActiveRecord/#{self.name}/update'
106
+ add_method_tracer :destroy, 'ActiveRecord/#{self.name}/destroy'
107
+ add_method_tracer :destroy!, 'ActiveRecord/#{self.name}/destroy'
108
+
109
+ # For dm-aggregates support:
110
+ for method in [ :aggregate ] do
111
+ next unless method_defined? method
112
+ add_method_tracer(method, 'ActiveRecord/#{self.name}/' + method.to_s)
113
+ end
114
+
115
+ end
116
+ end
117
+ end
118
+
119
+ DependencyDetection.defer do
120
+
121
+ depends_on do
122
+ defined?(DataMapper) && defined?(DataMapper::Adapters) && defined?(DataMapper::Adapters::DataObjectsAdapter)
123
+ end
124
+
125
+ executes do
126
+
127
+ # Catch the two entry points into DM::Repository::Adapter that bypass CRUD
128
+ # (for when SQL is run directly).
129
+ DataMapper::Adapters::DataObjectsAdapter.class_eval do
130
+
131
+ add_method_tracer :select, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/select'
132
+ add_method_tracer :execute, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/execute'
133
+
134
+ end
135
+ end
136
+ end
137
+
138
+ DependencyDetection.defer do
139
+
140
+ depends_on do
141
+ defined?(DataMapper) && defined?(DataMapper::Validations) && defined?(DataMapper::Validations::ClassMethods)
142
+ end
143
+
144
+ # DM::Validations overrides Model#create, but currently in a way that makes it
145
+ # impossible to instrument from one place. I've got a patch pending inclusion
146
+ # to make it instrumentable by putting the create method inside ClassMethods.
147
+ # This will pick it up if/when that patch is accepted.
148
+ executes do
149
+ DataMapper::Validations::ClassMethods.class_eval do
150
+ next unless method_defined? :create
151
+ add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
152
+ end
153
+ end
154
+ end
155
+
156
+ DependencyDetection.defer do
157
+
158
+ depends_on do
159
+ defined?(DataMapper) && defined?(DataMapper::Transaction)
160
+ end
161
+
162
+ # NOTE: DM::Transaction basically calls commit() twice, so as-is it will show
163
+ # up in traces twice -- second time subordinate to the first's scope. Works
164
+ # well enough.
165
+ executes do
166
+ DataMapper::Transaction.module_eval do
167
+ add_method_tracer :commit, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/commit'
168
+ end
169
+ end
170
+ end
171
+
172
+
173
+ module NewRelic
174
+ module Agent
175
+ module Instrumentation
176
+ module DataMapperInstrumentation
177
+
178
+ def self.included(klass)
179
+ klass.class_eval do
180
+ alias_method :log_without_newrelic_instrumentation, :log
181
+ alias_method :log, :log_with_newrelic_instrumentation
182
+ end
183
+ end
184
+
185
+ # Unlike in AR, log is called in DM after the query actually ran,
186
+ # complete with metrics. Since DO has already calculated the
187
+ # duration, there's nothing more to measure, so just record and log.
188
+ #
189
+ # We rely on the assumption that all possible entry points have been
190
+ # hooked with tracers, ensuring that notice_sql attaches this SQL to
191
+ # the proper call scope.
192
+ def log_with_newrelic_instrumentation(msg)
193
+ return unless NewRelic::Agent.is_execution_traced?
194
+ return unless operation = case msg.query
195
+ when /^\s*select/i then 'find'
196
+ when /^\s*(update|insert)/i then 'save'
197
+ when /^\s*delete/i then 'destroy'
198
+ else nil
199
+ end
200
+
201
+ # FYI: self.to_s will yield connection URI string.
202
+ duration = msg.duration / 1000000.0
203
+
204
+ # Attach SQL to current segment/scope.
205
+ NewRelic::Agent.instance.transaction_sampler.notice_sql(msg.query, nil, duration)
206
+
207
+ # Record query duration associated with each of the desired metrics.
208
+ metrics = [ "ActiveRecord/#{operation}", 'ActiveRecord/all' ]
209
+ metrics.each do |metric|
210
+ NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric).trace_call(duration)
211
+ end
212
+ ensure
213
+ log_without_newrelic_instrumentation(msg)
214
+ end
215
+
216
+ end # DataMapperInstrumentation
217
+ end # Instrumentation
218
+ end # Agent
219
+ end # NewRelic
220
+
221
+ DependencyDetection.defer do
222
+
223
+ depends_on do
224
+ defined?(DataObjects) && defined?(DataObjects::Connection)
225
+ end
226
+
227
+ executes do
228
+ DataObjects::Connection.class_eval do
229
+ include ::NewRelic::Agent::Instrumentation::DataMapperInstrumentation
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,44 @@
1
+ require 'new_relic/agent/instrumentation/controller_instrumentation'
2
+
3
+ DependencyDetection.defer do
4
+ depends_on do
5
+ !NewRelic::Control.instance['disable_dj']
6
+ end
7
+
8
+ depends_on do
9
+ defined?(::Delayed) && defined?(::Delayed::Job)
10
+ end
11
+
12
+ executes do
13
+ Delayed::Job.class_eval do
14
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
15
+ if self.instance_methods.include?('name')
16
+ add_transaction_tracer "invoke_job", :category => 'OtherTransaction/DelayedJob', :path => '#{self.name}'
17
+ else
18
+ add_transaction_tracer "invoke_job", :category => 'OtherTransaction/DelayedJob'
19
+ end
20
+ end
21
+ end
22
+
23
+ executes do
24
+ Delayed::Job.instance_eval do
25
+ if self.respond_to?('after_fork')
26
+ if method_defined?(:after_fork)
27
+ def after_fork_with_newrelic
28
+ NewRelic::Agent.after_fork(:force_reconnect => true)
29
+ after_fork_without_newrelic
30
+ end
31
+
32
+ alias_method :after_fork_without_newrelic, :after_fork
33
+ alias_method :after_fork, :after_fork_with_newrelic
34
+ else
35
+ def after_fork
36
+ NewRelic::Agent.after_fork(:force_reconnect => true)
37
+ super
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,56 @@
1
+ # NOTE there are multiple implementations of the MemCache client in Ruby,
2
+ # each with slightly different API's and semantics.
3
+ # See:
4
+ # http://www.deveiate.org/code/Ruby-MemCache/ (Gem: Ruby-MemCache)
5
+ # http://seattlerb.rubyforge.org/memcache-client/ (Gem: memcache-client)
6
+ # http://github.com/mperham/dalli (Gem: dalli)
7
+
8
+ module NewRelic
9
+ module Agent
10
+ module Instrumentation
11
+ module Memcache
12
+ module_function
13
+ def instrument_method(the_class, method_name)
14
+ return unless the_class.method_defined? method_name.to_sym
15
+ the_class.class_eval <<-EOD
16
+ def #{method_name}_with_newrelic_trace(*args)
17
+ metrics = ["MemCache/#{method_name}",
18
+ (NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction? ? 'MemCache/allWeb' : 'MemCache/allOther')]
19
+ self.class.trace_execution_scoped(metrics) do
20
+ t0 = Time.now
21
+ begin
22
+ #{method_name}_without_newrelic_trace(*args)
23
+ ensure
24
+ #{memcache_key_snippet(method_name)}
25
+ end
26
+ end
27
+ end
28
+ alias #{method_name}_without_newrelic_trace #{method_name}
29
+ alias #{method_name} #{method_name}_with_newrelic_trace
30
+ EOD
31
+ end
32
+ def memcache_key_snippet(method_name)
33
+ return "" unless NewRelic::Control.instance['capture_memcache_keys']
34
+ "NewRelic::Agent.instance.transaction_sampler.notice_nosql(args.first.inspect, (Time.now - t0).to_f) rescue nil"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+
42
+
43
+
44
+ DependencyDetection.defer do
45
+ depends_on do
46
+ !NewRelic::Control.instance['disable_memcache_instrumentation']
47
+ end
48
+
49
+ executes do
50
+ %w[get get_multi set add incr decr delete replace append prepend cas].each do | method_name |
51
+ NewRelic::Agent::Instrumentation::Memcache.instrument_method(::MemCache, method_name) if defined? ::MemCache
52
+ NewRelic::Agent::Instrumentation::Memcache.instrument_method(::Memcached, method_name) if defined? ::Memcached
53
+ NewRelic::Agent::Instrumentation::Memcache.instrument_method(::Dalli::Client, method_name) if defined? ::Dalli::Client
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,36 @@
1
+ require 'set'
2
+
3
+ DependencyDetection.defer do
4
+
5
+ depends_on do
6
+ defined?(Merb) && defined?(Merb::Controller)
7
+ end
8
+
9
+ executes do
10
+ require 'merb-core/controller/merb_controller'
11
+
12
+ Merb::Controller.class_eval do
13
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
14
+
15
+ class_inheritable_accessor :do_not_trace
16
+ class_inheritable_accessor :ignore_apdex
17
+
18
+ def self.newrelic_write_attr(attr_name, value) # :nodoc:
19
+ self.send "#{attr_name}=", attr_name, value
20
+ end
21
+
22
+ def self.newrelic_read_attr(attr_name) # :nodoc:
23
+ self.send attr_name
24
+ end
25
+
26
+ protected
27
+ # determine the path that is used in the metric name for
28
+ # the called controller action
29
+ def newrelic_metric_path
30
+ "#{controller_name}/#{action_name}"
31
+ end
32
+ alias_method :perform_action_without_newrelic_trace, :_dispatch
33
+ alias_method :_dispatch, :perform_action_with_newrelic_trace
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ DependencyDetection.defer do
2
+ depends_on do
3
+ defined?(Merb) && defined?(Merb::Dispatcher) && defined?(Merb::Dispatcher::DefaultException)
4
+ end
5
+
6
+ depends_on do
7
+ Merb::Dispatcher::DefaultException.respond_to?(:before)
8
+ end
9
+
10
+ executes do
11
+
12
+ # Hook in the notification to merb
13
+ error_notifier = Proc.new {
14
+ if request.exceptions #check that there's actually an exception
15
+ # Note, this assumes we have already captured the other information such as uri and params in the MetricFrame.
16
+ NewRelic::Agent::Instrumentation::MetricFrame.notice_error(request.exceptions.first)
17
+ end
18
+ }
19
+ Merb::Dispatcher::DefaultException.before error_notifier
20
+ Exceptions.before error_notifier
21
+
22
+ end
23
+ end
@@ -0,0 +1,326 @@
1
+ require 'new_relic/agent/instrumentation/metric_frame/pop'
2
+
3
+ # A struct holding the information required to measure a controller
4
+ # action. This is put on the thread local. Handles the issue of
5
+ # re-entrancy, or nested action calls.
6
+ #
7
+ # This class is not part of the public API. Avoid making calls on it directly.
8
+ #
9
+ module NewRelic
10
+ module Agent
11
+ module Instrumentation
12
+ class MetricFrame
13
+ # helper module refactored out of the `pop` method
14
+ include Pop
15
+
16
+ attr_accessor :start # A Time instance for the start time, never nil
17
+ attr_accessor :apdex_start # A Time instance used for calculating the apdex score, which
18
+ # might end up being @start, or it might be further upstream if
19
+ # we can find a request header for the queue entry time
20
+ attr_accessor :exception,
21
+ :filtered_params, :force_flag,
22
+ :jruby_cpu_start, :process_cpu_start, :database_metric_name
23
+
24
+ # Give the current metric frame a request context. Use this to
25
+ # get the URI and referer. The request is interpreted loosely
26
+ # as a Rack::Request or an ActionController::AbstractRequest.
27
+ attr_accessor :request
28
+
29
+
30
+ @@check_server_connection = false
31
+ def self.check_server_connection=(value)
32
+ @@check_server_connection = value
33
+ end
34
+ # Return the currently active metric frame, or nil. Call with +true+
35
+ # to create a new metric frame if one is not already on the thread.
36
+ def self.current(create_if_empty=nil)
37
+ f = Thread.current[:newrelic_metric_frame]
38
+ return f if f || !create_if_empty
39
+
40
+ # Reconnect to the server if necessary. This is only done
41
+ # for old versions of passenger that don't implement an explicit after_fork
42
+ # event.
43
+ agent.after_fork(:keep_retrying => false) if @@check_server_connection
44
+
45
+ Thread.current[:newrelic_metric_frame] = new
46
+ end
47
+
48
+ # This is the name of the model currently assigned to database
49
+ # measurements, overriding the default.
50
+ def self.database_metric_name
51
+ current && current.database_metric_name
52
+ end
53
+
54
+ def self.referer
55
+ current && current.referer
56
+ end
57
+
58
+ def self.agent
59
+ NewRelic::Agent.instance
60
+ end
61
+
62
+ @@java_classes_loaded = false
63
+
64
+ if defined? JRuby
65
+ begin
66
+ require 'java'
67
+ include_class 'java.lang.management.ManagementFactory'
68
+ include_class 'com.sun.management.OperatingSystemMXBean'
69
+ @@java_classes_loaded = true
70
+ rescue Exception => e
71
+ end
72
+ end
73
+
74
+ attr_reader :depth
75
+
76
+ def initialize
77
+ Thread.current[:newrelic_start_time] = @start = Time.now
78
+ @path_stack = [] # stack of [controller, path] elements
79
+ @jruby_cpu_start = jruby_cpu_time
80
+ @process_cpu_start = process_cpu
81
+ end
82
+
83
+ def agent
84
+ NewRelic::Agent.instance
85
+ end
86
+
87
+ def transaction_sampler
88
+ agent.transaction_sampler
89
+ end
90
+
91
+ private :agent
92
+ private :transaction_sampler
93
+
94
+
95
+ # Indicate that we are entering a measured controller action or task.
96
+ # Make sure you unwind every push with a pop call.
97
+ def push(m)
98
+ transaction_sampler.notice_first_scope_push(start)
99
+ @path_stack.push NewRelic::MetricParser::MetricParser.for_metric_named(m)
100
+ end
101
+
102
+ # Indicate that you don't want to keep the currently saved transaction
103
+ # information
104
+ def self.abort_transaction!
105
+ current.abort_transaction! if current
106
+ end
107
+
108
+ # For the current web transaction, return the path of the URI minus the host part and query string, or nil.
109
+ def uri
110
+ @uri ||= self.class.uri_from_request(@request) unless @request.nil?
111
+ end
112
+
113
+ # For the current web transaction, return the full referer, minus the host string, or nil.
114
+ def referer
115
+ @referer ||= self.class.referer_from_request(@request)
116
+ end
117
+
118
+ # Call this to ensure that the current transaction is not saved
119
+ def abort_transaction!
120
+ transaction_sampler.ignore_transaction
121
+ end
122
+ # This needs to be called after entering the call to trace the
123
+ # controller action, otherwise the controller action blames
124
+ # itself. It gets reset in the normal #pop call.
125
+ def start_transaction
126
+ agent.stats_engine.start_transaction metric_name
127
+ # Only push the transaction context info once, on entry:
128
+ if @path_stack.size == 1
129
+ transaction_sampler.notice_transaction(metric_name, uri, filtered_params)
130
+ end
131
+ end
132
+
133
+ def current_metric
134
+ @path_stack.last
135
+ end
136
+
137
+ # Return the path, the part of the metric after the category
138
+ def path
139
+ @path_stack.last.last
140
+ end
141
+
142
+ # Unwind one stack level. It knows if it's back at the outermost caller and
143
+ # does the appropriate wrapup of the context.
144
+ def pop
145
+ metric = @path_stack.pop
146
+ log_underflow if metric.nil?
147
+ if @path_stack.empty?
148
+ handle_empty_path_stack(metric)
149
+ else
150
+ set_new_scope!(current_stack_metric)
151
+ end
152
+ end
153
+
154
+ # If we have an active metric frame, notice the error and increment the error metric.
155
+ # Options:
156
+ # * <tt>:request</tt> => Request object to get the uri and referer
157
+ # * <tt>:uri</tt> => The request path, minus any request params or query string.
158
+ # * <tt>:referer</tt> => The URI of the referer
159
+ # * <tt>:metric</tt> => The metric name associated with the transaction
160
+ # * <tt>:request_params</tt> => Request parameters, already filtered if necessary
161
+ # * <tt>:custom_params</tt> => Custom parameters
162
+ # Anything left over is treated as custom params
163
+
164
+ def self.notice_error(e, options={})
165
+ request = options.delete(:request)
166
+ if request
167
+ options[:referer] = referer_from_request(request)
168
+ options[:uri] = uri_from_request(request)
169
+ end
170
+ if current
171
+ current.notice_error(e, options)
172
+ else
173
+ agent.error_collector.notice_error(e, options)
174
+ end
175
+ end
176
+
177
+ # Do not call this. Invoke the class method instead.
178
+ def notice_error(e, options={}) # :nodoc:
179
+ params = custom_parameters
180
+ options[:referer] = referer if referer
181
+ options[:request_params] = filtered_params if filtered_params
182
+ options[:uri] = uri if uri
183
+ options[:metric] = metric_name
184
+ options.merge!(custom_parameters)
185
+ if exception != e
186
+ result = agent.error_collector.notice_error(e, options)
187
+ self.exception = result if result
188
+ end
189
+ end
190
+
191
+ # Add context parameters to the metric frame. This information will be passed in to errors
192
+ # and transaction traces. Keys and Values should be strings, numbers or date/times.
193
+ def self.add_custom_parameters(p)
194
+ current.add_custom_parameters(p) if current
195
+ end
196
+
197
+ def self.custom_parameters
198
+ (current && current.custom_parameters) ? current.custom_parameters : {}
199
+ end
200
+
201
+ def record_apdex()
202
+ return unless recording_web_transaction? && NewRelic::Agent.is_execution_traced?
203
+ t = Time.now
204
+ self.class.record_apdex(current_metric, t - start, t - apdex_start, !exception.nil?)
205
+ end
206
+
207
+ def metric_name
208
+ return nil if @path_stack.empty?
209
+ current_metric.name
210
+ end
211
+
212
+ # Return the array of metrics to record for the current metric frame.
213
+ def recorded_metrics
214
+ metrics = [ metric_name ]
215
+ metrics += current_metric.summary_metrics if @path_stack.size == 1
216
+ metrics
217
+ end
218
+
219
+ # Yield to a block that is run with a database metric name context. This means
220
+ # the Database instrumentation will use this for the metric name if it does not
221
+ # otherwise know about a model. This is re-entrant.
222
+ #
223
+ # * <tt>model</tt> is the DB model class
224
+ # * <tt>method</tt> is the name of the finder method or other method to identify the operation with.
225
+ #
226
+ def with_database_metric_name(model, method)
227
+ previous = @database_metric_name
228
+ model_name = case model
229
+ when Class
230
+ model.name
231
+ when String
232
+ model
233
+ else
234
+ model.to_s
235
+ end
236
+ @database_metric_name = "ActiveRecord/#{model_name}/#{method}"
237
+ yield
238
+ ensure
239
+ @database_metric_name=previous
240
+ end
241
+
242
+ def custom_parameters
243
+ @custom_parameters ||= {}
244
+ end
245
+
246
+ def add_custom_parameters(p)
247
+ custom_parameters.merge!(p)
248
+ end
249
+
250
+ def self.recording_web_transaction?
251
+ c = Thread.current[:newrelic_metric_frame]
252
+ if c
253
+ c.recording_web_transaction?
254
+ end
255
+ end
256
+
257
+ def recording_web_transaction?
258
+ current_metric && current_metric.is_web_transaction?
259
+ end
260
+
261
+ def is_web_transaction?(metric)
262
+ 0 == metric.index("Controller")
263
+ end
264
+
265
+ # Make a safe attempt to get the referer from a request object, generally successful when
266
+ # it's a Rack request.
267
+ def self.referer_from_request(request)
268
+ if request && request.respond_to?(:referer)
269
+ request.referer.to_s.split('?').first
270
+ end
271
+ end
272
+
273
+ # Make a safe attempt to get the URI, without the host and query string.
274
+ def self.uri_from_request(request)
275
+ approximate_uri = case
276
+ when request.respond_to?(:fullpath) then request.fullpath
277
+ when request.respond_to?(:path) then request.path
278
+ when request.respond_to?(:request_uri) then request.request_uri
279
+ when request.respond_to?(:uri) then request.uri
280
+ when request.respond_to?(:url) then request.url
281
+ end
282
+ return approximate_uri[%r{^(https?://.*?)?(/[^?]*)}, 2] || '/' if approximate_uri # '
283
+ end
284
+
285
+ def self.record_apdex(current_metric, action_duration, total_duration, is_error)
286
+ summary_stat = agent.stats_engine.get_custom_stats("Apdex", NewRelic::ApdexStats)
287
+ controller_stat = agent.stats_engine.get_custom_stats(current_metric.apdex_metric_path, NewRelic::ApdexStats)
288
+ update_apdex(summary_stat, total_duration, is_error)
289
+ update_apdex(controller_stat, action_duration, is_error)
290
+ end
291
+
292
+ # Record an apdex value for the given stat. when `failed`
293
+ # the apdex should be recorded as a failure regardless of duration.
294
+ def self.update_apdex(stat, duration, failed)
295
+ duration = duration.to_f
296
+ apdex_t = NewRelic::Control.instance.apdex_t
297
+ case
298
+ when failed
299
+ stat.record_apdex_f
300
+ when duration <= apdex_t
301
+ stat.record_apdex_s
302
+ when duration <= 4 * apdex_t
303
+ stat.record_apdex_t
304
+ else
305
+ stat.record_apdex_f
306
+ end
307
+ end
308
+
309
+ private
310
+
311
+ def process_cpu
312
+ return nil if defined? JRuby
313
+ p = Process.times
314
+ p.stime + p.utime
315
+ end
316
+
317
+ def jruby_cpu_time # :nodoc:
318
+ return nil unless @@java_classes_loaded
319
+ threadMBean = ManagementFactory.getThreadMXBean()
320
+ java_utime = threadMBean.getCurrentThreadUserTime() # ns
321
+ -1 == java_utime ? 0.0 : java_utime/1e9
322
+ end
323
+ end
324
+ end
325
+ end
326
+ end