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,411 @@
1
+ ENV['SKIP_RAILS'] = 'true'
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
3
+ ##require "new_relic/stats"
4
+
5
+ module NewRelic; class TestObjectForStats
6
+ include Stats
7
+ attr_accessor :total_call_time
8
+ attr_accessor :total_exclusive_time
9
+ attr_accessor :begin_time
10
+ attr_accessor :end_time
11
+ attr_accessor :call_count
12
+ end; end
13
+
14
+
15
+ class NewRelic::StatsTest < Test::Unit::TestCase
16
+
17
+ def test_checked_calculation_standard
18
+ obj = NewRelic::TestObjectForStats.new
19
+
20
+ assert_equal(1.0, obj.checked_calculation(1, 1))
21
+
22
+ end
23
+
24
+ def test_checked_calculation_with_zero
25
+ obj = NewRelic::TestObjectForStats.new
26
+ assert_equal(0.0, obj.checked_calculation(1, 0))
27
+ end
28
+
29
+ def test_checked_calculation_should_return_floats
30
+ obj = NewRelic::TestObjectForStats.new
31
+ assert_equal(0.5, obj.checked_calculation(1, 2))
32
+ end
33
+
34
+ def test_sum_attributes
35
+ first = NewRelic::TestObjectForStats.new
36
+ second = mock('other object')
37
+ first.expects(:call_count).returns(6)
38
+ second.expects(:call_count).returns(8)
39
+ first.expects(:update_totals).with(second)
40
+ first.expects(:stack_min_max_from).with(second)
41
+ first.expects(:update_boundaries).with(second)
42
+ first.expects(:call_count=).with(8)
43
+ first.sum_attributes(second)
44
+ end
45
+
46
+ def mock_plusequals(first, second, method, first_value, second_value)
47
+ first.expects(method).returns(first_value)
48
+ second.expects(method).returns(second_value)
49
+ first.expects("#{method}=".to_sym).with(first_value + second_value)
50
+ end
51
+
52
+ def test_stack_min_max_from
53
+ first = NewRelic::TestObjectForStats.new
54
+ second = mock('other object')
55
+ mock_plusequals(first, second, :min_call_time, 1.5, 0.5)
56
+ mock_plusequals(first, second, :max_call_time, 1.0, 3.0)
57
+
58
+ first.stack_min_max_from(second)
59
+ end
60
+
61
+ def test_update_boundaries
62
+ first = NewRelic::TestObjectForStats.new
63
+ second = mock('other object')
64
+
65
+ first.expects(:should_replace_begin_time?).with(second).returns(true)
66
+ first.expects(:should_replace_end_time?).with(second).returns(true)
67
+ first.expects(:begin_time=).with('other_begin_time')
68
+ first.expects(:end_time=).with('other_end_time')
69
+
70
+ second.expects(:begin_time).returns('other_begin_time')
71
+ second.expects(:end_time).returns('other_end_time')
72
+ first.update_boundaries(second)
73
+ end
74
+
75
+ def test_should_replace_end_time
76
+ first = NewRelic::TestObjectForStats.new
77
+ second = mock('other object')
78
+
79
+ first.expects(:end_time).returns(Time.at(1))
80
+ second.expects(:end_time).returns(Time.at(2))
81
+ assert first.should_replace_end_time?(second), 'should replace end time when the other stat is larger'
82
+ end
83
+
84
+ def test_should_replace_begin_time_base
85
+ first = NewRelic::TestObjectForStats.new
86
+ second = mock('other object')
87
+
88
+ first.expects(:begin_time).returns(Time.at(2))
89
+ second.expects(:begin_time).returns(Time.at(1))
90
+
91
+ assert first.should_replace_begin_time?(second), 'should replace the begin time when it is larger'
92
+ end
93
+
94
+ def test_should_replace_begin_time_empty
95
+ first = NewRelic::TestObjectForStats.new
96
+ second = mock('other object')
97
+
98
+ first.expects(:begin_time).returns(Time.at(0))
99
+ second.expects(:begin_time).returns(Time.at(2))
100
+
101
+ first.expects(:begin_time).returns(Time.at(0))
102
+
103
+ assert first.should_replace_begin_time?(second), "should replace the begin time if self.call_count == 0"
104
+ end
105
+
106
+ def test_update_totals
107
+ first = NewRelic::TestObjectForStats.new
108
+ second = mock('other object')
109
+
110
+ [:total_call_time, :total_exclusive_time, :sum_of_squares].each do |method|
111
+ mock_plusequals(first, second, method, 2.0, 3.0)
112
+ end
113
+
114
+ first.update_totals(second)
115
+ end
116
+
117
+ def test_min_time_less
118
+ first = NewRelic::TestObjectForStats.new
119
+ second = mock('other object')
120
+
121
+ second.expects(:min_call_time).returns(1.0)
122
+ first.expects(:min_call_time).returns(2.0)
123
+ second.expects(:call_count).returns(1)
124
+
125
+ first.min_time_less?(second)
126
+ end
127
+
128
+ def test_expand_min_max_to
129
+ first = NewRelic::TestObjectForStats.new
130
+ second = mock('other object')
131
+
132
+ first.expects(:min_time_less?).with(second).returns(true)
133
+ first.expects(:max_call_time).returns(3.0)
134
+
135
+ second.expects(:min_call_time).returns(1.0)
136
+ second.expects(:max_call_time).returns(4.0).twice
137
+
138
+ first.expects(:min_call_time=).with(1.0)
139
+ first.expects(:max_call_time=).with(4.0)
140
+
141
+ first.expand_min_max_to(second)
142
+ end
143
+
144
+
145
+
146
+ def test_simple
147
+ stats = NewRelic::MethodTraceStats.new
148
+ validate stats, 0, 0, 0, 0
149
+
150
+ assert_equal stats.call_count,0
151
+ stats.trace_call 10
152
+ stats.trace_call 20
153
+ stats.trace_call 30
154
+
155
+ validate stats, 3, (10+20+30), 10, 30
156
+ end
157
+
158
+ def test_to_s
159
+ s1 = NewRelic::MethodTraceStats.new
160
+ s1.trace_call 10
161
+ assert_equal("[01/01/70 12:00AM UTC, 0.000s; 1 calls 10s]", s1.to_s)
162
+ end
163
+
164
+ def test_time_str
165
+ s1 = NewRelic::MethodTraceStats.new
166
+ assert_equal(s1.time_str(10), "10 ms")
167
+ assert_equal(s1.time_str(4999), "4999 ms")
168
+ assert_equal(s1.time_str(5000), "5.00 s")
169
+ assert_equal(s1.time_str(5010), "5.01 s")
170
+ assert_equal(s1.time_str(9999), "10.00 s")
171
+ assert_equal(s1.time_str(10000), "10.0 s")
172
+ assert_equal(s1.time_str(20000), "20.0 s")
173
+ end
174
+
175
+ def test_multiply_by
176
+ s1 = NewRelic::MethodTraceStats.new
177
+ s1.trace_call 10
178
+ assert_equal("[01/01/70 12:00AM UTC, 0.000s; 10 calls 10s]", s1.multiply_by(10).to_s)
179
+ end
180
+
181
+ def test_get_apdex
182
+ s1 = NewRelic::MethodTraceStats.new
183
+ s1.trace_call 10
184
+ assert_equal(s1.get_apdex, [1, 10, 10])
185
+ end
186
+
187
+ def test_apdex_score
188
+ s1 = NewRelic::MethodTraceStats.new
189
+ s1.trace_call 10
190
+ assert_in_delta(s1.apdex_score, 0.285714285714286, 0.0000001)
191
+ end
192
+
193
+ def test_as_percentage
194
+ s1 = NewRelic::MethodTraceStats.new
195
+ s1.trace_call 10
196
+ assert_equal(s1.as_percentage, 1000.0)
197
+ end
198
+
199
+ def test_calls_per_minute
200
+
201
+ s1 = NewRelic::TestObjectForStats.new
202
+ s1.call_count = 1
203
+ s1.begin_time = Time.at(0)
204
+ s1.end_time = Time.at(30)
205
+ assert_equal(s1.calls_per_minute, 2)
206
+ end
207
+
208
+ def test_total_call_time_per_minute
209
+ s1 = NewRelic::TestObjectForStats.new
210
+ s1.begin_time = Time.at(0)
211
+ s1.end_time = Time.at(0)
212
+ assert_equal(0, s1.total_call_time_per_minute)
213
+ s1.begin_time = Time.at(0)
214
+ s1.end_time = Time.at(30)
215
+ s1.total_call_time = 10
216
+ assert_equal(20, s1.total_call_time_per_minute)
217
+ end
218
+
219
+ def test_time_percentage
220
+ s1 = NewRelic::TestObjectForStats.new
221
+ s1.begin_time = Time.at(0)
222
+ s1.end_time = Time.at(0)
223
+ assert_equal(0, s1.time_percentage)
224
+ s1.total_call_time = 10
225
+ s1.begin_time = Time.at(0)
226
+ s1.end_time = Time.at(30)
227
+ assert_equal((1.0 / 3.0), s1.time_percentage)
228
+ s1.total_call_time = 20
229
+ assert_equal((2.0 / 3.0), s1.time_percentage)
230
+ end
231
+
232
+ def test_exclusive_time_percentage
233
+ s1 = NewRelic::TestObjectForStats.new
234
+ s1.begin_time = Time.at(0)
235
+ s1.end_time = Time.at(0)
236
+ assert_equal(0, s1.exclusive_time_percentage)
237
+ s1.total_exclusive_time = 10
238
+ s1.begin_time = Time.at(0)
239
+ s1.end_time = Time.at(30)
240
+ assert_equal((1.0 / 3.0), s1.exclusive_time_percentage)
241
+ s1.total_exclusive_time = 20
242
+ assert_equal((2.0 / 3.0), s1.exclusive_time_percentage)
243
+ end
244
+
245
+ def test_sum_merge
246
+ s1 = NewRelic::MethodTraceStats.new
247
+ s2 = NewRelic::MethodTraceStats.new
248
+ s1.trace_call 10
249
+ s2.trace_call 20
250
+ s2.freeze
251
+
252
+ validate s1, 1, 10, 10, 10
253
+ validate s2, 1, 20, 20, 20
254
+ s1.sum_merge! s2
255
+ validate s1, 1, (10+20), 10 + 20, 20 + 10
256
+ validate s2, 1, 20, 20, 20
257
+ end
258
+
259
+ def test_sum_merge_with_exclusive
260
+ s1 = NewRelic::MethodTraceStats.new
261
+ s2 = NewRelic::MethodTraceStats.new
262
+
263
+ s1.trace_call 10, 5
264
+ s2.trace_call 20, 10
265
+ s2.freeze
266
+
267
+ validate s1, 1, 10, 10, 10, 5
268
+ validate s2, 1, 20, 20, 20, 10
269
+ s1.sum_merge! s2
270
+ validate s1, 1, (10+20), 10 + 20, 20 + 10, (10+5)
271
+ end
272
+
273
+ def test_merge
274
+ s1 = NewRelic::MethodTraceStats.new
275
+ s2 = NewRelic::MethodTraceStats.new
276
+
277
+ s1.trace_call 10
278
+ s2.trace_call 20
279
+ s2.freeze
280
+
281
+ validate s2, 1, 20, 20, 20
282
+ s3 = s1.merge s2
283
+ validate s3, 2, (10+20), 10, 20
284
+ validate s1, 1, 10, 10, 10
285
+ validate s2, 1, 20, 20, 20
286
+
287
+ s1.merge! s2
288
+ validate s1, 2, (10+20), 10, 20
289
+ validate s2, 1, 20, 20, 20
290
+ end
291
+
292
+ def test_merge_with_exclusive
293
+ s1 = NewRelic::MethodTraceStats.new
294
+
295
+ s2 = NewRelic::MethodTraceStats.new
296
+
297
+ s1.trace_call 10, 5
298
+ s2.trace_call 20, 10
299
+ s2.freeze
300
+
301
+ validate s2, 1, 20, 20, 20, 10
302
+ s3 = s1.merge s2
303
+ validate s3, 2, (10+20), 10, 20, (10+5)
304
+ validate s1, 1, 10, 10, 10, 5
305
+ validate s2, 1, 20, 20, 20, 10
306
+
307
+ s1.merge! s2
308
+ validate s1, 2, (10+20), 10, 20, (5+10)
309
+ validate s2, 1, 20, 20, 20, 10
310
+ end
311
+
312
+ def test_merge_array
313
+ s1 = NewRelic::MethodTraceStats.new
314
+ merges = []
315
+ merges << (NewRelic::MethodTraceStats.new.trace_call 1)
316
+ merges << (NewRelic::MethodTraceStats.new.trace_call 1)
317
+ merges << (NewRelic::MethodTraceStats.new.trace_call 1)
318
+
319
+ s1.merge! merges
320
+ validate s1, 3, 3, 1, 1
321
+ end
322
+
323
+ def test_freeze
324
+ s1 = NewRelic::MethodTraceStats.new
325
+
326
+ s1.trace_call 10
327
+ s1.freeze
328
+
329
+ begin
330
+ # the following should throw an exception because s1 is frozen
331
+ s1.trace_call 20
332
+ assert false
333
+ rescue StandardError
334
+ assert s1.frozen?
335
+ validate s1, 1, 10, 10, 10
336
+ end
337
+ end
338
+
339
+ def test_std_dev
340
+ s = NewRelic::MethodTraceStats.new
341
+ s.trace_call 1
342
+ assert s.standard_deviation == 0
343
+
344
+ s = NewRelic::MethodTraceStats.new
345
+ s.trace_call 10
346
+ s.trace_call 10
347
+ s.sum_of_squares = nil
348
+ assert s.standard_deviation == 0
349
+
350
+ s = NewRelic::MethodTraceStats.new
351
+ s.trace_call 0.001
352
+ s.trace_call 0.001
353
+ assert s.standard_deviation == 0
354
+
355
+
356
+ s = NewRelic::MethodTraceStats.new
357
+ s.trace_call 10
358
+ s.trace_call 10
359
+ s.trace_call 10
360
+ s.trace_call 10
361
+ s.trace_call 10
362
+ s.trace_call 10
363
+ assert s.standard_deviation == 0
364
+
365
+ s = NewRelic::MethodTraceStats.new
366
+ s.trace_call 4
367
+ s.trace_call 7
368
+ s.trace_call 13
369
+ s.trace_call 16
370
+ s.trace_call 8
371
+ s.trace_call 4
372
+ assert_equal(s.sum_of_squares, 4**2 + 7**2 + 13**2 + 16**2 + 8**2 + 4**2)
373
+
374
+ s.trace_call 9
375
+ s.trace_call 3
376
+ s.trace_call 1000
377
+ s.trace_call 4
378
+
379
+ # calculated stdev (population, not sample) from a spreadsheet.
380
+ assert_in_delta(s.standard_deviation, 297.76, 0.01)
381
+ end
382
+
383
+ def test_std_dev_merge
384
+ s1 = NewRelic::MethodTraceStats.new
385
+ s1.trace_call 4
386
+ s1.trace_call 7
387
+
388
+ s2 = NewRelic::MethodTraceStats.new
389
+ s2.trace_call 13
390
+ s2.trace_call 16
391
+
392
+ s3 = s1.merge(s2)
393
+
394
+ assert_equal(s1.sum_of_squares, 4*4 + 7*7)
395
+ assert_in_delta(s1.standard_deviation, 1.5, 0.01)
396
+
397
+ assert_in_delta(s2.standard_deviation, 1.5, 0.01)
398
+ assert_equal(s3.sum_of_squares, 4*4 + 7*7 + 13*13 + 16*16, "check sum of squares")
399
+ assert_in_delta(s3.standard_deviation, 4.743, 0.01)
400
+ end
401
+
402
+ private
403
+ def validate (stats, count, total, min, max, exclusive = nil)
404
+ assert_equal stats.call_count, count
405
+ assert_equal stats.total_call_time, total
406
+ assert_equal stats.average_call_time, (count > 0 ? total / count : 0)
407
+ assert_equal stats.min_call_time, min
408
+ assert_equal stats.max_call_time, max
409
+ assert_equal stats.total_exclusive_time, exclusive if exclusive
410
+ end
411
+ end
@@ -0,0 +1,91 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', '..','test_helper'))
2
+ require 'new_relic/transaction_analysis/segment_summary'
3
+ class NewRelic::TransactionAnalysis::SegmentSummaryTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @sample = mock('sample')
7
+ @ss = NewRelic::TransactionAnalysis::SegmentSummary.new('Controller/foo', @sample)
8
+ end
9
+
10
+ # these are mostly stub tests just making sure that the API doesn't
11
+ # change if anyone ever needs to modify it.
12
+
13
+ def test_insert
14
+ segment = mock('segment')
15
+ segment.expects(:metric_name).returns('Controller/foo')
16
+ segment.expects(:duration).returns(0.1)
17
+ segment.expects(:exclusive_duration).returns(0.1)
18
+ @ss << segment
19
+ assert_equal 0.1, @ss.total_time
20
+ assert_equal 0.1, @ss.exclusive_time
21
+ assert_equal 1, @ss.call_count
22
+ end
23
+
24
+ def test_insert_error
25
+ segment = mock('segment')
26
+ segment.expects(:metric_name).returns('Controller/bar').twice
27
+ assert_raise(ArgumentError) do
28
+ @ss << segment
29
+ end
30
+ end
31
+
32
+ def test_average_time
33
+ @ss.total_time = 0.1
34
+ @ss.call_count = 2
35
+ assert_equal 0.05, @ss.average_time
36
+ end
37
+
38
+ def test_average_exclusive_time
39
+ @ss.exclusive_time = 0.1
40
+ @ss.call_count = 2
41
+ assert_equal 0.05, @ss.average_exclusive_time
42
+ end
43
+
44
+ def test_exclusive_time_percentage_nil
45
+ @ss.exclusive_time = nil
46
+ assert_equal 0, @ss.exclusive_time_percentage
47
+ end
48
+
49
+ def test_exclusive_time_percentage
50
+ @ss.exclusive_time = 0.05
51
+ @sample.expects(:duration).returns(0.1).times(3)
52
+ assert_equal 0.5, @ss.exclusive_time_percentage
53
+ end
54
+
55
+ def test_total_time_percentage_nil
56
+ @ss.total_time = nil
57
+ assert_equal 0, @ss.total_time_percentage
58
+ end
59
+
60
+ def test_total_time_percentage
61
+ @ss.total_time = 0.05
62
+ @sample.expects(:duration).returns(0.1).times(3)
63
+ assert_equal 0.5, @ss.total_time_percentage
64
+ end
65
+
66
+ def test_nesting_total_time
67
+ segment = mock('segment')
68
+ segment.expects(:metric_name).twice.returns('Controller/foo')
69
+ segment.expects(:duration).returns(0.1)
70
+ segment.expects(:exclusive_duration).returns(0)
71
+ @ss << segment
72
+ segment.expects(:exclusive_duration).returns(0.1)
73
+ @ss.current_nest_count += 1
74
+ @ss << segment
75
+ assert_equal 0.1, @ss.total_time
76
+ assert_equal 0.1, @ss.exclusive_time
77
+ assert_equal 2, @ss.call_count
78
+ end
79
+
80
+ def test_ui_name_default
81
+ @ss.metric_name = 'Remainder'
82
+ assert_equal 'Remainder', @ss.ui_name
83
+ end
84
+
85
+ def test_ui_name_lookup
86
+ mocked_object = mock('metric parser obj')
87
+ mocked_object.expects(:developer_name).returns('Developer Name')
88
+ NewRelic::MetricParser::MetricParser.expects(:parse).with('Controller/foo').returns(mocked_object)
89
+ assert_equal 'Developer Name', @ss.ui_name
90
+ end
91
+ end