newrelic_rpm 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/LICENSE +37 -0
- data/README +93 -0
- data/Rakefile +38 -0
- data/install.rb +37 -0
- data/lib/new_relic/agent.rb +26 -0
- data/lib/new_relic/agent/agent.rb +762 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/collection_helper.rb +81 -0
- data/lib/new_relic/agent/error_collector.rb +105 -0
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +95 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +151 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
- data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +105 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +18 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +17 -0
- data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +15 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +6 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +35 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
- data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +30 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +23 -0
- data/lib/new_relic/agent/instrumentation/rails/rails.rb +6 -0
- data/lib/new_relic/agent/method_tracer.rb +171 -0
- data/lib/new_relic/agent/patch_const_missing.rb +31 -0
- data/lib/new_relic/agent/samplers/cpu.rb +29 -0
- data/lib/new_relic/agent/samplers/memory.rb +55 -0
- data/lib/new_relic/agent/samplers/mongrel.rb +26 -0
- data/lib/new_relic/agent/stats_engine.rb +241 -0
- data/lib/new_relic/agent/synchronize.rb +40 -0
- data/lib/new_relic/agent/transaction_sampler.rb +281 -0
- data/lib/new_relic/agent/worker_loop.rb +128 -0
- data/lib/new_relic/api/deployments.rb +92 -0
- data/lib/new_relic/config.rb +194 -0
- data/lib/new_relic/config/merb.rb +35 -0
- data/lib/new_relic/config/rails.rb +113 -0
- data/lib/new_relic/config/ruby.rb +9 -0
- data/lib/new_relic/local_environment.rb +108 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +26 -0
- data/lib/new_relic/metric_spec.rb +39 -0
- data/lib/new_relic/metrics.rb +7 -0
- data/lib/new_relic/noticed_error.rb +21 -0
- data/lib/new_relic/shim_agent.rb +95 -0
- data/lib/new_relic/stats.rb +359 -0
- data/lib/new_relic/transaction_analysis.rb +122 -0
- data/lib/new_relic/transaction_sample.rb +499 -0
- data/lib/new_relic/version.rb +111 -0
- data/lib/new_relic_api.rb +275 -0
- data/lib/newrelic_rpm.rb +27 -0
- data/lib/tasks/agent_tests.rake +14 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/newrelic.yml +137 -0
- data/recipes/newrelic.rb +46 -0
- data/test/config/newrelic.yml +26 -0
- data/test/config/test_config.rb +9 -0
- data/test/new_relic/agent/mock_ar_connection.rb +40 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/model_fixture.rb +17 -0
- data/test/new_relic/agent/tc_active_record.rb +91 -0
- data/test/new_relic/agent/tc_agent.rb +112 -0
- data/test/new_relic/agent/tc_collection_helper.rb +104 -0
- data/test/new_relic/agent/tc_controller.rb +98 -0
- data/test/new_relic/agent/tc_dispatcher_instrumentation.rb +52 -0
- data/test/new_relic/agent/tc_error_collector.rb +127 -0
- data/test/new_relic/agent/tc_method_tracer.rb +306 -0
- data/test/new_relic/agent/tc_stats_engine.rb +218 -0
- data/test/new_relic/agent/tc_synchronize.rb +37 -0
- data/test/new_relic/agent/tc_transaction_sample.rb +175 -0
- data/test/new_relic/agent/tc_transaction_sample_builder.rb +200 -0
- data/test/new_relic/agent/tc_transaction_sampler.rb +305 -0
- data/test/new_relic/agent/tc_worker_loop.rb +101 -0
- data/test/new_relic/agent/testable_agent.rb +13 -0
- data/test/new_relic/tc_config.rb +36 -0
- data/test/new_relic/tc_deployments_api.rb +37 -0
- data/test/new_relic/tc_environment.rb +94 -0
- data/test/new_relic/tc_metric_spec.rb +150 -0
- data/test/new_relic/tc_shim_agent.rb +9 -0
- data/test/new_relic/tc_stats.rb +141 -0
- data/test/test_helper.rb +39 -0
- data/test/ui/tc_newrelic_helper.rb +44 -0
- data/ui/controllers/newrelic_controller.rb +200 -0
- data/ui/helpers/google_pie_chart.rb +55 -0
- data/ui/helpers/newrelic_helper.rb +286 -0
- data/ui/views/layouts/newrelic_default.rhtml +49 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +12 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_row.rhtml +14 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +22 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +19 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +11 -0
- data/ui/views/newrelic/_stack_trace.rhtml +30 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +45 -0
- data/ui/views/newrelic/images/arrow-close.png +0 -0
- data/ui/views/newrelic/images/arrow-open.png +0 -0
- data/ui/views/newrelic/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/index.rhtml +37 -0
- data/ui/views/newrelic/javascript/transaction_sample.js +107 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +62 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/stylesheets/style.css +394 -0
- metadata +180 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
|
2
|
+
require 'new_relic_api'
|
3
|
+
class NewRelic::DeploymentsTests < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
NewRelic::API::Deployments.class_eval do
|
7
|
+
attr_accessor :messages, :exit_status, :errors, :revision
|
8
|
+
def err(message); @errors = @errors ? @errors + message : message; end
|
9
|
+
def info(message); @messages = @messages ? @messages + message : message; end
|
10
|
+
def just_exit(status=0); @exit_status ||= status; end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
def teardown
|
14
|
+
return unless @deployment
|
15
|
+
puts @deployment.errors
|
16
|
+
puts @deployment.messages
|
17
|
+
puts @deployment.exit_status
|
18
|
+
end
|
19
|
+
def test_help
|
20
|
+
@deployment = NewRelic::API::Deployments.new "-?"
|
21
|
+
assert_equal 0, @deployment.exit_status
|
22
|
+
assert_match /^Usage/, @deployment.messages
|
23
|
+
assert_nil @deployment.revision
|
24
|
+
@deployment = nil
|
25
|
+
end
|
26
|
+
def test_run
|
27
|
+
@deployment = NewRelic::API::Deployments.new(%w[-a APP -r 3838 --user=Bill] << "Some lengthy description")
|
28
|
+
assert_nil @deployment.exit_status
|
29
|
+
assert_nil @deployment.errors
|
30
|
+
assert_equal '3838', @deployment.revision
|
31
|
+
@deployment.run
|
32
|
+
assert_equal 1, @deployment.exit_status
|
33
|
+
assert_match /Unable to upload/, @deployment.errors
|
34
|
+
@deployment = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
|
2
|
+
require "test/unit"
|
3
|
+
require "mocha"
|
4
|
+
##require 'new_relic/local_environment'
|
5
|
+
class EnvironmentTest < ActiveSupport::TestCase
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
# To remove mock server instances from ObjectSpace
|
9
|
+
ObjectSpace.garbage_collect
|
10
|
+
super
|
11
|
+
end
|
12
|
+
class MockOptions
|
13
|
+
def fetch (*args)
|
14
|
+
1000
|
15
|
+
end
|
16
|
+
end
|
17
|
+
MOCK_OPTIONS = MockOptions.new
|
18
|
+
|
19
|
+
def test_environment
|
20
|
+
e = NewRelic::LocalEnvironment.new
|
21
|
+
assert_equal :unknown, e.environment
|
22
|
+
assert_nil e.identifier
|
23
|
+
end
|
24
|
+
def test_webrick
|
25
|
+
Object.const_set :OPTIONS, { :port => 3000 }
|
26
|
+
e = NewRelic::LocalEnvironment.new
|
27
|
+
assert_equal :webrick, e.environment
|
28
|
+
assert_equal 3000, e.identifier
|
29
|
+
Object.class_eval { remove_const :OPTIONS }
|
30
|
+
end
|
31
|
+
def test_no_webrick
|
32
|
+
Object.const_set :OPTIONS, 'foo'
|
33
|
+
e = NewRelic::LocalEnvironment.new
|
34
|
+
assert_equal :unknown, e.environment
|
35
|
+
assert_nil e.identifier
|
36
|
+
Object.class_eval { remove_const :OPTIONS }
|
37
|
+
end
|
38
|
+
def test_mongrel
|
39
|
+
|
40
|
+
class << self
|
41
|
+
module ::Mongrel
|
42
|
+
class HttpServer
|
43
|
+
def port; 3000; end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
Mongrel::HttpServer.new
|
48
|
+
e = NewRelic::LocalEnvironment.new
|
49
|
+
assert_equal :mongrel, e.environment
|
50
|
+
assert_equal 3000, e.identifier
|
51
|
+
Mongrel::HttpServer.class_eval {undef_method :port}
|
52
|
+
end
|
53
|
+
def test_thin
|
54
|
+
class << self
|
55
|
+
module ::Thin
|
56
|
+
class Server
|
57
|
+
def backend; self; end
|
58
|
+
def socket; "/socket/file.000"; end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
mock_thin = Thin::Server.new
|
63
|
+
e = NewRelic::LocalEnvironment.new
|
64
|
+
assert_equal :thin, e.environment
|
65
|
+
assert_equal '/socket/file.000', e.identifier
|
66
|
+
mock_thin
|
67
|
+
end
|
68
|
+
def test_litespeed
|
69
|
+
e = NewRelic::LocalEnvironment.new
|
70
|
+
assert_equal :unknown, e.environment
|
71
|
+
assert_nil e.identifier
|
72
|
+
end
|
73
|
+
def test_passenger
|
74
|
+
class << self
|
75
|
+
module ::Passenger
|
76
|
+
const_set "AbstractServer", 0
|
77
|
+
end
|
78
|
+
end
|
79
|
+
e = NewRelic::LocalEnvironment.new
|
80
|
+
assert_equal :passenger, e.environment
|
81
|
+
assert_equal 'passenger', e.identifier
|
82
|
+
|
83
|
+
NewRelic::Config.instance.instance_eval do
|
84
|
+
@settings['app_name'] = 'myapp'
|
85
|
+
end
|
86
|
+
|
87
|
+
e = NewRelic::LocalEnvironment.new
|
88
|
+
assert_equal :passenger, e.environment
|
89
|
+
assert_equal 'passenger:myapp', e.identifier
|
90
|
+
|
91
|
+
::Passenger.class_eval { remove_const :AbstractServer }
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
|
2
|
+
##require "new_relic/stats"
|
3
|
+
class NewRelic::StatsTests < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_simple
|
6
|
+
stats = NewRelic::MethodTraceStats.new
|
7
|
+
validate stats, 0, 0, 0, 0
|
8
|
+
|
9
|
+
assert_equal stats.call_count,0
|
10
|
+
stats.trace_call 10
|
11
|
+
stats.trace_call 20
|
12
|
+
stats.trace_call 30
|
13
|
+
|
14
|
+
validate stats, 3, (10+20+30), 10, 30
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_equal
|
18
|
+
spec1 = NewRelic::MetricSpec.new('Controller')
|
19
|
+
spec2 = NewRelic::MetricSpec.new('Controller', nil)
|
20
|
+
|
21
|
+
assert spec1.eql?(NewRelic::MetricSpec.new('Controller'))
|
22
|
+
assert spec2.eql?(NewRelic::MetricSpec.new('Controller', nil))
|
23
|
+
assert !spec1.eql?(spec2)
|
24
|
+
assert !spec2.eql?(NewRelic::MetricSpec.new('Controller', '/dude'))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_merge
|
28
|
+
s1 = NewRelic::MethodTraceStats.new
|
29
|
+
s2 = NewRelic::MethodTraceStats.new
|
30
|
+
|
31
|
+
s1.trace_call 10
|
32
|
+
s2.trace_call 20
|
33
|
+
s2.freeze
|
34
|
+
|
35
|
+
validate s2, 1, 20, 20, 20
|
36
|
+
s3 = s1.merge s2
|
37
|
+
validate s3, 2, (10+20), 10, 20
|
38
|
+
validate s1, 1, 10, 10, 10
|
39
|
+
validate s2, 1, 20, 20, 20
|
40
|
+
|
41
|
+
s1.merge! s2
|
42
|
+
validate s1, 2, (10+20), 10, 20
|
43
|
+
validate s2, 1, 20, 20, 20
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_merge_with_exclusive
|
47
|
+
s1 = NewRelic::MethodTraceStats.new
|
48
|
+
|
49
|
+
s2 = NewRelic::MethodTraceStats.new
|
50
|
+
|
51
|
+
s1.trace_call 10, 5
|
52
|
+
s2.trace_call 20, 10
|
53
|
+
s2.freeze
|
54
|
+
|
55
|
+
validate s2, 1, 20, 20, 20, 10
|
56
|
+
s3 = s1.merge s2
|
57
|
+
validate s3, 2, (10+20), 10, 20, (10+5)
|
58
|
+
validate s1, 1, 10, 10, 10, 5
|
59
|
+
validate s2, 1, 20, 20, 20, 10
|
60
|
+
|
61
|
+
s1.merge! s2
|
62
|
+
validate s1, 2, (10+20), 10, 20, (5+10)
|
63
|
+
validate s2, 1, 20, 20, 20, 10
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_merge_array
|
67
|
+
s1 = NewRelic::MethodTraceStats.new
|
68
|
+
merges = []
|
69
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
70
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
71
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
72
|
+
|
73
|
+
s1.merge! merges
|
74
|
+
validate s1, 3, 3, 1, 1
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_freeze
|
78
|
+
s1 = NewRelic::MethodTraceStats.new
|
79
|
+
|
80
|
+
s1.trace_call 10
|
81
|
+
s1.freeze
|
82
|
+
|
83
|
+
begin
|
84
|
+
# the following should throw an exception because s1 is frozen
|
85
|
+
s1.trace_call 20
|
86
|
+
assert false
|
87
|
+
rescue StandardError
|
88
|
+
assert s1.frozen?
|
89
|
+
validate s1, 1, 10, 10, 10
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_std_dev
|
94
|
+
s = NewRelic::MethodTraceStats.new
|
95
|
+
|
96
|
+
s.trace_call 10
|
97
|
+
s.trace_call 10
|
98
|
+
s.trace_call 10
|
99
|
+
s.trace_call 10
|
100
|
+
s.trace_call 10
|
101
|
+
s.trace_call 10
|
102
|
+
assert s.standard_deviation == 0
|
103
|
+
|
104
|
+
s = NewRelic::MethodTraceStats.new
|
105
|
+
s.trace_call 4
|
106
|
+
s.trace_call 7
|
107
|
+
s.trace_call 13
|
108
|
+
s.trace_call 16
|
109
|
+
s.trace_call 8
|
110
|
+
s.trace_call 4
|
111
|
+
assert_equal(s.sum_of_squares, 4**2 + 7**2 + 13**2 + 16**2 + 8**2 + 4**2)
|
112
|
+
|
113
|
+
s.trace_call 9
|
114
|
+
s.trace_call 3
|
115
|
+
s.trace_call 1000
|
116
|
+
s.trace_call 4
|
117
|
+
|
118
|
+
# calculated stdev (population, not sample) from a spreadsheet.
|
119
|
+
assert_in_delta(s.standard_deviation, 297.76, 0.01)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_std_dev_merge
|
123
|
+
s1 = NewRelic::MethodTraceStats.new
|
124
|
+
s1.trace_call 4
|
125
|
+
s1.trace_call 7
|
126
|
+
|
127
|
+
s2 = NewRelic::MethodTraceStats.new
|
128
|
+
s2.trace_call 13
|
129
|
+
s2.trace_call 16
|
130
|
+
|
131
|
+
s3 = s1.merge(s2)
|
132
|
+
|
133
|
+
assert(s1.sum_of_squares, 4*4 + 7*7)
|
134
|
+
assert_in_delta(s1.standard_deviation, 1.5, 0.01)
|
135
|
+
|
136
|
+
assert_in_delta(s2.standard_deviation, 1.5, 0.01)
|
137
|
+
assert_equal(s3.sum_of_squares, 4*4 + 7*7 + 13*13 + 16*16, "check sum of squares")
|
138
|
+
assert_in_delta(s3.standard_deviation, 4.743, 0.01)
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
def validate (stats, count, total, min, max, exclusive = nil)
|
143
|
+
assert_equal stats.call_count, count
|
144
|
+
assert_equal stats.total_call_time, total
|
145
|
+
assert_equal stats.average_call_time, (count > 0 ? total / count : 0)
|
146
|
+
assert_equal stats.min_call_time, min
|
147
|
+
assert_equal stats.max_call_time, max
|
148
|
+
assert_equal stats.total_exclusive_time, exclusive if exclusive
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
|
2
|
+
##require "new_relic/stats"
|
3
|
+
|
4
|
+
class NewRelic::StatsTests < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_simple
|
7
|
+
stats = NewRelic::MethodTraceStats.new
|
8
|
+
validate stats, 0, 0, 0, 0
|
9
|
+
|
10
|
+
assert_equal stats.call_count,0
|
11
|
+
stats.trace_call 10
|
12
|
+
stats.trace_call 20
|
13
|
+
stats.trace_call 30
|
14
|
+
|
15
|
+
validate stats, 3, (10+20+30), 10, 30
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_merge
|
19
|
+
s1 = NewRelic::MethodTraceStats.new
|
20
|
+
s2 = NewRelic::MethodTraceStats.new
|
21
|
+
|
22
|
+
s1.trace_call 10
|
23
|
+
s2.trace_call 20
|
24
|
+
s2.freeze
|
25
|
+
|
26
|
+
validate s2, 1, 20, 20, 20
|
27
|
+
s3 = s1.merge s2
|
28
|
+
validate s3, 2, (10+20), 10, 20
|
29
|
+
validate s1, 1, 10, 10, 10
|
30
|
+
validate s2, 1, 20, 20, 20
|
31
|
+
|
32
|
+
s1.merge! s2
|
33
|
+
validate s1, 2, (10+20), 10, 20
|
34
|
+
validate s2, 1, 20, 20, 20
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_merge_with_exclusive
|
38
|
+
s1 = NewRelic::MethodTraceStats.new
|
39
|
+
|
40
|
+
s2 = NewRelic::MethodTraceStats.new
|
41
|
+
|
42
|
+
s1.trace_call 10, 5
|
43
|
+
s2.trace_call 20, 10
|
44
|
+
s2.freeze
|
45
|
+
|
46
|
+
validate s2, 1, 20, 20, 20, 10
|
47
|
+
s3 = s1.merge s2
|
48
|
+
validate s3, 2, (10+20), 10, 20, (10+5)
|
49
|
+
validate s1, 1, 10, 10, 10, 5
|
50
|
+
validate s2, 1, 20, 20, 20, 10
|
51
|
+
|
52
|
+
s1.merge! s2
|
53
|
+
validate s1, 2, (10+20), 10, 20, (5+10)
|
54
|
+
validate s2, 1, 20, 20, 20, 10
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_merge_array
|
58
|
+
s1 = NewRelic::MethodTraceStats.new
|
59
|
+
merges = []
|
60
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
61
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
62
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
63
|
+
|
64
|
+
s1.merge! merges
|
65
|
+
validate s1, 3, 3, 1, 1
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_freeze
|
69
|
+
s1 = NewRelic::MethodTraceStats.new
|
70
|
+
|
71
|
+
s1.trace_call 10
|
72
|
+
s1.freeze
|
73
|
+
|
74
|
+
begin
|
75
|
+
# the following should throw an exception because s1 is frozen
|
76
|
+
s1.trace_call 20
|
77
|
+
assert false
|
78
|
+
rescue StandardError
|
79
|
+
assert s1.frozen?
|
80
|
+
validate s1, 1, 10, 10, 10
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_std_dev
|
85
|
+
s = NewRelic::MethodTraceStats.new
|
86
|
+
|
87
|
+
s.trace_call 10
|
88
|
+
s.trace_call 10
|
89
|
+
s.trace_call 10
|
90
|
+
s.trace_call 10
|
91
|
+
s.trace_call 10
|
92
|
+
s.trace_call 10
|
93
|
+
assert s.standard_deviation == 0
|
94
|
+
|
95
|
+
s = NewRelic::MethodTraceStats.new
|
96
|
+
s.trace_call 4
|
97
|
+
s.trace_call 7
|
98
|
+
s.trace_call 13
|
99
|
+
s.trace_call 16
|
100
|
+
s.trace_call 8
|
101
|
+
s.trace_call 4
|
102
|
+
assert_equal(s.sum_of_squares, 4**2 + 7**2 + 13**2 + 16**2 + 8**2 + 4**2)
|
103
|
+
|
104
|
+
s.trace_call 9
|
105
|
+
s.trace_call 3
|
106
|
+
s.trace_call 1000
|
107
|
+
s.trace_call 4
|
108
|
+
|
109
|
+
# calculated stdev (population, not sample) from a spreadsheet.
|
110
|
+
assert_in_delta(s.standard_deviation, 297.76, 0.01)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_std_dev_merge
|
114
|
+
s1 = NewRelic::MethodTraceStats.new
|
115
|
+
s1.trace_call 4
|
116
|
+
s1.trace_call 7
|
117
|
+
|
118
|
+
s2 = NewRelic::MethodTraceStats.new
|
119
|
+
s2.trace_call 13
|
120
|
+
s2.trace_call 16
|
121
|
+
|
122
|
+
s3 = s1.merge(s2)
|
123
|
+
|
124
|
+
assert(s1.sum_of_squares, 4*4 + 7*7)
|
125
|
+
assert_in_delta(s1.standard_deviation, 1.5, 0.01)
|
126
|
+
|
127
|
+
assert_in_delta(s2.standard_deviation, 1.5, 0.01)
|
128
|
+
assert_equal(s3.sum_of_squares, 4*4 + 7*7 + 13*13 + 16*16, "check sum of squares")
|
129
|
+
assert_in_delta(s3.standard_deviation, 4.743, 0.01)
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
def validate (stats, count, total, min, max, exclusive = nil)
|
134
|
+
assert_equal stats.call_count, count
|
135
|
+
assert_equal stats.total_call_time, total
|
136
|
+
assert_equal stats.average_call_time, (count > 0 ? total / count : 0)
|
137
|
+
assert_equal stats.min_call_time, min
|
138
|
+
assert_equal stats.max_call_time, max
|
139
|
+
assert_equal stats.total_exclusive_time, exclusive if exclusive
|
140
|
+
end
|
141
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module NewRelic; TEST = true; end unless defined? NewRelic::TEST
|
2
|
+
NEWRELIC_PLUGIN_DIR = File.expand_path(File.dirname(__FILE__)+"/..")
|
3
|
+
$LOAD_PATH << File.join(NEWRELIC_PLUGIN_DIR,"test")
|
4
|
+
$LOAD_PATH.uniq!
|
5
|
+
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
|
7
|
+
|
8
|
+
require 'test_help'
|
9
|
+
require 'mocha'
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
|
13
|
+
module NewRelic
|
14
|
+
class Config
|
15
|
+
def setup_log_with_block_logging(*args)
|
16
|
+
silence_stream(::STDERR) { self.setup_log_without_block_logging(*args) }
|
17
|
+
end
|
18
|
+
alias_method_chain :setup_log, :block_logging rescue nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# This is a mixin for hacking the select method
|
23
|
+
if defined? ActiveRecord::ConnectionAdapters
|
24
|
+
class ActiveRecord::ConnectionAdapters::MysqlAdapter
|
25
|
+
|
26
|
+
def log_info_with_slowdown(sql, name, seconds)
|
27
|
+
log_info_without_slowdown(sql, name, seconds)
|
28
|
+
sleep 0.1
|
29
|
+
end
|
30
|
+
|
31
|
+
def setup_slow
|
32
|
+
self.class.alias_method_chain :log_info, :slowdown
|
33
|
+
end
|
34
|
+
|
35
|
+
def teardown_slow
|
36
|
+
alias :log_info :log_info_without_slowdown
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|