wd_newrelic_rpm 3.3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/CHANGELOG +591 -0
  2. data/LICENSE +64 -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 +467 -0
  14. data/lib/new_relic/agent/agent.rb +1325 -0
  15. data/lib/new_relic/agent/beacon_configuration.rb +121 -0
  16. data/lib/new_relic/agent/browser_monitoring.rb +142 -0
  17. data/lib/new_relic/agent/busy_calculator.rb +99 -0
  18. data/lib/new_relic/agent/chained_call.rb +13 -0
  19. data/lib/new_relic/agent/database.rb +223 -0
  20. data/lib/new_relic/agent/error_collector.rb +251 -0
  21. data/lib/new_relic/agent/instrumentation.rb +9 -0
  22. data/lib/new_relic/agent/instrumentation/active_merchant.rb +29 -0
  23. data/lib/new_relic/agent/instrumentation/active_record.rb +137 -0
  24. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
  25. data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
  26. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +443 -0
  27. data/lib/new_relic/agent/instrumentation/data_mapper.rb +238 -0
  28. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
  29. data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
  30. data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
  31. data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
  32. data/lib/new_relic/agent/instrumentation/metric_frame.rb +353 -0
  33. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
  34. data/lib/new_relic/agent/instrumentation/net.rb +29 -0
  35. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +37 -0
  36. data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
  37. data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
  38. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
  39. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
  40. data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
  41. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +180 -0
  42. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +37 -0
  43. data/lib/new_relic/agent/instrumentation/sinatra.rb +78 -0
  44. data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
  45. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +21 -0
  46. data/lib/new_relic/agent/method_tracer.rb +528 -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 +143 -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/sql_sampler.rb +286 -0
  54. data/lib/new_relic/agent/stats_engine.rb +26 -0
  55. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
  56. data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
  57. data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
  58. data/lib/new_relic/agent/stats_engine/transactions.rb +125 -0
  59. data/lib/new_relic/agent/transaction_info.rb +74 -0
  60. data/lib/new_relic/agent/transaction_sample_builder.rb +116 -0
  61. data/lib/new_relic/agent/transaction_sampler.rb +468 -0
  62. data/lib/new_relic/agent/worker_loop.rb +89 -0
  63. data/lib/new_relic/collection_helper.rb +77 -0
  64. data/lib/new_relic/command.rb +85 -0
  65. data/lib/new_relic/commands/deployments.rb +105 -0
  66. data/lib/new_relic/commands/install.rb +80 -0
  67. data/lib/new_relic/control.rb +46 -0
  68. data/lib/new_relic/control/class_methods.rb +53 -0
  69. data/lib/new_relic/control/configuration.rb +206 -0
  70. data/lib/new_relic/control/frameworks.rb +10 -0
  71. data/lib/new_relic/control/frameworks/external.rb +16 -0
  72. data/lib/new_relic/control/frameworks/merb.rb +31 -0
  73. data/lib/new_relic/control/frameworks/rails.rb +164 -0
  74. data/lib/new_relic/control/frameworks/rails3.rb +75 -0
  75. data/lib/new_relic/control/frameworks/ruby.rb +42 -0
  76. data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
  77. data/lib/new_relic/control/instance_methods.rb +179 -0
  78. data/lib/new_relic/control/instrumentation.rb +100 -0
  79. data/lib/new_relic/control/logging_methods.rb +143 -0
  80. data/lib/new_relic/control/profiling.rb +25 -0
  81. data/lib/new_relic/control/server_methods.rb +114 -0
  82. data/lib/new_relic/data_serialization.rb +151 -0
  83. data/lib/new_relic/delayed_job_injection.rb +51 -0
  84. data/lib/new_relic/language_support.rb +73 -0
  85. data/lib/new_relic/local_environment.rb +428 -0
  86. data/lib/new_relic/merbtasks.rb +6 -0
  87. data/lib/new_relic/metric_data.rb +51 -0
  88. data/lib/new_relic/metric_spec.rb +76 -0
  89. data/lib/new_relic/metrics.rb +9 -0
  90. data/lib/new_relic/noticed_error.rb +29 -0
  91. data/lib/new_relic/rack/browser_monitoring.rb +76 -0
  92. data/lib/new_relic/rack/developer_mode.rb +268 -0
  93. data/lib/new_relic/recipes.rb +77 -0
  94. data/lib/new_relic/stats.rb +335 -0
  95. data/lib/new_relic/timer_lib.rb +27 -0
  96. data/lib/new_relic/transaction_analysis.rb +77 -0
  97. data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
  98. data/lib/new_relic/transaction_sample.rb +261 -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 +203 -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 +312 -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/fixtures/proc_cpuinfo.txt +575 -0
  116. data/test/new_relic/agent/agent/connect_test.rb +403 -0
  117. data/test/new_relic/agent/agent/start_test.rb +255 -0
  118. data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
  119. data/test/new_relic/agent/agent_test.rb +140 -0
  120. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  121. data/test/new_relic/agent/agent_test_controller_test.rb +382 -0
  122. data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
  123. data/test/new_relic/agent/beacon_configuration_test.rb +111 -0
  124. data/test/new_relic/agent/browser_monitoring_test.rb +323 -0
  125. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  126. data/test/new_relic/agent/database_test.rb +149 -0
  127. data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
  128. data/test/new_relic/agent/error_collector_test.rb +192 -0
  129. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +576 -0
  130. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +34 -0
  131. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
  132. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +171 -0
  133. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
  134. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
  135. data/test/new_relic/agent/instrumentation/queue_time_test.rb +382 -0
  136. data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
  137. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
  138. data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
  139. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
  140. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
  141. data/test/new_relic/agent/method_tracer_test.rb +386 -0
  142. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  143. data/test/new_relic/agent/rpm_agent_test.rb +149 -0
  144. data/test/new_relic/agent/sampler_test.rb +19 -0
  145. data/test/new_relic/agent/shim_agent_test.rb +20 -0
  146. data/test/new_relic/agent/sql_sampler_test.rb +192 -0
  147. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
  148. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +82 -0
  149. data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
  150. data/test/new_relic/agent/stats_engine_test.rb +220 -0
  151. data/test/new_relic/agent/transaction_info_test.rb +13 -0
  152. data/test/new_relic/agent/transaction_sample_builder_test.rb +219 -0
  153. data/test/new_relic/agent/transaction_sampler_test.rb +967 -0
  154. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  155. data/test/new_relic/agent_test.rb +187 -0
  156. data/test/new_relic/collection_helper_test.rb +149 -0
  157. data/test/new_relic/command/deployments_test.rb +68 -0
  158. data/test/new_relic/control/class_methods_test.rb +62 -0
  159. data/test/new_relic/control/configuration_test.rb +84 -0
  160. data/test/new_relic/control/logging_methods_test.rb +185 -0
  161. data/test/new_relic/control_test.rb +256 -0
  162. data/test/new_relic/data_serialization_test.rb +208 -0
  163. data/test/new_relic/delayed_job_injection_test.rb +16 -0
  164. data/test/new_relic/local_environment_test.rb +85 -0
  165. data/test/new_relic/metric_data_test.rb +125 -0
  166. data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
  167. data/test/new_relic/metric_spec_test.rb +95 -0
  168. data/test/new_relic/rack/all_test.rb +11 -0
  169. data/test/new_relic/rack/browser_monitoring_test.rb +142 -0
  170. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  171. data/test/new_relic/rack/developer_mode_test.rb +74 -0
  172. data/test/new_relic/stats_test.rb +411 -0
  173. data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
  174. data/test/new_relic/transaction_analysis_test.rb +121 -0
  175. data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
  176. data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
  177. data/test/new_relic/transaction_sample/segment_test.rb +389 -0
  178. data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
  179. data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
  180. data/test/new_relic/transaction_sample_test.rb +177 -0
  181. data/test/new_relic/version_number_test.rb +89 -0
  182. data/test/script/build_test_gem.sh +51 -0
  183. data/test/script/ci.sh +94 -0
  184. data/test/script/ci_bench.sh +52 -0
  185. data/test/test_contexts.rb +29 -0
  186. data/test/test_helper.rb +155 -0
  187. data/ui/helpers/developer_mode_helper.rb +357 -0
  188. data/ui/helpers/google_pie_chart.rb +48 -0
  189. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  190. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  191. data/ui/views/newrelic/_sample.rhtml +20 -0
  192. data/ui/views/newrelic/_segment.rhtml +28 -0
  193. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  194. data/ui/views/newrelic/_segment_row.rhtml +12 -0
  195. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  196. data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
  197. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  198. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  199. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  200. data/ui/views/newrelic/_table.rhtml +12 -0
  201. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  202. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  203. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  204. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  205. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  206. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  207. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  208. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  209. data/ui/views/newrelic/file/images/textmate.png +0 -0
  210. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  211. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  212. data/ui/views/newrelic/file/stylesheets/style.css +490 -0
  213. data/ui/views/newrelic/index.rhtml +71 -0
  214. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  215. data/ui/views/newrelic/show_sample.rhtml +80 -0
  216. data/ui/views/newrelic/show_source.rhtml +3 -0
  217. data/ui/views/newrelic/threads.rhtml +53 -0
  218. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
  219. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +67 -0
  220. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
  221. data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
  222. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
  223. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
  224. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
  225. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
  226. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
  227. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
  228. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
  229. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
  230. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
  231. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
  232. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
  233. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
  234. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
  235. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
  236. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
  237. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
  238. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
  239. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
  240. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
  241. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
  242. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
  243. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
  244. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
  245. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
  246. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +135 -0
  247. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
  248. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
  249. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
  250. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
  251. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
  252. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
  253. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
  254. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
  255. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
  256. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
  257. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
  258. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
  259. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
  260. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
  261. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
  262. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
  263. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
  264. metadata +376 -0
