newrelic_rpm 3.6.7.159 → 3.6.8.164
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -0
- data/lib/new_relic/agent/agent.rb +38 -35
- data/lib/new_relic/agent/agent_logger.rb +6 -47
- data/lib/new_relic/agent/beacon_configuration.rb +10 -4
- data/lib/new_relic/agent/browser_monitoring.rb +39 -33
- data/lib/new_relic/agent/commands/agent_command.rb +4 -4
- data/lib/new_relic/agent/commands/agent_command_router.rb +72 -10
- data/lib/new_relic/agent/commands/thread_profiler_session.rb +110 -0
- data/lib/new_relic/agent/commands/xray_session.rb +55 -0
- data/lib/new_relic/agent/commands/xray_session_collection.rb +158 -0
- data/lib/new_relic/agent/configuration/default_source.rb +61 -24
- data/lib/new_relic/agent/configuration/mask_defaults.rb +2 -2
- data/lib/new_relic/agent/configuration/server_source.rb +1 -1
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +2 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +4 -10
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +10 -11
- data/lib/new_relic/agent/memory_logger.rb +52 -0
- data/lib/new_relic/agent/new_relic_service.rb +4 -0
- data/lib/new_relic/agent/request_sampler.rb +32 -13
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +6 -3
- data/lib/new_relic/agent/threading/agent_thread.rb +2 -1
- data/lib/new_relic/agent/threading/backtrace_node.rb +80 -27
- data/lib/new_relic/agent/threading/backtrace_service.rb +264 -0
- data/lib/new_relic/agent/threading/thread_profile.rb +79 -118
- data/lib/new_relic/agent/transaction/developer_mode_sample_buffer.rb +56 -0
- data/lib/new_relic/agent/transaction/force_persist_sample_buffer.rb +25 -0
- data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +25 -0
- data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +86 -0
- data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +64 -0
- data/lib/new_relic/agent/transaction.rb +25 -4
- data/lib/new_relic/agent/transaction_sample_builder.rb +6 -10
- data/lib/new_relic/agent/transaction_sampler.rb +47 -202
- data/lib/new_relic/agent/worker_loop.rb +47 -39
- data/lib/new_relic/agent.rb +1 -1
- data/lib/new_relic/build.rb +2 -2
- data/lib/new_relic/coerce.rb +8 -0
- data/lib/new_relic/control/instance_methods.rb +1 -0
- data/lib/new_relic/rack/browser_monitoring.rb +15 -1
- data/lib/new_relic/rack/developer_mode.rb +1 -1
- data/lib/new_relic/transaction_sample.rb +20 -5
- data/lib/new_relic/version.rb +1 -1
- data/newrelic.yml +4 -6
- data/newrelic_rpm.gemspec +1 -1
- data/test/agent_helper.rb +11 -0
- data/test/environments/lib/environments/runner.rb +5 -1
- data/test/environments/rails21/Gemfile +2 -2
- data/test/environments/rails22/Gemfile +2 -2
- data/test/environments/rails23/Gemfile +2 -2
- data/test/environments/rails31/Gemfile +2 -2
- data/test/environments/rails32/Gemfile +2 -2
- data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
- data/test/multiverse/suites/agent_only/testing_app.rb +6 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +5 -5
- data/test/multiverse/suites/agent_only/xray_sessions_test.rb +163 -0
- data/test/multiverse/suites/rails/request_statistics_test.rb +2 -2
- data/test/multiverse/suites/rails/view_instrumentation_test.rb +20 -21
- data/test/new_relic/agent/agent/connect_test.rb +0 -10
- data/test/new_relic/agent/agent_test.rb +27 -44
- data/test/new_relic/agent/browser_monitoring_test.rb +0 -52
- data/test/new_relic/agent/commands/agent_command_router_test.rb +150 -12
- data/test/new_relic/agent/commands/{thread_profiler_test.rb → thread_profiler_session_test.rb} +58 -19
- data/test/new_relic/agent/commands/xray_session_collection_test.rb +332 -0
- data/test/new_relic/agent/commands/xray_session_test.rb +42 -0
- data/test/new_relic/agent/configuration/manager_test.rb +2 -1
- data/test/new_relic/agent/configuration/server_source_test.rb +10 -10
- data/test/new_relic/agent/cpu_sampler_test.rb +50 -0
- data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +31 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +0 -1
- data/test/new_relic/agent/instrumentation/sequel_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +0 -1
- data/test/new_relic/agent/memory_logger_test.rb +53 -0
- data/test/new_relic/agent/new_relic_service_test.rb +1 -1
- data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -5
- data/test/new_relic/agent/request_sampler_test.rb +70 -20
- data/test/new_relic/agent/rules_engine_test.rb +6 -0
- data/test/new_relic/agent/threading/agent_thread_test.rb +2 -2
- data/test/new_relic/agent/threading/backtrace_node_test.rb +110 -17
- data/test/new_relic/agent/threading/backtrace_service_test.rb +567 -0
- data/test/new_relic/agent/threading/fake_thread.rb +4 -0
- data/test/new_relic/agent/threading/thread_profile_test.rb +141 -217
- data/test/new_relic/agent/threading/threaded_test_case.rb +3 -8
- data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +69 -0
- data/test/new_relic/agent/transaction/force_persist_sample_buffer_test.rb +52 -0
- data/test/new_relic/agent/transaction/slowest_sample_buffer_test.rb +67 -0
- data/test/new_relic/agent/transaction/xray_sample_buffer_test.rb +71 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +171 -307
- data/test/new_relic/agent/transaction_test.rb +33 -5
- data/test/new_relic/agent/worker_loop_test.rb +33 -11
- data/test/new_relic/coerce_test.rb +13 -0
- data/test/new_relic/fake_collector.rb +26 -3
- data/test/new_relic/multiverse_helpers.rb +2 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +12 -0
- data/test/new_relic/rack/developer_mode_test.rb +2 -2
- data/test/new_relic/transaction_sample_test.rb +19 -2
- data/test/performance/lib/performance/console_reporter.rb +1 -1
- data/test/performance/lib/performance/test_case.rb +7 -3
- data/test/performance/script/runner +3 -0
- data/test/performance/suites/thread_profiling.rb +83 -0
- data/test/test_helper.rb +2 -2
- data.tar.gz.sig +0 -0
- metadata +32 -32
- metadata.gz.sig +1 -1
- data/lib/new_relic/agent/commands/thread_profiler.rb +0 -80
@@ -168,6 +168,30 @@ class NewRelic::Agent::TransactionTest < Test::Unit::TestCase
|
|
168
168
|
)
|
169
169
|
end
|
170
170
|
|
171
|
+
def test_stop_sets_name
|
172
|
+
NewRelic::Agent::Transaction.start(:controller)
|
173
|
+
txn = NewRelic::Agent::Transaction.stop('new_name')
|
174
|
+
assert_equal 'new_name', txn.name
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_name_is_unset_if_nil
|
178
|
+
txn = NewRelic::Agent::Transaction.new
|
179
|
+
txn.name = nil
|
180
|
+
assert !txn.name_set?
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_name_is_unset_if_unknown
|
184
|
+
txn = NewRelic::Agent::Transaction.new
|
185
|
+
txn.name = NewRelic::Agent::UNKNOWN_METRIC
|
186
|
+
assert !txn.name_set?
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_name_set_if_anything_else
|
190
|
+
txn = NewRelic::Agent::Transaction.new
|
191
|
+
txn.name = "anything else"
|
192
|
+
assert txn.name_set?
|
193
|
+
end
|
194
|
+
|
171
195
|
def test_start_adds_controller_context_to_txn_stack
|
172
196
|
NewRelic::Agent::Transaction.start(:controller)
|
173
197
|
assert_equal 1, NewRelic::Agent::Transaction.stack.size
|
@@ -198,9 +222,12 @@ class NewRelic::Agent::TransactionTest < Test::Unit::TestCase
|
|
198
222
|
end
|
199
223
|
|
200
224
|
def test_end_fires_a_transaction_finished_event
|
201
|
-
name, timestamp, duration = nil
|
202
|
-
NewRelic::Agent.subscribe(:transaction_finished) do
|
203
|
-
name
|
225
|
+
name, timestamp, duration, type = nil
|
226
|
+
NewRelic::Agent.subscribe(:transaction_finished) do |payload|
|
227
|
+
name = payload[:name]
|
228
|
+
timestamp = payload[:start_timestamp]
|
229
|
+
duration = payload[:duration]
|
230
|
+
type = payload[:type]
|
204
231
|
end
|
205
232
|
|
206
233
|
start_time = freeze_time
|
@@ -213,12 +240,13 @@ class NewRelic::Agent::TransactionTest < Test::Unit::TestCase
|
|
213
240
|
assert_equal 'Controller/foo/1/bar/22', name
|
214
241
|
assert_equal start_time.to_f, timestamp
|
215
242
|
assert_equal 5.0, duration
|
243
|
+
assert_equal :controller, type
|
216
244
|
end
|
217
245
|
|
218
246
|
def test_end_fires_a_transaction_finished_event_with_overview_metrics
|
219
247
|
options = nil
|
220
|
-
NewRelic::Agent.subscribe(:transaction_finished) do |
|
221
|
-
options =
|
248
|
+
NewRelic::Agent.subscribe(:transaction_finished) do |payload|
|
249
|
+
options = payload[:overview_metrics]
|
222
250
|
end
|
223
251
|
|
224
252
|
NewRelic::Agent::Transaction.start(:controller)
|
@@ -7,7 +7,6 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
|
|
7
7
|
class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
|
8
8
|
def setup
|
9
9
|
@worker_loop = NewRelic::Agent::WorkerLoop.new
|
10
|
-
@test_start_time = Time.now
|
11
10
|
end
|
12
11
|
|
13
12
|
def test_add_task
|
@@ -20,18 +19,18 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def test_with_duration
|
23
|
-
|
22
|
+
freeze_time
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
Time.stubs(:now).returns(*ticks(0, 0.12, 0.005))
|
24
|
+
period = 5.0
|
25
|
+
worker_loop = NewRelic::Agent::WorkerLoop.new(:duration => 16.0)
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
count += 1
|
27
|
+
def worker_loop.sleep(duration)
|
28
|
+
advance_time(duration)
|
32
29
|
end
|
33
30
|
|
34
|
-
|
31
|
+
count = 0
|
32
|
+
worker_loop.run(period) { count += 1 }
|
33
|
+
assert_equal 3, count
|
35
34
|
end
|
36
35
|
|
37
36
|
def test_duration_clock_starts_with_run
|
@@ -62,13 +61,13 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
|
|
62
61
|
assert done
|
63
62
|
end
|
64
63
|
|
65
|
-
class
|
64
|
+
class Supernova < StandardError; end
|
66
65
|
|
67
66
|
def test_task_error__exception
|
68
67
|
expects_logging(:error, any_parameters)
|
69
68
|
@worker_loop.run(0) do
|
70
69
|
@worker_loop.stop
|
71
|
-
raise
|
70
|
+
raise Supernova, "oops"
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
@@ -81,6 +80,29 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
|
|
81
80
|
end
|
82
81
|
end
|
83
82
|
|
83
|
+
def test_worker_loop_propagates_errors_given_the_option
|
84
|
+
@worker_loop = NewRelic::Agent::WorkerLoop.new(
|
85
|
+
:limit => 2,
|
86
|
+
:propagate_errors => true
|
87
|
+
)
|
88
|
+
|
89
|
+
assert_raises Supernova do
|
90
|
+
@worker_loop.run(0) do
|
91
|
+
raise Supernova
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_dynamically_adjusts_the_period_once_the_loop_has_been_started
|
97
|
+
freeze_time
|
98
|
+
|
99
|
+
worker_loop = NewRelic::Agent::WorkerLoop.new(:limit => 2)
|
100
|
+
|
101
|
+
worker_loop.expects(:sleep).with(5.0)
|
102
|
+
worker_loop.expects(:sleep).with(7.0)
|
103
|
+
worker_loop.run(5.0) { advance_time(5.0); worker_loop.period = 7.0 }
|
104
|
+
end
|
105
|
+
|
84
106
|
def ticks(start, finish, step)
|
85
107
|
(start..finish).step(step).map{|i| Time.at(i)}
|
86
108
|
end
|
@@ -31,6 +31,19 @@ class CoerceTest < Test::Unit::TestCase
|
|
31
31
|
int("not valid", "HERE")
|
32
32
|
end
|
33
33
|
|
34
|
+
def test_int_coerce_or_nil
|
35
|
+
assert_equal 1, int_or_nil(1)
|
36
|
+
assert_equal 1, int_or_nil("1")
|
37
|
+
assert_equal 1, int_or_nil(1.0)
|
38
|
+
assert_equal 1, int_or_nil(Rational(1, 1))
|
39
|
+
assert_equal nil, int_or_nil("invalid")
|
40
|
+
assert_equal nil, int_or_nil(nil)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_int_or_nil_coerce_logs_with_context
|
44
|
+
expects_logging(:warn, all_of(includes("HERE"), includes("Integer")), anything)
|
45
|
+
int_or_nil("not valid", "HERE")
|
46
|
+
end
|
34
47
|
|
35
48
|
def test_float_coerce
|
36
49
|
assert_equal 1.0, float(1.0)
|
@@ -23,6 +23,7 @@ module NewRelic
|
|
23
23
|
'get_redirect_host' => [200, {'return_value' => 'localhost'}],
|
24
24
|
'connect' => [200, {'return_value' => {"agent_run_id" => agent_run_id}}],
|
25
25
|
'get_agent_commands' => [200, {'return_value' => []}],
|
26
|
+
'agent_command_results' => [200, {'return_value' => []}],
|
26
27
|
'metric_data' => [200, {'return_value' => [[{'name' => 'Some/Metric/Spec'}, 1]]}],
|
27
28
|
'sql_trace_data' => [200, {'return_value' => nil}],
|
28
29
|
'transaction_sample_data' => [200, {'return_value' => nil}],
|
@@ -173,10 +174,10 @@ module NewRelic
|
|
173
174
|
end
|
174
175
|
|
175
176
|
class ProfileDataPost < AgentPost
|
176
|
-
attr_accessor :
|
177
|
+
attr_accessor :sample_count, :traces
|
177
178
|
def initialize(opts={})
|
178
179
|
super
|
179
|
-
@
|
180
|
+
@sample_count = @body[1][0][3]
|
180
181
|
@body[1][0][4] = unblob(@body[1][0][4]) if @format == :json
|
181
182
|
@traces = @body[1][0][4]
|
182
183
|
end
|
@@ -190,13 +191,35 @@ module NewRelic
|
|
190
191
|
end
|
191
192
|
|
192
193
|
class TransactionSampleDataPost < AgentPost
|
194
|
+
class SubmittedTransactionTrace
|
195
|
+
def initialize(body)
|
196
|
+
@body = body
|
197
|
+
end
|
198
|
+
|
199
|
+
def metric_name
|
200
|
+
@body[2]
|
201
|
+
end
|
202
|
+
|
203
|
+
def uri
|
204
|
+
@body[3]
|
205
|
+
end
|
206
|
+
|
207
|
+
def xray_id
|
208
|
+
@body[8]
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
193
212
|
def initialize(opts={})
|
194
213
|
super
|
195
214
|
@body[4] = unblob(@body[4]) if @format == :json
|
196
215
|
end
|
197
216
|
|
217
|
+
def samples
|
218
|
+
@samples ||= @body[1].map { |s| SubmittedTransactionTrace.new(s) }
|
219
|
+
end
|
220
|
+
|
198
221
|
def metric_name
|
199
|
-
|
222
|
+
samples.first.metric_name
|
200
223
|
end
|
201
224
|
end
|
202
225
|
class AnalyticEventDataPost < AgentPost
|
@@ -72,6 +72,7 @@ EOL
|
|
72
72
|
mocha_teardown
|
73
73
|
TestApp.doc = nil
|
74
74
|
NewRelic::Agent.config.remove_config(@config)
|
75
|
+
NewRelic::Agent.agent.transaction_sampler.reset!
|
75
76
|
end
|
76
77
|
|
77
78
|
def test_make_sure_header_is_set
|
@@ -161,6 +162,17 @@ EOL
|
|
161
162
|
assert(last_response.body.include?(guid), last_response.body)
|
162
163
|
end
|
163
164
|
end
|
165
|
+
|
166
|
+
def test_calculate_content_length_accounts_for_multibyte_characters_for_186
|
167
|
+
String.stubs(:respond_to?).with(:bytesize).returns(false)
|
168
|
+
browser_monitoring = NewRelic::Rack::BrowserMonitoring.new(mock('app'))
|
169
|
+
assert_equal 24, browser_monitoring.calculate_content_length("猿も木から落ちる")
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_calculate_content_length_accounts_for_multibyte_characters_for_modern_ruby
|
173
|
+
browser_monitoring = NewRelic::Rack::BrowserMonitoring.new(mock('app'))
|
174
|
+
assert_equal 18, browser_monitoring.calculate_content_length("七転び八起き")
|
175
|
+
end
|
164
176
|
end
|
165
177
|
else
|
166
178
|
puts "Skipping tests in #{__FILE__} because Rails is unavailable (or too old)"
|
@@ -44,7 +44,7 @@ class DeveloperModeTest < Test::Unit::TestCase
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_show_sample_summary_displays_sample_details
|
47
|
-
get "/newrelic/show_sample_summary?id=#{@sampler.samples[0].sample_id}"
|
47
|
+
get "/newrelic/show_sample_summary?id=#{@sampler.dev_mode_sample_buffer.samples[0].sample_id}"
|
48
48
|
|
49
49
|
assert last_response.ok?
|
50
50
|
assert last_response.body.include?('/here')
|
@@ -53,7 +53,7 @@ class DeveloperModeTest < Test::Unit::TestCase
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_explain_sql_displays_query_plan
|
56
|
-
sample = @sampler.samples[0]
|
56
|
+
sample = @sampler.dev_mode_sample_buffer.samples[0]
|
57
57
|
sql_segment = sample.sql_segments[0]
|
58
58
|
explain_results = NewRelic::Agent::Database.process_resultset(example_explain_as_hashes)
|
59
59
|
|
@@ -178,6 +178,13 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
|
|
178
178
|
assert(s.timestamp.instance_of?(Float), "s.timestamp should be a Float, but is #{s.timestamp.class.inspect}")
|
179
179
|
end
|
180
180
|
|
181
|
+
def test_xray_session_id
|
182
|
+
@t.xray_session_id = 123
|
183
|
+
s = @t.prepare_to_send
|
184
|
+
assert_equal(123, s.xray_session_id)
|
185
|
+
end
|
186
|
+
|
187
|
+
|
181
188
|
def test_count_segments
|
182
189
|
transaction = run_sample_trace_on(NewRelic::Agent::TransactionSampler.new) do |sampler|
|
183
190
|
sampler.notice_push_scope "level0"
|
@@ -221,21 +228,31 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
|
|
221
228
|
(@t.duration * 1000).round,
|
222
229
|
@t.params[:path], @t.params[:uri],
|
223
230
|
trace_tree,
|
224
|
-
@t.guid, nil, !!@t.force_persist]
|
231
|
+
@t.guid, nil, !!@t.force_persist, @t.xray_session_id]
|
225
232
|
|
226
233
|
assert_equal expected_array, @t.to_collector_array(@marshaller.default_encoder)
|
227
234
|
end
|
228
235
|
|
236
|
+
FORCE_PERSIST_POSITION = 7
|
237
|
+
|
238
|
+
def test_to_collector_array_forces_xrays
|
239
|
+
@t.force_persist = false
|
240
|
+
@t.xray_session_id = 123
|
241
|
+
result = @t.to_collector_array(@marshaller.default_encoder)
|
242
|
+
assert_equal true, result[FORCE_PERSIST_POSITION]
|
243
|
+
end
|
244
|
+
|
229
245
|
def test_to_collector_array_with_bad_values
|
230
246
|
transaction = NewRelic::TransactionSample.new(nil)
|
231
247
|
transaction.root_segment.end_trace(Rational(10, 1))
|
248
|
+
transaction.xray_session_id = "booooooo"
|
232
249
|
|
233
250
|
expected = [
|
234
251
|
0, 10_000,
|
235
252
|
nil, nil,
|
236
253
|
trace_tree(transaction),
|
237
254
|
transaction.guid,
|
238
|
-
nil, false]
|
255
|
+
nil, false, nil]
|
239
256
|
|
240
257
|
assert_equal expected, transaction.to_collector_array(@marshaller.default_encoder)
|
241
258
|
end
|
@@ -51,12 +51,16 @@ module Performance
|
|
51
51
|
result = Result.new(self.class, name)
|
52
52
|
begin
|
53
53
|
with_callbacks(name) do
|
54
|
-
|
55
|
-
|
54
|
+
if self.method(name).arity == 0
|
55
|
+
result.timer.measure do
|
56
|
+
self.send(name)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
self.send(name, result.timer)
|
56
60
|
end
|
57
61
|
result
|
58
62
|
end
|
59
|
-
rescue => e
|
63
|
+
rescue StandardError, LoadError => e
|
60
64
|
result.exception = e
|
61
65
|
end
|
62
66
|
result
|
@@ -22,6 +22,9 @@ parser = OptionParser.new do |opts|
|
|
22
22
|
opts.on("-i", "--instrumentor=NAME", "Use the named instrumentor") do |name|
|
23
23
|
options[:instrumentors] = [name]
|
24
24
|
end
|
25
|
+
opts.on("-s", "--suite=NAME", "Filter to just run a single test suite") do |name|
|
26
|
+
options[:suite] = name
|
27
|
+
end
|
25
28
|
opts.on("-n", "--name=NAME", "Filter tests to those matching NAME") do |name|
|
26
29
|
options[:name] = name
|
27
30
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
class ThreadProfiling < Performance::TestCase
|
6
|
+
def recurse(n, final)
|
7
|
+
if n == 0
|
8
|
+
final.call
|
9
|
+
else
|
10
|
+
recurse(n-1, final)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def block
|
15
|
+
@mutex.synchronize do
|
16
|
+
@cvar.wait(@mutex)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
require 'new_relic/agent/threading/backtrace_service'
|
22
|
+
|
23
|
+
@nthreads = 16
|
24
|
+
|
25
|
+
@mutex = Mutex.new
|
26
|
+
@cvar = ConditionVariable.new
|
27
|
+
@threadq = Queue.new
|
28
|
+
@threads = []
|
29
|
+
|
30
|
+
@nthreads.times do
|
31
|
+
@threads << Thread.new do
|
32
|
+
@threadq << self
|
33
|
+
transaction_state = NewRelic::Agent::TransactionState.get
|
34
|
+
def transaction_state.in_request_transaction?; true; end
|
35
|
+
recurse(50, method(:block))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Ensure that all threads have had a chance to start up
|
40
|
+
started_count = 0
|
41
|
+
while started_count < @nthreads do
|
42
|
+
@threadq.pop
|
43
|
+
started_count += 1
|
44
|
+
end
|
45
|
+
|
46
|
+
@service = NewRelic::Agent::Threading::BacktraceService.new
|
47
|
+
@worker_loop = @service.worker_loop
|
48
|
+
def @worker_loop.run; end # we want to drive it manually
|
49
|
+
end
|
50
|
+
|
51
|
+
def teardown
|
52
|
+
@cvar.broadcast
|
53
|
+
@threads.each(&:join)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_gather_backtraces(timer)
|
57
|
+
@service.subscribe(NewRelic::Agent::Threading::BacktraceService::ALL_TRANSACTIONS)
|
58
|
+
timer.measure do
|
59
|
+
(iterations / 10).times do
|
60
|
+
@service.poll
|
61
|
+
end
|
62
|
+
end
|
63
|
+
@service.unsubscribe(NewRelic::Agent::Threading::BacktraceService::ALL_TRANSACTIONS)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_gather_backtraces_subscribed(timer)
|
67
|
+
@service.subscribe('eagle')
|
68
|
+
timer.measure do
|
69
|
+
(iterations / 10).times do
|
70
|
+
t0 = Time.now.to_f
|
71
|
+
@service.poll
|
72
|
+
payload = {
|
73
|
+
:name => 'eagle',
|
74
|
+
:start_timestamp => t0,
|
75
|
+
:duration => Time.now.to_f-t0,
|
76
|
+
:thread => @threads.sample
|
77
|
+
}
|
78
|
+
@service.on_transaction_finished(payload)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
@service.unsubscribe('eagle')
|
82
|
+
end
|
83
|
+
end
|