newrelic_rpm 3.5.2.17 → 3.5.3.24
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/.travis.yml +3 -1
- data/CHANGELOG +39 -23
- data/GUIDELINES_FOR_CONTRIBUTING.md +23 -2
- data/Rakefile +32 -0
- data/lib/new_relic/agent.rb +1 -0
- data/lib/new_relic/agent/agent.rb +45 -6
- data/lib/new_relic/agent/browser_monitoring.rb +36 -20
- data/lib/new_relic/agent/busy_calculator.rb +12 -4
- data/lib/new_relic/agent/configuration/defaults.rb +6 -1
- data/lib/new_relic/agent/configuration/environment_source.rb +14 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +14 -10
- data/lib/new_relic/agent/new_relic_service.rb +192 -34
- data/lib/new_relic/agent/pipe_channel_manager.rb +1 -2
- data/lib/new_relic/agent/pipe_service.rb +5 -1
- data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
- data/lib/new_relic/agent/sql_sampler.rb +29 -10
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +40 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +1 -2
- data/lib/new_relic/agent/thread.rb +27 -0
- data/lib/new_relic/agent/thread_profiler.rb +295 -0
- data/lib/new_relic/agent/worker_loop.rb +29 -15
- data/lib/new_relic/control/frameworks/rails.rb +4 -4
- data/lib/new_relic/control/frameworks/rails3.rb +1 -1
- data/lib/new_relic/helper.rb +3 -0
- data/lib/new_relic/metric_data.rb +10 -2
- data/lib/new_relic/noticed_error.rb +5 -0
- data/lib/new_relic/transaction_sample.rb +23 -13
- data/lib/new_relic/transaction_sample/segment.rb +13 -15
- data/lib/new_relic/version.rb +1 -1
- data/lib/tasks/tests.rake +5 -11
- data/test/multiverse/.gitignore +10 -0
- data/test/multiverse/README.md +90 -0
- data/test/multiverse/Rakefile +17 -0
- data/test/multiverse/lib/multiverse/color.rb +13 -0
- data/test/multiverse/lib/multiverse/envfile.rb +66 -0
- data/test/multiverse/lib/multiverse/environment.rb +16 -0
- data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
- data/test/multiverse/lib/multiverse/runner.rb +44 -0
- data/test/multiverse/lib/multiverse/suite.rb +162 -0
- data/test/multiverse/script/run_one +3 -0
- data/test/multiverse/script/runner +9 -0
- data/test/multiverse/suites/active_record/Envfile +13 -0
- data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
- data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
- data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
- data/test/multiverse/suites/agent_only/Envfile +3 -0
- data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
- data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
- data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
- data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
- data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
- data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
- data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
- data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
- data/test/multiverse/suites/datamapper/Envfile +8 -0
- data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
- data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
- data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
- data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
- data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
- data/test/multiverse/suites/no_load/Envfile +2 -0
- data/test/multiverse/suites/no_load/config/newrelic.yml +23 -0
- data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
- data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
- data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
- data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
- data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
- data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
- data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
- data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
- data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
- data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
- data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
- data/test/multiverse/suites/rails_3_views/Envfile +16 -0
- data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
- data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
- data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
- data/test/multiverse/suites/resque/Envfile +21 -0
- data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
- data/test/multiverse/suites/resque/dump.rdb +0 -0
- data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
- data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
- data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
- data/test/multiverse/suites/rum_auto_instrumentation/problem_response.html +422 -0
- data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
- data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +115 -0
- data/test/multiverse/suites/sinatra/Envfile +13 -0
- data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +76 -0
- data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
- data/test/multiverse/test/multiverse_test.rb +55 -0
- data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
- data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
- data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
- data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
- data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
- data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
- data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
- data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
- data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
- data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
- data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
- data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
- data/test/new_relic/agent/agent_test.rb +54 -2
- data/test/new_relic/agent/agent_test_controller.rb +1 -1
- data/test/new_relic/agent/agent_test_controller_test.rb +35 -5
- data/test/new_relic/agent/browser_monitoring_test.rb +8 -8
- data/test/new_relic/agent/configuration/environment_source_test.rb +16 -0
- data/test/new_relic/agent/method_tracer_test.rb +6 -6
- data/test/new_relic/agent/new_relic_service_test.rb +137 -20
- data/test/new_relic/agent/sql_sampler_test.rb +26 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +1 -1
- data/test/new_relic/agent/stats_engine_test.rb +1 -0
- data/test/new_relic/agent/thread_profiler_test.rb +536 -0
- data/test/new_relic/agent/thread_test.rb +76 -0
- data/test/new_relic/agent/threaded_test.rb +65 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +16 -13
- data/test/new_relic/agent/worker_loop_test.rb +20 -0
- data/test/new_relic/fake_collector.rb +103 -31
- data/test/new_relic/fake_service.rb +7 -1
- data/test/new_relic/metric_data_test.rb +45 -16
- data/test/new_relic/noticed_error_test.rb +14 -0
- data/test/new_relic/transaction_sample/segment_test.rb +23 -4
- data/test/new_relic/transaction_sample_test.rb +39 -0
- data/ui/views/layouts/newrelic_default.rhtml +1 -0
- data/ui/views/newrelic/threads.rhtml +2 -10
- metadata +88 -2
@@ -188,4 +188,30 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
|
|
188
188
|
assert_equal('select * from test where foo in (?,?,?,?,?)', sql_traces[1].sql)
|
189
189
|
end
|
190
190
|
end
|
191
|
+
|
192
|
+
def test_to_collector_array
|
193
|
+
with_config(:'transaction_tracer.explain_enabled' => false) do
|
194
|
+
data = NewRelic::Agent::TransactionSqlData.new
|
195
|
+
data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
|
196
|
+
'guid')
|
197
|
+
data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test",
|
198
|
+
"Database/test/select",
|
199
|
+
{}, 1.5)])
|
200
|
+
@sampler.harvest_slow_sql(data)
|
201
|
+
sql_traces = @sampler.harvest
|
202
|
+
|
203
|
+
params = RUBY_VERSION >= '1.9.2' ? "eJyrrgUAAXUA+Q==\n" : {}
|
204
|
+
expected = [ 'WebTransaction/Controller/c/a', '/c/a', 526336943,
|
205
|
+
'select * from test', 'Database/test/select',
|
206
|
+
1, 1500, 1500, 1500, params ]
|
207
|
+
|
208
|
+
if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
|
209
|
+
marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
|
210
|
+
else
|
211
|
+
marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
|
212
|
+
end
|
213
|
+
|
214
|
+
assert_equal expected, sql_traces[0].to_collector_array(marshaller)
|
215
|
+
end
|
216
|
+
end
|
191
217
|
end
|
@@ -195,6 +195,7 @@ class NewRelic::Agent::StatsEngineTest < Test::Unit::TestCase
|
|
195
195
|
::GC::Profiler.stubs(:enabled?).returns(true)
|
196
196
|
::GC::Profiler.stubs(:total_time).returns(1.0, 4.0)
|
197
197
|
::GC.stubs(:count).returns(1, 3)
|
198
|
+
::GC::Profiler.stubs(:clear).returns(nil)
|
198
199
|
elsif NewRelic::LanguageSupport.using_version?('1.8.7') &&
|
199
200
|
RUBY_DESCRIPTION =~ /Ruby Enterprise Edition/
|
200
201
|
::GC.stubs(:time).returns(1000000, 4000000)
|
@@ -0,0 +1,536 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
require 'base64'
|
3
|
+
require 'thread'
|
4
|
+
require 'timeout'
|
5
|
+
require 'zlib'
|
6
|
+
require 'new_relic/agent/threaded_test'
|
7
|
+
require 'new_relic/agent/thread_profiler'
|
8
|
+
|
9
|
+
if RUBY_VERSION < '1.9.2'
|
10
|
+
class ThreadProfilerUnsupportedTest < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@profiler = NewRelic::Agent::ThreadProfiler.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_thread_profiling_isnt_supported
|
16
|
+
assert_equal false, NewRelic::Agent::ThreadProfiler.is_supported?
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_wont_start_when_not_supported
|
20
|
+
@profiler.start(0, 0, 0, true)
|
21
|
+
assert_equal false, @profiler.running?
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_stop_is_safe_when_not_supported
|
25
|
+
@profiler.start(0, 0, 0, true)
|
26
|
+
@profiler.stop(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if RUBY_VERSION >= '1.9.2'
|
33
|
+
require 'json'
|
34
|
+
|
35
|
+
class ThreadProfilerTest < ThreadedTest
|
36
|
+
|
37
|
+
START_COMMAND = [[666,{
|
38
|
+
"name" => "start_profiler",
|
39
|
+
"arguments" => {
|
40
|
+
"profile_id" => 42,
|
41
|
+
"sample_period" => 0.02,
|
42
|
+
"duration" => 0.025,
|
43
|
+
"only_runnable_threads" => false,
|
44
|
+
"only_request_threads" => false,
|
45
|
+
"profile_agent_code" => false,
|
46
|
+
}
|
47
|
+
}]]
|
48
|
+
|
49
|
+
STOP_COMMAND = [[666,{
|
50
|
+
"name" => "stop_profiler",
|
51
|
+
"arguments" => {
|
52
|
+
"profile_id" => 42,
|
53
|
+
"report_data" => true,
|
54
|
+
}
|
55
|
+
}]]
|
56
|
+
|
57
|
+
STOP_AND_DISCARD_COMMAND = [[666,{
|
58
|
+
"name" => "stop_profiler",
|
59
|
+
"arguments" => {
|
60
|
+
"profile_id" => 42,
|
61
|
+
"report_data" => false,
|
62
|
+
}
|
63
|
+
}]]
|
64
|
+
|
65
|
+
NO_COMMAND = []
|
66
|
+
|
67
|
+
def setup
|
68
|
+
super
|
69
|
+
@profiler = NewRelic::Agent::ThreadProfiler.new
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_is_supported
|
73
|
+
assert NewRelic::Agent::ThreadProfiler.is_supported?
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_is_not_running
|
77
|
+
assert !@profiler.running?
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_is_running
|
81
|
+
@profiler.start(0, 0, 0, true)
|
82
|
+
assert @profiler.running?
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_is_not_finished_if_no_profile_started
|
86
|
+
assert !@profiler.finished?
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_can_stop_a_running_profile
|
90
|
+
@profiler.start(0, 0, 0, true)
|
91
|
+
assert @profiler.running?
|
92
|
+
|
93
|
+
@profiler.stop(true)
|
94
|
+
|
95
|
+
assert @profiler.finished?
|
96
|
+
assert_not_nil @profiler.profile
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_can_stop_a_running_profile_and_discard
|
100
|
+
@profiler.start(0, 0, 0, true)
|
101
|
+
assert @profiler.running?
|
102
|
+
|
103
|
+
@profiler.stop(false)
|
104
|
+
|
105
|
+
assert_nil @profiler.profile
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_wont_crash_if_stopping_when_not_started
|
109
|
+
@profiler.stop(true)
|
110
|
+
assert_equal false, @profiler.running?
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_respond_to_commands_with_no_commands_doesnt_run
|
114
|
+
@profiler.respond_to_commands(NO_COMMAND)
|
115
|
+
assert_equal false, @profiler.running?
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_respond_to_commands_starts_running
|
119
|
+
@profiler.respond_to_commands(START_COMMAND)
|
120
|
+
assert_equal true, @profiler.running?
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_respond_to_commands_stops
|
124
|
+
@profiler.start(0, 0, 0, true)
|
125
|
+
assert @profiler.running?
|
126
|
+
|
127
|
+
@profiler.respond_to_commands(STOP_COMMAND)
|
128
|
+
assert_equal true, @profiler.profile.finished?
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_respond_to_commands_stops_and_discards
|
132
|
+
@profiler.start(0, 0, 0, true)
|
133
|
+
assert @profiler.running?
|
134
|
+
|
135
|
+
@profiler.respond_to_commands(STOP_AND_DISCARD_COMMAND)
|
136
|
+
assert_nil @profiler.profile
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_respond_to_commands_wont_start_second_profile
|
140
|
+
@profiler.start(0, 0, 0, true)
|
141
|
+
original_profile = @profiler.profile
|
142
|
+
|
143
|
+
@profiler.respond_to_commands(START_COMMAND)
|
144
|
+
|
145
|
+
assert_equal original_profile, @profiler.profile
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_response_to_commands_start_notifies_of_result
|
149
|
+
saw_command_id = nil
|
150
|
+
@profiler.respond_to_commands(START_COMMAND) { |id, err| saw_command_id = id }
|
151
|
+
assert_equal 666, saw_command_id
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_response_to_commands_start_notifies_of_error
|
155
|
+
saw_command_id = nil
|
156
|
+
error = nil
|
157
|
+
|
158
|
+
@profiler.respond_to_commands(START_COMMAND)
|
159
|
+
@profiler.respond_to_commands(START_COMMAND) { |id, err| saw_command_id = id; error = err }
|
160
|
+
|
161
|
+
assert_equal 666, saw_command_id
|
162
|
+
assert_not_nil error
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_response_to_commands_stop_notifies_of_result
|
166
|
+
saw_command_id = nil
|
167
|
+
@profiler.start(0,0, 0, true)
|
168
|
+
@profiler.respond_to_commands(STOP_COMMAND) { |id, err| saw_command_id = id }
|
169
|
+
assert_equal 666, saw_command_id
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_command_attributes_passed_along
|
173
|
+
@profiler.respond_to_commands(START_COMMAND)
|
174
|
+
assert_equal 42, @profiler.profile.profile_id
|
175
|
+
assert_equal 0.02, @profiler.profile.interval
|
176
|
+
assert_equal false, @profiler.profile.profile_agent_code
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_missing_name_in_command
|
180
|
+
command = [[666,{ "arguments" => {} } ]]
|
181
|
+
@profiler.respond_to_commands(command)
|
182
|
+
|
183
|
+
assert_equal false, @profiler.running?
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_malformed_agent_command
|
187
|
+
command = [[666]]
|
188
|
+
@profiler.respond_to_commands(command)
|
189
|
+
|
190
|
+
assert_equal false, @profiler.running?
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
class ThreadProfileTest < ThreadedTest
|
196
|
+
|
197
|
+
def setup
|
198
|
+
super
|
199
|
+
|
200
|
+
@single_trace = [
|
201
|
+
"irb.rb:69:in `catch'",
|
202
|
+
"irb.rb:69:in `start'",
|
203
|
+
"irb:12:in `<main>'"
|
204
|
+
]
|
205
|
+
|
206
|
+
@profile = NewRelic::Agent::ThreadProfile.new(-1, 0.029, 0.01, true)
|
207
|
+
end
|
208
|
+
|
209
|
+
# Running Tests
|
210
|
+
def test_profiler_collects_backtrace_from_every_thread
|
211
|
+
FakeThread.list << FakeThread.new
|
212
|
+
FakeThread.list << FakeThread.new
|
213
|
+
|
214
|
+
@profile.run
|
215
|
+
|
216
|
+
assert_equal 2, @profile.poll_count
|
217
|
+
assert_equal 4, @profile.sample_count
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_profiler_collects_into_request_bucket
|
221
|
+
FakeThread.list << FakeThread.new(
|
222
|
+
:bucket => :request,
|
223
|
+
:backtrace => @single_trace)
|
224
|
+
|
225
|
+
@profile.run
|
226
|
+
|
227
|
+
assert_equal 1, @profile.traces[:request].size
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_profiler_collects_into_background_bucket
|
231
|
+
FakeThread.list << FakeThread.new(
|
232
|
+
:bucket => :background,
|
233
|
+
:backtrace => @single_trace)
|
234
|
+
|
235
|
+
@profile.run
|
236
|
+
|
237
|
+
assert_equal 1, @profile.traces[:background].size
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_profiler_collects_into_other_bucket
|
241
|
+
FakeThread.list << FakeThread.new(
|
242
|
+
:bucket => :other,
|
243
|
+
:backtrace => @single_trace)
|
244
|
+
|
245
|
+
@profile.run
|
246
|
+
|
247
|
+
assert_equal 1, @profile.traces[:other].size
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_profiler_collects_into_agent_bucket
|
251
|
+
FakeThread.list << FakeThread.new(
|
252
|
+
:bucket => :agent,
|
253
|
+
:backtrace => @single_trace)
|
254
|
+
|
255
|
+
@profile.run
|
256
|
+
|
257
|
+
assert_equal 1, @profile.traces[:agent].size
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_profiler_ignores_agent_threads_when_told_to
|
261
|
+
FakeThread.list << FakeThread.new(
|
262
|
+
:bucket => :ignore,
|
263
|
+
:backtrace => @single_trace)
|
264
|
+
|
265
|
+
@profile.run
|
266
|
+
|
267
|
+
@profile.traces.each do |key, trace|
|
268
|
+
assert trace.empty?, "Trace :#{key} should have been empty"
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_profiler_tries_to_scrub_backtraces
|
273
|
+
FakeThread.list << FakeThread.new(
|
274
|
+
:bucket => :agent,
|
275
|
+
:backtrace => @single_trace,
|
276
|
+
:scrubbed_backtrace => @single_trace[0..0])
|
277
|
+
|
278
|
+
@profile.run
|
279
|
+
|
280
|
+
assert_equal [], @profile.traces[:agent].first.children
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_profile_can_be_stopped
|
284
|
+
# Can't easily stop in middle of processing since FakeThread's synchronous
|
285
|
+
# Mark to bail immediately, then see we didn't record anything
|
286
|
+
@profile.stop
|
287
|
+
|
288
|
+
@profile.run
|
289
|
+
|
290
|
+
assert_not_nil @profile.stop_time
|
291
|
+
assert_equal true, @profile.finished?
|
292
|
+
|
293
|
+
assert_equal 0, @profile.poll_count
|
294
|
+
@profile.traces.each do |key, trace|
|
295
|
+
assert_equal [], trace, "Trace for :#{key} should have been empty"
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_profiler_tracks_time
|
300
|
+
@profile.run
|
301
|
+
|
302
|
+
assert_not_nil @profile.start_time
|
303
|
+
assert_not_nil @profile.stop_time
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_finished
|
307
|
+
assert !@profile.finished?
|
308
|
+
|
309
|
+
@profile.run.join
|
310
|
+
|
311
|
+
assert @profile.finished?
|
312
|
+
end
|
313
|
+
|
314
|
+
# Parsing and Aggregation Tests
|
315
|
+
def test_parse_backtrace
|
316
|
+
trace = [
|
317
|
+
"/Users/jclark/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb.rb:69:in `catch'",
|
318
|
+
"/Users/jclark/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb.rb:69:in `start'",
|
319
|
+
"/Users/jclark/.rbenv/versions/1.9.3/bin/irb:12:in `<main>'"
|
320
|
+
]
|
321
|
+
|
322
|
+
result = NewRelic::Agent::ThreadProfile.parse_backtrace(trace)
|
323
|
+
assert_equal({ :method => 'catch',
|
324
|
+
:file => '/Users/jclark/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb.rb',
|
325
|
+
:line_no => 69 }, result[0])
|
326
|
+
assert_equal({ :method => 'start',
|
327
|
+
:file => '/Users/jclark/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb.rb',
|
328
|
+
:line_no => 69 }, result[1])
|
329
|
+
assert_equal({ :method => '<main>',
|
330
|
+
:file => '/Users/jclark/.rbenv/versions/1.9.3/bin/irb',
|
331
|
+
:line_no => 12 }, result[2])
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_aggregate_empty_trace
|
335
|
+
result = @profile.aggregate([])
|
336
|
+
assert_nil result
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_aggregate_nil_trace
|
340
|
+
result = @profile.aggregate(nil)
|
341
|
+
assert_nil result
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_aggregate_builds_tree_from_first_trace
|
345
|
+
result = @profile.aggregate(@single_trace)
|
346
|
+
|
347
|
+
tree = NewRelic::Agent::ThreadProfile::Node.new(@single_trace[-1])
|
348
|
+
child = NewRelic::Agent::ThreadProfile::Node.new(@single_trace[-2], tree)
|
349
|
+
NewRelic::Agent::ThreadProfile::Node.new(@single_trace[-3], child)
|
350
|
+
|
351
|
+
assert_equal tree, result
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_aggregate_builds_tree_from_overlapping_traces
|
355
|
+
result = @profile.aggregate(@single_trace)
|
356
|
+
result = @profile.aggregate(@single_trace, [result])
|
357
|
+
|
358
|
+
tree = NewRelic::Agent::ThreadProfile::Node.new(@single_trace[-1])
|
359
|
+
tree.runnable_count += 1
|
360
|
+
child = NewRelic::Agent::ThreadProfile::Node.new(@single_trace[-2], tree)
|
361
|
+
child.runnable_count += 1
|
362
|
+
grand = NewRelic::Agent::ThreadProfile::Node.new(@single_trace[-3], child)
|
363
|
+
grand.runnable_count += 1
|
364
|
+
|
365
|
+
assert_equal tree, result
|
366
|
+
end
|
367
|
+
|
368
|
+
def test_aggregate_builds_tree_from_diverging_traces
|
369
|
+
other_trace = [
|
370
|
+
"irb.rb:69:in `catch'",
|
371
|
+
"chunky_bacon.rb:42:in `start'",
|
372
|
+
"irb:12:in `<main>'"
|
373
|
+
]
|
374
|
+
|
375
|
+
result = @profile.aggregate(@single_trace)
|
376
|
+
result = @profile.aggregate(@single_trace, [result])
|
377
|
+
|
378
|
+
tree = NewRelic::Agent::ThreadProfile::Node.new(@single_trace[-1])
|
379
|
+
tree.runnable_count += 1
|
380
|
+
|
381
|
+
child = NewRelic::Agent::ThreadProfile::Node.new(@single_trace[-2], tree)
|
382
|
+
grand = NewRelic::Agent::ThreadProfile::Node.new(@single_trace[-3], child)
|
383
|
+
|
384
|
+
other_child = NewRelic::Agent::ThreadProfile::Node.new(other_trace[-2], tree)
|
385
|
+
other_grand = NewRelic::Agent::ThreadProfile::Node.new(other_trace[-3], other_child)
|
386
|
+
|
387
|
+
assert_equal tree, result
|
388
|
+
end
|
389
|
+
|
390
|
+
def test_prune_tree
|
391
|
+
@profile.aggregate(@single_trace)
|
392
|
+
|
393
|
+
t = @profile.prune!(1)
|
394
|
+
|
395
|
+
assert_equal 0, @profile.traces[:request].first.children.size
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_prune_keeps_highest_counts
|
399
|
+
@profile.aggregate(@single_trace, @profile.traces[:request])
|
400
|
+
@profile.aggregate(@single_trace, @profile.traces[:other])
|
401
|
+
@profile.aggregate(@single_trace, @profile.traces[:other])
|
402
|
+
|
403
|
+
@profile.prune!(1)
|
404
|
+
|
405
|
+
assert_equal [], @profile.traces[:request]
|
406
|
+
assert_equal 1, @profile.traces[:other].size
|
407
|
+
assert_equal [], @profile.traces[:other][0].children
|
408
|
+
end
|
409
|
+
|
410
|
+
def test_prune_keeps_highest_count_then_depths
|
411
|
+
@profile.aggregate(@single_trace, @profile.traces[:request])
|
412
|
+
@profile.aggregate(@single_trace, @profile.traces[:other])
|
413
|
+
|
414
|
+
@profile.prune!(2)
|
415
|
+
|
416
|
+
assert_equal 1, @profile.traces[:request].size
|
417
|
+
assert_equal 1, @profile.traces[:other].size
|
418
|
+
assert_equal [], @profile.traces[:request][0].children
|
419
|
+
assert_equal [], @profile.traces[:other][0].children
|
420
|
+
end
|
421
|
+
|
422
|
+
def test_to_compressed_array
|
423
|
+
@profile.instance_variable_set(:@start_time, 1350403938892.524)
|
424
|
+
@profile.instance_variable_set(:@stop_time, 1350403939904.375)
|
425
|
+
@profile.instance_variable_set(:@poll_count, 10)
|
426
|
+
@profile.instance_variable_set(:@sample_count, 2)
|
427
|
+
|
428
|
+
trace = ["thread_profiler.py:1:in `<module>'"]
|
429
|
+
10.times { @profile.aggregate(trace, @profile.traces[:other]) }
|
430
|
+
|
431
|
+
trace = [
|
432
|
+
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py:489:in `__bootstrap'",
|
433
|
+
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py:512:in `__bootstrap_inner'",
|
434
|
+
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py:480:in `run'",
|
435
|
+
"thread_profiler.py:76:in `_profiler_loop'",
|
436
|
+
"thread_profiler.py:103:in `_run_profiler'",
|
437
|
+
"thread_profiler.py:165:in `collect_thread_stacks'"]
|
438
|
+
10.times { @profile.aggregate(trace, @profile.traces[:agent]) }
|
439
|
+
|
440
|
+
expected = [[
|
441
|
+
-1,
|
442
|
+
1350403938892.524,
|
443
|
+
1350403939904.375,
|
444
|
+
10,
|
445
|
+
"eJy9klFPwjAUhf/LfW7WDQTUGBPUiYkGdAxelqXZRpGGrm1uS8xi/O924JQX\n9Un7dm77ndN7c19hlt7FCZxnWQZug7xYMYN6LSTHwDRA4KLWq53kl0CinEQh\nCUmW5zmBJH5axPPUk16MJ/E0/cGk0lLyyrGPS+uKamu943DQeX5HMtypz5In\nwv6vRCeZ1NoAGQ2PCDpvrOM1fRAlFtjQWyxq/qJxa+lj4zZaBeuuQpccrdDK\n0l4wolKU1OxftOoQLNTzIdL/EcjJafjnQYyVWjvrsDBMKNVOZBD1/jO27fPs\naBG+DoGr8fX9JJktpjftVry9A9unzGo=\n",
|
446
|
+
2,
|
447
|
+
0
|
448
|
+
]]
|
449
|
+
|
450
|
+
assert_equal expected, @profile.to_compressed_array
|
451
|
+
end
|
452
|
+
|
453
|
+
def test_compress
|
454
|
+
original = '{"OTHER": [[["thread_profiler.py", "<module>", 1], 10, 0, []]], "REQUEST": [], "AGENT": [[["/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", "__bootstrap", 489], 10, 0, [[["/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", "__bootstrap_inner", 512], 10, 0, [[["/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", "run", 480], 10, 0, [[["thread_profiler.py", "_profiler_loop", 76], 10, 0, [[["thread_profiler.py", "_run_profiler", 103], 10, 0, [[["thread_profiler.py", "collect_thread_stacks", 165], 10, 0, []]]]]]]]]]]]], "BACKGROUND": []}'
|
455
|
+
assert_equal(
|
456
|
+
"eJy9UtFOwjAU/ZWlz2QdKKCGmKBOTDSgY/iyLM02ijR0vcttiVmM/047J0LiA080bdJz2nPPbe/9IrP4KYzIjZckCTFr5NmSVQgrITn6VU06HhmVsNxKfmv33dSuoOPZmaSpBSQK3xbhPHYBHBxPwmncRqPzWhte0heRY4Y1fcSs5J+AG01fa7MG5a9+GfrOUQtQmvb8IZUip1Vzw6GfpIT6aNNhLAcw2mBWWXh5dX2Q01lcmVCKoyX73d5ZvHGrmpcGx27/V2uPmQRwPzQcnCSzJnvOVTq4OEVWgJS8MKw91SYrNtrJB/3jVvkbVnU3vn+eRLPF9KHpm+8dYyPRqg==",
|
457
|
+
NewRelic::Agent::ThreadProfile.compress(original).gsub(/\n/, ''))
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
class ThreadProfileNodeTest < Test::Unit::TestCase
|
462
|
+
SINGLE_LINE = "irb.rb:69:in `catch'"
|
463
|
+
|
464
|
+
def test_single_node_converts_to_array
|
465
|
+
line = "irb.rb:69:in `catch'"
|
466
|
+
node = NewRelic::Agent::ThreadProfile::Node.new(line)
|
467
|
+
|
468
|
+
assert_equal([
|
469
|
+
["irb.rb", "catch", 69],
|
470
|
+
0, 0,
|
471
|
+
[]],
|
472
|
+
node.to_array)
|
473
|
+
end
|
474
|
+
|
475
|
+
def test_multiple_nodes_converts_to_array
|
476
|
+
line = "irb.rb:69:in `catch'"
|
477
|
+
child_line = "bacon.rb:42:in `yum'"
|
478
|
+
node = NewRelic::Agent::ThreadProfile::Node.new(line)
|
479
|
+
child = NewRelic::Agent::ThreadProfile::Node.new(child_line, node)
|
480
|
+
|
481
|
+
assert_equal([
|
482
|
+
["irb.rb", "catch", 69],
|
483
|
+
0, 0,
|
484
|
+
[
|
485
|
+
[
|
486
|
+
['bacon.rb', 'yum', 42],
|
487
|
+
0,0,
|
488
|
+
[]
|
489
|
+
]
|
490
|
+
]],
|
491
|
+
node.to_array)
|
492
|
+
end
|
493
|
+
|
494
|
+
def test_add_child_twice
|
495
|
+
parent = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE)
|
496
|
+
child = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE)
|
497
|
+
|
498
|
+
parent.add_child(child)
|
499
|
+
parent.add_child(child)
|
500
|
+
|
501
|
+
assert_equal 1, parent.children.size
|
502
|
+
end
|
503
|
+
|
504
|
+
def test_prune_keeps_children
|
505
|
+
parent = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE)
|
506
|
+
child = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE, parent)
|
507
|
+
|
508
|
+
parent.prune!
|
509
|
+
|
510
|
+
assert_equal [child], parent.children
|
511
|
+
end
|
512
|
+
|
513
|
+
def test_prune_removes_children
|
514
|
+
parent = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE)
|
515
|
+
child = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE, parent)
|
516
|
+
|
517
|
+
child.to_prune = true
|
518
|
+
parent.prune!
|
519
|
+
|
520
|
+
assert_equal [], parent.children
|
521
|
+
end
|
522
|
+
|
523
|
+
def test_prune_removes_children
|
524
|
+
parent = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE)
|
525
|
+
child = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE, parent)
|
526
|
+
grandchild = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE, child)
|
527
|
+
|
528
|
+
grandchild.to_prune = true
|
529
|
+
parent.prune!
|
530
|
+
|
531
|
+
assert_equal [child], parent.children
|
532
|
+
assert_equal [], child.children
|
533
|
+
end
|
534
|
+
|
535
|
+
end
|
536
|
+
end
|