@@ -0,0 +1,82 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
2
+
3
+
4
+ class NewRelic::Agent::MetricStatsTest < Test::Unit::TestCase
5
+ def setup
6
+ NewRelic::Agent.manual_start
7
+ @engine = NewRelic::Agent.instance.stats_engine
8
+ rescue => e
9
+ puts e
10
+ puts e.backtrace.join("\n")
11
+ end
12
+
13
+ def teardown
14
+ @engine.harvest_timeslice_data({},{})
15
+ super
16
+ end
17
+
18
+ def test_get_no_scope
19
+ s1 = @engine.get_stats "a"
20
+ s2 = @engine.get_stats "a"
21
+ s3 = @engine.get_stats "b"
22
+
23
+ assert_not_nil s1
24
+ assert_not_nil s2
25
+ assert_not_nil s3
26
+
27
+ assert s1 == s2
28
+ assert s1 != s3
29
+ end
30
+
31
+ def test_harvest
32
+ @engine.clear_stats
33
+ s1 = @engine.get_stats "a"
34
+ s2 = @engine.get_stats "c"
35
+
36
+ s1.trace_call 10
37
+ s2.trace_call 1
38
+ s2.trace_call 3
39
+
40
+ assert_equal 1, @engine.get_stats("a").call_count
41
+ assert_equal 10, @engine.get_stats("a").total_call_time
42
+
43
+ assert_equal 2, @engine.get_stats("c").call_count
44
+ assert_equal 4, @engine.get_stats("c").total_call_time
45
+
46
+ metric_data = @engine.harvest_timeslice_data({}, {}).values
47
+
48
+ # after harvest, all the metrics should be reset
49
+ assert_equal 0, @engine.get_stats("a").call_count
50
+ assert_equal 0, @engine.get_stats("a").total_call_time
51
+
52
+ assert_equal 0, @engine.get_stats("c").call_count
53
+ assert_equal 0, @engine.get_stats("c").total_call_time
54
+
55
+ metric_data = metric_data.reverse if metric_data[0].metric_spec.name != "a"
56
+
57
+ assert_equal 'a', metric_data[0].metric_spec.name
58
+
59
+ assert_equal 1, metric_data[0].stats.call_count
60
+ assert_equal 10, metric_data[0].stats.total_call_time
61
+ end
62
+
63
+ def test_harvest_with_merge
64
+ s = @engine.get_stats "a"
65
+ s.trace_call 1
66
+
67
+ assert_equal 1, @engine.get_stats("a").call_count
68
+
69
+ harvest = @engine.harvest_timeslice_data({}, {})
70
+ assert_equal 0, s.call_count
71
+ s.trace_call 2
72
+ assert_equal 1, s.call_count
73
+
74
+ # this calk should merge the contents of the previous harvest,
75
+ # so the stats for metric "a" should have 2 data points
76
+ harvest = @engine.harvest_timeslice_data(harvest, {})
77
+ stats = harvest.fetch(NewRelic::MetricSpec.new("a")).stats
78
+ assert_equal 2, stats.call_count
79
+ assert_equal 3, stats.total_call_time
80
+ end
81
+ end
82
+
@@ -0,0 +1,99 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', '..','..','test_helper'))
2
+ require 'new_relic/agent/samplers/cpu_sampler'
3
+
4
+ class NewRelic::Agent::StatsEngine::SamplersTest < Test::Unit::TestCase
5
+
6
+ class TestObject
7
+ include NewRelic::Agent::StatsEngine::Samplers
8
+ end
9
+
10
+ def setup
11
+ @stats_engine = NewRelic::Agent::StatsEngine.new
12
+ NewRelic::Agent.instance.stubs(:stats_engine).returns(@stats_engine)
13
+ end
14
+
15
+ def test_add_sampler_to_positive
16
+ object = TestObject.new
17
+ sampler = mock('sampler')
18
+ sampler_array = mock('sampler_array')
19
+ sampler_array.expects(:include?).with(sampler).returns(false)
20
+ sampler_array.expects(:<<).with(sampler)
21
+ sampler.expects(:stats_engine=).with(object)
22
+
23
+ object.send(:add_sampler_to, sampler_array, sampler)
24
+ end
25
+
26
+ def test_add_sampler_to_negative
27
+ object = TestObject.new
28
+ sampler = mock('sampler')
29
+ sampler_array = mock('sampler_array')
30
+ sampler_array.expects(:include?).with(sampler).returns(true)
31
+ assert_raise(RuntimeError) do
32
+ object.send(:add_sampler_to, sampler_array, sampler)
33
+ end
34
+ end
35
+
36
+ def test_cpu
37
+ s = NewRelic::Agent::Samplers::CpuSampler.new
38
+ # need to set this instance value to prevent it skipping a 'too
39
+ # fast' poll time
40
+ s.stats_engine = @stats_engine
41
+ s.instance_eval { @last_time = Time.now - 1.1 }
42
+ s.poll
43
+ s.instance_eval { @last_time = Time.now - 1.1 }
44
+ s.poll
45
+ assert_equal 2, s.systemtime_stats.call_count
46
+ assert_equal 2, s.usertime_stats.call_count
47
+ assert s.usertime_stats.total_call_time >= 0, "user cpu greater/equal to 0: #{s.usertime_stats.total_call_time}"
48
+ assert s.systemtime_stats.total_call_time >= 0, "system cpu greater/equal to 0: #{s.systemtime_stats.total_call_time}"
49
+ end
50
+ def test_memory__default
51
+ s = NewRelic::Agent::Samplers::MemorySampler.new
52
+ s.stats_engine = @stats_engine
53
+ s.poll
54
+ s.poll
55
+ s.poll
56
+ assert_equal 3, s.stats.call_count
57
+ assert s.stats.total_call_time > 0.5, "cpu greater than 0.5 ms: #{s.stats.total_call_time}"
58
+ end
59
+ def test_memory__linux
60
+ return if RUBY_PLATFORM =~ /darwin/
61
+ NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'linux'
62
+ s = NewRelic::Agent::Samplers::MemorySampler.new
63
+ s.stats_engine = @stats_engine
64
+ s.poll
65
+ s.poll
66
+ s.poll
67
+ assert_equal 3, s.stats.call_count
68
+ assert s.stats.total_call_time > 0.5, "cpu greater than 0.5 ms: #{s.stats.total_call_time}"
69
+ end
70
+ def test_memory__solaris
71
+ return if defined? JRuby
72
+ NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'solaris'
73
+ NewRelic::Agent::Samplers::MemorySampler::ShellPS.any_instance.stubs(:get_memory).returns 999
74
+ s = NewRelic::Agent::Samplers::MemorySampler.new
75
+ s.stats_engine = @stats_engine
76
+ s.poll
77
+ assert_equal 1, s.stats.call_count
78
+ assert_equal 999, s.stats.total_call_time
79
+ end
80
+ def test_memory__windows
81
+ return if defined? JRuby
82
+ NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'win32'
83
+ assert_raise NewRelic::Agent::Sampler::Unsupported do
84
+ NewRelic::Agent::Samplers::MemorySampler.new
85
+ end
86
+ end
87
+ def test_load_samplers
88
+ @stats_engine.expects(:add_harvest_sampler).at_least_once unless defined? JRuby
89
+ @stats_engine.expects(:add_sampler).never
90
+ NewRelic::Control.instance.load_samplers
91
+ sampler_count = 4
92
+ assert_equal sampler_count, NewRelic::Agent::Sampler.sampler_classes.size, NewRelic::Agent::Sampler.sampler_classes.inspect
93
+ end
94
+ def test_memory__is_supported
95
+ NewRelic::Agent::Samplers::MemorySampler.stubs(:platform).returns 'windows'
96
+ assert !NewRelic::Agent::Samplers::MemorySampler.supported_on_this_platform? || defined? JRuby
97
+ end
98
+
99
+ end
@@ -0,0 +1,220 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..', 'test_helper'))
2
+
3
+
4
+ class NewRelic::Agent::StatsEngineTest < Test::Unit::TestCase
5
+ def setup
6
+ NewRelic::Agent.manual_start
7
+ @engine = NewRelic::Agent::StatsEngine.new
8
+ rescue => e
9
+ puts e
10
+ puts e.backtrace.join("\n")
11
+ end
12
+
13
+ def teardown
14
+ @engine.harvest_timeslice_data({},{})
15
+ mocha_teardown
16
+ super
17
+ end
18
+
19
+ def test_scope
20
+ @engine.push_scope "scope1"
21
+ assert @engine.peek_scope.name == "scope1"
22
+
23
+ expected = @engine.push_scope "scope2"
24
+ @engine.pop_scope expected, 0
25
+
26
+ scoped = @engine.get_stats "a"
27
+ scoped.trace_call 3
28
+
29
+ assert scoped.total_call_time == 3
30
+ unscoped = @engine.get_stats "a"
31
+
32
+ assert scoped == @engine.get_stats("a")
33
+ assert unscoped.total_call_time == 3
34
+ end
35
+
36
+ def test_scope__overlap
37
+ NewRelic::Agent.instance.stubs(:stats_engine).returns(@engine)
38
+
39
+ @engine.scope_name = 'orlando'
40
+ self.class.trace_execution_scoped('disney', :deduct_call_time_from_parent => false) { sleep 0.1 }
41
+ orlando_disney = @engine.get_stats 'disney'
42
+
43
+ @engine.scope_name = 'anaheim'
44
+ self.class.trace_execution_scoped('disney', :deduct_call_time_from_parent => false) { sleep 0.1 }
45
+ anaheim_disney = @engine.get_stats 'disney'
46
+
47
+ disney = @engine.get_stats_no_scope "disney"
48
+
49
+ assert_not_same orlando_disney, anaheim_disney
50
+ assert_not_equal orlando_disney, anaheim_disney
51
+ assert_equal 1, orlando_disney.call_count
52
+ assert_equal 1, anaheim_disney.call_count
53
+ assert_same disney, orlando_disney.unscoped_stats
54
+ assert_same disney, anaheim_disney.unscoped_stats
55
+ assert_equal 2, disney.call_count
56
+ assert_equal disney.total_call_time, orlando_disney.total_call_time + anaheim_disney.total_call_time
57
+
58
+ end
59
+
60
+ def test_simplethrowcase(depth=0)
61
+
62
+ fail "doh" if depth == 10
63
+
64
+ scope = @engine.push_scope "scope#{depth}"
65
+
66
+ begin
67
+ test_simplethrowcase(depth+1)
68
+ rescue StandardError => e
69
+ if (depth != 0)
70
+ raise e
71
+ end
72
+ ensure
73
+ @engine.pop_scope scope, 0
74
+ end
75
+
76
+ if depth == 0
77
+ assert @engine.peek_scope.nil?
78
+ end
79
+ end
80
+
81
+
82
+ def test_scope_failure
83
+ scope1 = @engine.push_scope "scope1"
84
+ @engine.push_scope "scope2"
85
+
86
+ begin
87
+ @engine.pop_scope scope1
88
+ fail "Didn't throw when scope push/pop mismatched"
89
+ rescue
90
+ # success
91
+ end
92
+ end
93
+
94
+ def test_children_time
95
+ t1 = Time.now
96
+
97
+ expected1 = @engine.push_scope "a"
98
+ sleep 0.001
99
+ t2 = Time.now
100
+
101
+ expected2 = @engine.push_scope "b"
102
+ sleep 0.002
103
+ t3 = Time.now
104
+
105
+ expected = @engine.push_scope "c"
106
+ sleep 0.003
107
+ scope = @engine.pop_scope expected, Time.now - t3
108
+
109
+ t4 = Time.now
110
+
111
+ check_time_approximate 0, scope.children_time
112
+ check_time_approximate 0.003, @engine.peek_scope.children_time
113
+
114
+ sleep 0.001
115
+ t5 = Time.now
116
+
117
+ expected = @engine.push_scope "d"
118
+ sleep 0.002
119
+ scope = @engine.pop_scope expected, Time.now - t5
120
+
121
+ t6 = Time.now
122
+
123
+ check_time_approximate 0, scope.children_time
124
+
125
+ scope = @engine.pop_scope expected2, Time.now - t2
126
+ assert_equal scope.name, 'b'
127
+
128
+ check_time_approximate (t4 - t3) + (t6 - t5), scope.children_time
129
+
130
+ scope = @engine.pop_scope expected1, Time.now - t1
131
+ assert_equal scope.name, 'a'
132
+
133
+ check_time_approximate (t6 - t2), scope.children_time
134
+ end
135
+
136
+ def test_simple_start_transaction
137
+ assert @engine.peek_scope.nil?
138
+ scope = @engine.push_scope "scope"
139
+ @engine.start_transaction
140
+ assert !@engine.peek_scope.nil?
141
+ @engine.pop_scope scope, 0.01
142
+ assert @engine.peek_scope.nil?
143
+ @engine.end_transaction
144
+ assert @engine.peek_scope.nil?
145
+ end
146
+
147
+
148
+ # test for when the scope stack contains an element only used for tts and not metrics
149
+ def test_simple_tt_only_scope
150
+ scope1 = @engine.push_scope "a", 0, true
151
+ scope2 = @engine.push_scope "b", 10, false
152
+ scope3 = @engine.push_scope "c", 20, true
153
+
154
+ @engine.pop_scope scope3, 10
155
+ @engine.pop_scope scope2, 10
156
+ @engine.pop_scope scope1, 10
157
+
158
+ assert_equal 0, scope3.children_time
159
+ assert_equal 10, scope2.children_time
160
+ assert_equal 10, scope1.children_time
161
+ end
162
+
163
+ def test_double_tt_only_scope
164
+ scope1 = @engine.push_scope "a", 0, true
165
+ scope2 = @engine.push_scope "b", 10, false
166
+ scope3 = @engine.push_scope "c", 20, false
167
+ scope4 = @engine.push_scope "d", 30, true
168
+
169
+ @engine.pop_scope scope4, 10
170
+ @engine.pop_scope scope3, 10
171
+ @engine.pop_scope scope2, 10
172
+ @engine.pop_scope scope1, 10
173
+
174
+ assert_equal 0, scope4.children_time.round
175
+ assert_equal 10, scope3.children_time.round
176
+ assert_equal 10, scope2.children_time.round
177
+ assert_equal 10, scope1.children_time.round
178
+ end
179
+
180
+
181
+ def test_collect_gc_data
182
+ GC.disable unless NewRelic::LanguageSupport.using_engine?('jruby')
183
+ if NewRelic::LanguageSupport.using_engine?('rbx')
184
+ agent = ::Rubinius::Agent.loopback
185
+ agent.stubs(:get).with('system.gc.young.total_wallclock') \
186
+ .returns([:value, 1000], [:value, 2500])
187
+ agent.stubs(:get).with('system.gc.full.total_wallclock') \
188
+ .returns([:value, 2000], [:value, 3500])
189
+ agent.stubs(:get).with('system.gc.young.count') \
190
+ .returns([:value, 1], [:value, 2])
191
+ agent.stubs(:get).with('system.gc.full.count') \
192
+ .returns([:value, 1], [:value, 2])
193
+ ::Rubinius::Agent.stubs(:loopback).returns(agent)
194
+ elsif NewRelic::LanguageSupport.using_version?('1.9')
195
+ ::GC::Profiler.stubs(:enabled?).returns(true)
196
+ ::GC::Profiler.stubs(:total_time).returns(1.0, 4.0)
197
+ ::GC.stubs(:count).returns(1, 3)
198
+ elsif NewRelic::LanguageSupport.using_version?('1.8')
199
+ ::GC.stubs(:time).returns(1000000, 4000000)
200
+ ::GC.stubs(:collections).returns(1, 3)
201
+ end
202
+
203
+ engine = NewRelic::Agent.instance.stats_engine
204
+ scope = engine.push_scope "scope"
205
+ engine.start_transaction
206
+ engine.pop_scope scope, 0.01
207
+ engine.end_transaction
208
+
209
+ gc_stats = engine.get_stats('GC/cumulative')
210
+ assert_equal 2, gc_stats.call_count
211
+ assert_equal 3.0, gc_stats.total_call_time
212
+ ensure
213
+ GC.enable unless NewRelic::LanguageSupport.using_engine?('jruby')
214
+ end
215
+
216
+ private
217
+ def check_time_approximate(expected, actual)
218
+ assert((expected - actual).abs < 0.1, "Expected between #{expected - 0.1} and #{expected + 0.1}, got #{actual}")
219
+ end
220
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+ require 'ostruct'
3
+
4
+ class NewRelic::Agent::TransactionInfoTest < Test::Unit::TestCase
5
+ def setup
6
+ @request = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=1234<tag>evil</tag>5678'})
7
+ end
8
+
9
+ def test_get_token_gets_sanitized_token_from_cookie
10
+ assert_equal('1234&lt;tag&gt;evil&lt;/tag&gt;5678',
11
+ NewRelic::Agent::TransactionInfo.get_token(@request))
12
+ end
13
+ end
@@ -0,0 +1,219 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+
3
+ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @builder = NewRelic::Agent::TransactionSampleBuilder.new
7
+ end
8
+
9
+ # if it doesn't the core app tests will break. Not strictly necessary but
10
+ # we'll enforce it with this test for now.
11
+ def test_trace_entry_returns_segment
12
+ segment = @builder.trace_entry("/Foo/Bar", Time.now)
13
+ assert segment, "Segment should not be nil"
14
+ assert segment.is_a?(NewRelic::TransactionSample::Segment), "Segment should not be a #{segment.class.name}"
15
+ end
16
+
17
+ def test_build_sample
18
+ build_segment("a") do
19
+ build_segment("aa") do
20
+ build_segment("aaa")
21
+ end
22
+ build_segment("ab") do
23
+ build_segment("aba") do
24
+ build_segment("abaa")
25
+ end
26
+ build_segment("aba")
27
+ build_segment("abc") do
28
+ build_segment("abca")
29
+ build_segment("abcd")
30
+ end
31
+ end
32
+ end
33
+ build_segment "b"
34
+ build_segment "c" do
35
+ build_segment "ca"
36
+ build_segment "cb" do
37
+ build_segment "cba"
38
+ end
39
+ end
40
+
41
+ @builder.finish_trace(Time.now.to_f)
42
+ validate_builder
43
+ end
44
+
45
+ def test_freeze
46
+ build_segment "a" do
47
+ build_segment "aa"
48
+ end
49
+
50
+ begin
51
+ builder.sample
52
+ assert false
53
+ rescue => e
54
+ # expected
55
+ end
56
+
57
+ @builder.finish_trace(Time.now.to_f)
58
+
59
+ validate_builder
60
+
61
+ begin
62
+ build_segment "b"
63
+ assert false
64
+ rescue TypeError => e
65
+ # expected
66
+ end
67
+ end
68
+
69
+ # this is really a test for transaction sample
70
+ def test_omit_segments_with
71
+ build_segment "Controller/my_controller/index" do
72
+ sleep 0.010
73
+
74
+ build_segment "Rails/Application Code Loading" do
75
+ sleep 0.020
76
+
77
+ build_segment "foo/bar" do
78
+ sleep 0.010
79
+ end
80
+ end
81
+
82
+ build_segment "a" do
83
+ build_segment "ab"
84
+ sleep 0.010
85
+ end
86
+ build_segment "b" do
87
+ build_segment "ba"
88
+ sleep 0.05
89
+ build_segment "bb"
90
+ build_segment "bc" do
91
+ build_segment "bca"
92
+ sleep 0.05
93
+ end
94
+ end
95
+ build_segment "c"
96
+ end
97
+ @builder.finish_trace(Time.now.to_f)
98
+
99
+ validate_builder false
100
+
101
+ sample = @builder.sample
102
+
103
+ should_be_a_copy = sample.omit_segments_with('OMIT NOTHING')
104
+ validate_segment should_be_a_copy.root_segment, false
105
+
106
+ assert_equal sample.params, should_be_a_copy.params
107
+ assert_equal(sample.root_segment.to_debug_str(0),
108
+ should_be_a_copy.root_segment.to_debug_str(0))
109
+
110
+ without_code_loading = sample.omit_segments_with('Rails/Application Code Loading')
111
+ validate_segment without_code_loading.root_segment, false
112
+
113
+ # after we take out code loading, the delta should be approximately
114
+ # 30 milliseconds
115
+ delta = (sample.duration - without_code_loading.duration) * 1000
116
+
117
+ # Need to allow substantial headroom on the upper bound to prevent
118
+ # spurious errors.
119
+ assert delta >= 28, "delta #{delta} should be between 28 and 100"
120
+ # disable this test for a couple days:
121
+ assert delta <= 100, "delta #{delta} should be between 28 and 100"
122
+
123
+ # ensure none of the segments have this regex
124
+ without_code_loading.each_segment do |segment|
125
+ assert_nil segment.metric_name =~ /Rails\/Application Code Loading/
126
+ end
127
+ end
128
+ def test_unbalanced_handling
129
+ assert_raise RuntimeError do
130
+ build_segment("a") do
131
+ begin
132
+ build_segment("aa") do
133
+ build_segment("aaa") do
134
+ raise "a problem"
135
+ end
136
+ end
137
+ rescue; end
138
+ end
139
+ end
140
+ end
141
+ def test_marshal
142
+ build_segment "a" do
143
+ build_segment "ab"
144
+ end
145
+ build_segment "b" do
146
+ build_segment "ba"
147
+ build_segment "bb"
148
+ build_segment "bc" do
149
+ build_segment "bca"
150
+ end
151
+ end
152
+ build_segment "c"
153
+
154
+ @builder.finish_trace(Time.now.to_f)
155
+ validate_builder
156
+
157
+ dump = Marshal.dump @builder.sample
158
+ sample = Marshal.restore(dump)
159
+ validate_segment(sample.root_segment)
160
+ end
161
+
162
+ def test_parallel_first_level_segments
163
+ build_segment "a" do
164
+ build_segment "ab"
165
+ end
166
+ build_segment "b"
167
+ build_segment "c"
168
+
169
+ @builder.finish_trace(Time.now.to_f)
170
+ validate_builder
171
+ end
172
+
173
+ def test_trace_should_not_record_more_than_segment_limit
174
+ @builder.segment_limit = 3
175
+ 8.times {|i| build_segment i.to_s }
176
+ assert_equal 3, @builder.sample.count_segments
177
+ end
178
+
179
+ # regression
180
+ def test_trace_should_log_segment_reached_once
181
+ @builder.segment_limit = 3
182
+ NewRelic::Control.instance.log.expects(:debug).once
183
+ 8.times {|i| build_segment i.to_s }
184
+ end
185
+
186
+
187
+ def validate_builder(check_names = true)
188
+ validate_segment @builder.sample.root_segment, check_names
189
+ end
190
+
191
+ def validate_segment(s, check_names = true)
192
+ p = s.parent_segment
193
+
194
+ unless p.nil? || p.metric_name == 'ROOT'
195
+ assert p.called_segments.include?(s)
196
+ assert_equal p.metric_name.length, s.metric_name.length - 1, "p: #{p.metric_name}, s: #{s.metric_name}" if check_names
197
+ assert p.metric_name < s.metric_name if check_names
198
+ assert p.entry_timestamp <= s.entry_timestamp
199
+ end
200
+
201
+ assert s.exit_timestamp >= s.entry_timestamp
202
+
203
+ children = s.called_segments
204
+ last_segment = s
205
+ children.each do |child|
206
+ assert child.metric_name > last_segment.metric_name if check_names
207
+ assert child.entry_timestamp >= last_segment.entry_timestamp
208
+ last_metric = child
209
+
210
+ validate_segment(child, check_names)
211
+ end
212
+ end
213
+
214
+ def build_segment(metric, time = 0, &proc)
215
+ @builder.trace_entry(metric, Time.now.to_f)
216
+ proc.call if proc
217
+ @builder.trace_exit(metric, Time.now.to_f)
218
+ end
219
+ end