newrelic_rpm 3.6.6.147 → 3.6.7.152
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gitignore +0 -1
- data/CHANGELOG +55 -17
- data/Guardfile +7 -0
- data/Rakefile +6 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +5 -0
- data/bin/nrdebug +273 -0
- data/install.rb +3 -3
- data/lib/new_relic/agent.rb +4 -6
- data/lib/new_relic/agent/agent.rb +76 -72
- data/lib/new_relic/agent/autostart.rb +18 -5
- data/lib/new_relic/agent/browser_monitoring.rb +41 -35
- data/lib/new_relic/agent/browser_token.rb +38 -0
- data/lib/new_relic/agent/busy_calculator.rb +7 -5
- data/lib/new_relic/agent/commands/agent_command.rb +19 -0
- data/lib/new_relic/agent/commands/agent_command_router.rb +88 -0
- data/lib/new_relic/agent/commands/thread_profiler.rb +80 -0
- data/lib/new_relic/agent/configuration/default_source.rb +700 -0
- data/lib/new_relic/agent/configuration/environment_source.rb +83 -30
- data/lib/new_relic/agent/configuration/manager.rb +8 -8
- data/lib/new_relic/agent/configuration/mask_defaults.rb +2 -2
- data/lib/new_relic/agent/cross_app_monitor.rb +10 -21
- data/lib/new_relic/agent/cross_app_tracing.rb +3 -3
- data/lib/new_relic/agent/error_collector.rb +7 -10
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -1
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +5 -1
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +5 -1
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +5 -1
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -1
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +5 -12
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -0
- data/lib/new_relic/agent/instrumentation/{rails4/active_record.rb → active_record_4.rb} +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +11 -11
- data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -6
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +12 -6
- data/lib/new_relic/agent/instrumentation/curb.rb +11 -2
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -3
- data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +11 -2
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +13 -4
- data/lib/new_relic/agent/instrumentation/puma.rb +2 -1
- data/lib/new_relic/agent/instrumentation/rack.rb +15 -17
- data/lib/new_relic/agent/method_tracer.rb +181 -191
- data/lib/new_relic/agent/new_relic_service.rb +16 -14
- data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
- data/lib/new_relic/agent/request_sampler.rb +32 -165
- data/lib/new_relic/agent/sampled_buffer.rb +79 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -8
- data/lib/new_relic/agent/sql_sampler.rb +3 -3
- data/lib/new_relic/agent/stats_engine.rb +1 -1
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +2 -3
- data/lib/new_relic/agent/stats_engine/transactions.rb +2 -22
- data/lib/new_relic/agent/threading/agent_thread.rb +41 -0
- data/lib/new_relic/agent/threading/backtrace_node.rb +71 -0
- data/lib/new_relic/agent/threading/thread_profile.rb +172 -0
- data/lib/new_relic/agent/transaction.rb +16 -4
- data/lib/new_relic/agent/transaction_sample_builder.rb +13 -3
- data/lib/new_relic/agent/transaction_sampler.rb +5 -8
- data/lib/new_relic/agent/transaction_state.rb +166 -0
- data/lib/new_relic/agent/transaction_timings.rb +53 -0
- data/lib/new_relic/cli/command.rb +91 -0
- data/lib/new_relic/{commands → cli}/deployments.rb +13 -9
- data/lib/new_relic/{commands → cli}/install.rb +2 -2
- data/lib/new_relic/control/frameworks/rails.rb +1 -8
- data/lib/new_relic/control/instance_methods.rb +1 -2
- data/lib/new_relic/helper.rb +9 -0
- data/lib/new_relic/local_environment.rb +16 -63
- data/lib/new_relic/rack/browser_monitoring.rb +8 -5
- data/lib/new_relic/recipes.rb +44 -31
- data/lib/new_relic/transaction_sample.rb +6 -2
- data/lib/new_relic/version.rb +1 -1
- data/lib/tasks/install.rake +21 -1
- data/newrelic_rpm.gemspec +5 -1
- data/test/agent_helper.rb +4 -9
- data/test/environments/.gitignore +16 -0
- data/test/environments/lib/environments/runner.rb +104 -0
- data/test/environments/norails/Gemfile +11 -0
- data/test/environments/norails/Rakefile +9 -0
- data/test/environments/rails21/Gemfile +24 -0
- data/test/environments/rails21/Rakefile +12 -0
- data/test/environments/rails21/app/controllers/application.rb +20 -0
- data/test/environments/rails21/config/boot.rb +113 -0
- data/test/environments/rails21/config/database.yml +31 -0
- data/test/environments/rails21/config/environment.rb +28 -0
- data/test/environments/rails21/config/environments/development.rb +16 -0
- data/test/environments/rails21/config/environments/production.rb +8 -0
- data/test/environments/rails21/config/environments/test.rb +10 -0
- data/test/environments/rails21/config/routes.rb +5 -0
- data/test/environments/rails21/db/schema.rb +5 -0
- data/test/environments/rails22/Gemfile +29 -0
- data/test/environments/rails22/Rakefile +12 -0
- data/test/environments/rails22/app/controllers/application.rb +20 -0
- data/test/environments/rails22/config/boot.rb +113 -0
- data/test/environments/rails22/config/database.yml +31 -0
- data/test/environments/rails22/config/environment.rb +27 -0
- data/test/environments/rails22/config/environments/development.rb +16 -0
- data/test/environments/rails22/config/environments/production.rb +8 -0
- data/test/environments/rails22/config/environments/test.rb +10 -0
- data/test/environments/rails22/config/routes.rb +5 -0
- data/test/environments/rails22/db/schema.rb +5 -0
- data/test/environments/rails23/Gemfile +22 -0
- data/test/environments/rails23/Rakefile +12 -0
- data/test/environments/rails23/app/controllers/application.rb +20 -0
- data/test/environments/rails23/config/boot.rb +127 -0
- data/test/environments/rails23/config/database.yml +31 -0
- data/test/environments/rails23/config/environment.rb +25 -0
- data/test/environments/rails23/config/environments/development.rb +16 -0
- data/test/environments/rails23/config/environments/production.rb +8 -0
- data/test/environments/rails23/config/environments/test.rb +10 -0
- data/test/environments/rails23/config/preinitializer.rb +25 -0
- data/test/environments/rails23/config/routes.rb +5 -0
- data/test/environments/rails23/db/schema.rb +5 -0
- data/test/environments/rails30/Gemfile +19 -0
- data/test/environments/rails30/Rakefile +9 -0
- data/test/environments/rails30/config/application.rb +17 -0
- data/test/environments/rails30/config/boot.rb +10 -0
- data/test/environments/rails30/config/database.yml +31 -0
- data/test/environments/rails30/config/environment.rb +6 -0
- data/test/environments/rails30/config/initializers/new_rails_defaults.rb +11 -0
- data/test/environments/rails30/db/schema.rb +5 -0
- data/test/environments/rails31/Gemfile +19 -0
- data/test/environments/rails31/Rakefile +9 -0
- data/test/environments/rails31/config/application.rb +18 -0
- data/test/environments/rails31/config/boot.rb +10 -0
- data/test/environments/rails31/config/database.yml +31 -0
- data/test/environments/rails31/config/environment.rb +6 -0
- data/test/environments/rails31/config/initializers/new_rails_defaults.rb +21 -0
- data/test/environments/rails31/db/schema.rb +5 -0
- data/test/environments/rails32/Gemfile +25 -0
- data/test/environments/rails32/Rakefile +9 -0
- data/test/environments/rails32/config/application.rb +19 -0
- data/test/environments/rails32/config/boot.rb +10 -0
- data/test/environments/rails32/config/database.yml +31 -0
- data/test/environments/rails32/config/environment.rb +6 -0
- data/test/environments/rails32/db/schema.rb +5 -0
- data/test/environments/rails40/Gemfile +25 -0
- data/test/environments/rails40/Rakefile +9 -0
- data/test/environments/rails40/config/application.rb +18 -0
- data/test/environments/rails40/config/boot.rb +10 -0
- data/test/environments/rails40/config/database.yml +31 -0
- data/test/environments/rails40/config/environment.rb +6 -0
- data/test/environments/rails40/db/schema.rb +5 -0
- data/test/multiverse/lib/multiverse/suite.rb +24 -12
- data/test/multiverse/suites/agent_only/logging_test.rb +18 -1
- data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +1 -8
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +10 -7
- data/test/multiverse/suites/curb/curb_test.rb +17 -3
- data/test/multiverse/suites/excon/Envfile +1 -1
- data/test/multiverse/suites/excon/excon_test.rb +18 -2
- data/test/multiverse/suites/httpclient/httpclient_test.rb +2 -2
- data/test/multiverse/suites/net_http/net_http_test.rb +2 -2
- data/test/multiverse/suites/rails/error_tracing_test.rb +35 -8
- data/test/multiverse/suites/rails/ignore_test.rb +48 -0
- data/test/multiverse/suites/rails/mongrel_queue_depth_test.rb +44 -0
- data/test/multiverse/suites/sequel/sequel_test.rb +11 -0
- data/test/multiverse/suites/sinatra/ignoring_test.rb +2 -2
- data/test/multiverse/suites/typhoeus/Envfile +9 -2
- data/test/multiverse/suites/typhoeus/typhoeus_test.rb +3 -2
- data/test/new_relic/agent/agent/start_test.rb +3 -22
- data/test/new_relic/agent/agent_test.rb +6 -5
- data/test/new_relic/agent/autostart_test.rb +39 -1
- data/test/new_relic/agent/browser_monitoring_test.rb +43 -88
- data/test/new_relic/agent/browser_token_test.rb +52 -0
- data/test/new_relic/agent/busy_calculator_test.rb +1 -1
- data/test/new_relic/agent/commands/agent_command_router_test.rb +98 -0
- data/test/new_relic/agent/commands/agent_command_test.rb +37 -0
- data/test/new_relic/agent/commands/thread_profiler_test.rb +177 -0
- data/test/new_relic/agent/configuration/default_source_test.rb +81 -0
- data/test/new_relic/agent/configuration/environment_source_test.rb +81 -7
- data/test/new_relic/agent/configuration/manager_test.rb +16 -1
- data/test/new_relic/agent/cross_app_monitor_test.rb +3 -5
- data/test/new_relic/agent/error_collector_test.rb +14 -0
- data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +2 -3
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +29 -31
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +22 -0
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +2 -2
- data/test/new_relic/agent/method_tracer_test.rb +2 -2
- data/test/new_relic/agent/new_relic_service_test.rb +5 -49
- data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -0
- data/test/new_relic/agent/request_sampler_test.rb +32 -95
- data/test/new_relic/agent/rpm_agent_test.rb +7 -5
- data/test/new_relic/agent/sampled_buffer_test.rb +178 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +0 -1
- data/test/new_relic/agent/stats_engine_test.rb +10 -17
- data/test/new_relic/agent/threading/agent_thread_test.rb +107 -0
- data/test/new_relic/agent/threading/backtrace_node_test.rb +96 -0
- data/test/new_relic/agent/{threaded_test.rb → threading/fake_thread.rb} +0 -25
- data/test/new_relic/agent/threading/thread_profile_test.rb +308 -0
- data/test/new_relic/agent/threading/threaded_test_case.rb +33 -0
- data/test/new_relic/agent/transaction/pop_test.rb +0 -16
- data/test/new_relic/agent/transaction_sample_builder_test.rb +23 -4
- data/test/new_relic/agent/transaction_sampler_test.rb +14 -15
- data/test/new_relic/agent/transaction_state_test.rb +75 -0
- data/test/new_relic/agent/transaction_test.rb +15 -0
- data/test/new_relic/agent/transaction_timings_test.rb +81 -0
- data/test/new_relic/agent_test.rb +12 -14
- data/test/new_relic/{command → cli}/deployments_test.rb +41 -13
- data/test/new_relic/control/frameworks/rails_test.rb +1 -2
- data/test/new_relic/control_test.rb +1 -2
- data/test/new_relic/dependency_detection_test.rb +14 -0
- data/test/new_relic/fake_collector.rb +1 -0
- data/test/new_relic/helper_test.rb +7 -2
- data/test/new_relic/http_client_test_cases.rb +33 -1
- data/test/new_relic/local_environment_test.rb +0 -23
- data/test/new_relic/metric_data_test.rb +4 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +31 -30
- data/test/performance/lib/performance/result.rb +15 -4
- data/test/performance/lib/performance/timer.rb +7 -1
- data/test/performance/script/baselines +102 -0
- data/test/performance/suites/rum_autoinsertion.rb +57 -0
- data/test/rum/basic.result.html +10 -0
- data/test/rum/basic.source.html +10 -0
- data/test/rum/comments1.result.html +24 -0
- data/test/rum/comments1.source.html +24 -0
- data/test/rum/comments2.result.html +24 -0
- data/test/rum/comments2.source.html +24 -0
- data/test/rum/gt_in_quotes1.result.html +27 -0
- data/test/rum/gt_in_quotes1.source.html +27 -0
- data/test/rum/gt_in_quotes2.result.html +24 -0
- data/test/rum/gt_in_quotes2.source.html +24 -0
- data/test/rum/gt_in_quotes_mismatch.result.html +24 -0
- data/test/rum/gt_in_quotes_mismatch.source.html +24 -0
- data/test/rum/gt_in_single_quotes1.result.html +25 -0
- data/test/rum/gt_in_single_quotes1.source.html +25 -0
- data/test/rum/gt_in_single_quotes_mismatch.result.html +25 -0
- data/test/rum/gt_in_single_quotes_mismatch.source.html +25 -0
- data/test/rum/incomplete_non_meta_tags.result.html +10 -0
- data/test/rum/incomplete_non_meta_tags.source.html +10 -0
- data/test/rum/no_body.result.html +21 -0
- data/test/rum/no_body.source.html +21 -0
- data/test/rum/no_header.result.html +7 -0
- data/test/rum/no_header.source.html +7 -0
- data/test/rum/no_start_header.result.html +9 -0
- data/test/rum/no_start_header.source.html +9 -0
- data/test/rum/script1.result.html +19 -0
- data/test/rum/script1.source.html +19 -0
- data/test/rum/script2.result.html +17 -0
- data/test/rum/script2.source.html +17 -0
- data/test/rum/x_ua_meta_tag.result.html +10 -0
- data/test/rum/x_ua_meta_tag.source.html +10 -0
- data/test/rum/x_ua_meta_tag_multiline.result.html +11 -0
- data/test/rum/x_ua_meta_tag_multiline.source.html +11 -0
- data/test/rum/x_ua_meta_tag_with_others.result.html +11 -0
- data/test/rum/x_ua_meta_tag_with_others.source.html +11 -0
- data/test/rum/x_ua_meta_tag_with_spaces.result.html +10 -0
- data/test/rum/x_ua_meta_tag_with_spaces.source.html +10 -0
- data/test/script/ci.sh +1 -12
- data/test/test_helper.rb +1 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +11 -0
- metadata +225 -32
- metadata.gz.sig +0 -0
- data/lib/new_relic/agent/configuration/defaults.rb +0 -157
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +0 -56
- data/lib/new_relic/agent/thread.rb +0 -37
- data/lib/new_relic/agent/thread_profiler.rb +0 -323
- data/lib/new_relic/agent/transaction_info.rb +0 -114
- data/lib/new_relic/command.rb +0 -89
- data/test/new_relic/agent/agent_test_controller_test.rb +0 -348
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +0 -70
- data/test/new_relic/agent/thread_profiler_test.rb +0 -586
- data/test/new_relic/agent/thread_test.rb +0 -93
- data/test/new_relic/agent/transaction_info_test.rb +0 -99
@@ -59,10 +59,9 @@ module NewRelic
|
|
59
59
|
get_stats(metric_name, false)
|
60
60
|
end
|
61
61
|
|
62
|
-
# If use_scope is true, two chained metrics are created, one with scope and one without
|
63
62
|
# If scoped_metric_only is true, only a scoped metric is created (used by rendering metrics which by definition are per controller only)
|
64
|
-
|
65
|
-
|
63
|
+
# Leaving second, unused parameter for compatibility
|
64
|
+
def get_stats(metric_name, _ = true, scoped_metric_only = false, scope = nil)
|
66
65
|
stats = nil
|
67
66
|
with_stats_lock do
|
68
67
|
if scoped_metric_only
|
@@ -29,8 +29,6 @@ module Agent
|
|
29
29
|
def end_transaction; end
|
30
30
|
def push_scope(*args); end
|
31
31
|
def transaction_sampler=(*args); end
|
32
|
-
def scope_name=(*args); end
|
33
|
-
def scope_name; end
|
34
32
|
def pop_scope(*args); end
|
35
33
|
end
|
36
34
|
|
@@ -85,23 +83,6 @@ module Agent
|
|
85
83
|
NewRelic::Agent.logger.warn("NewRelic::Agent::StatsEngine#transaction_sampler is deprecated")
|
86
84
|
end
|
87
85
|
|
88
|
-
# set the name of the transaction for the current thread, which will be used
|
89
|
-
# to define the scope of all traced methods called on this thread until the
|
90
|
-
# scope stack is empty.
|
91
|
-
#
|
92
|
-
# currently the transaction name is the name of the controller action that
|
93
|
-
# is invoked via the dispatcher, but conceivably we could use other transaction
|
94
|
-
# names in the future if the traced application does more than service http request
|
95
|
-
# via controller actions
|
96
|
-
def scope_name=(transaction)
|
97
|
-
Thread::current[:newrelic_scope_name] = transaction
|
98
|
-
end
|
99
|
-
|
100
|
-
# Returns the current scope name from the thread local
|
101
|
-
def scope_name
|
102
|
-
Thread::current[:newrelic_scope_name]
|
103
|
-
end
|
104
|
-
|
105
86
|
# Start a new transaction, unless one is already in progress
|
106
87
|
def start_transaction
|
107
88
|
NewRelic::Agent.instance.events.notify(:start_transaction)
|
@@ -115,8 +96,7 @@ module Agent
|
|
115
96
|
stack = scope_stack
|
116
97
|
|
117
98
|
if stack && stack.empty?
|
118
|
-
|
119
|
-
Thread::current[:newrelic_scope_name] = nil
|
99
|
+
NewRelic::Agent::TransactionState.get.clear_stats_scope_stack
|
120
100
|
end
|
121
101
|
end
|
122
102
|
|
@@ -126,7 +106,7 @@ module Agent
|
|
126
106
|
|
127
107
|
# Returns the current scope stack, memoized to a thread local variable
|
128
108
|
def scope_stack
|
129
|
-
|
109
|
+
NewRelic::Agent::TransactionState.get.stats_scope_stack
|
130
110
|
end
|
131
111
|
end
|
132
112
|
end
|
@@ -0,0 +1,41 @@
|
|
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
|
+
module NewRelic
|
6
|
+
module Agent
|
7
|
+
module Threading
|
8
|
+
|
9
|
+
class AgentThread < ::Thread
|
10
|
+
def initialize(label)
|
11
|
+
::NewRelic::Agent.logger.debug("Creating New Relic thread: #{label}")
|
12
|
+
self[:newrelic_label] = label
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.bucket_thread(thread, profile_agent_code)
|
17
|
+
if thread.key?(:newrelic_label)
|
18
|
+
profile_agent_code ? :agent : :ignore
|
19
|
+
elsif TransactionState.in_background_transaction?(thread)
|
20
|
+
:background
|
21
|
+
elsif TransactionState.in_request_transaction?(thread)
|
22
|
+
:request
|
23
|
+
else
|
24
|
+
:other
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.scrub_backtrace(thread, profile_agent_code)
|
29
|
+
begin
|
30
|
+
bt = thread.backtrace
|
31
|
+
rescue Exception => e
|
32
|
+
::NewRelic::Agent.logger.debug("Failed to backtrace #{thread.inspect}: #{e.class.name}: #{e.to_s}")
|
33
|
+
end
|
34
|
+
return nil unless bt
|
35
|
+
profile_agent_code ? bt : bt.select { |t| t !~ /\/newrelic_rpm-\d/ }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,71 @@
|
|
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
|
+
module NewRelic
|
6
|
+
module Agent
|
7
|
+
module Threading
|
8
|
+
|
9
|
+
class BacktraceNode
|
10
|
+
attr_reader :file, :method, :line_no, :children
|
11
|
+
attr_accessor :runnable_count, :to_prune, :depth
|
12
|
+
|
13
|
+
def initialize(line, parent=nil)
|
14
|
+
line =~ /(.*)\:(\d+)\:in `(.*)'/
|
15
|
+
@file = $1
|
16
|
+
@method = $3
|
17
|
+
@line_no = $2.to_i
|
18
|
+
@children = []
|
19
|
+
@runnable_count = 0
|
20
|
+
@to_prune = false
|
21
|
+
@depth = 0
|
22
|
+
|
23
|
+
parent.add_child(self) if parent
|
24
|
+
end
|
25
|
+
|
26
|
+
def ==(other)
|
27
|
+
@file == other.file &&
|
28
|
+
@method == other.method &&
|
29
|
+
@line_no == other.line_no
|
30
|
+
end
|
31
|
+
|
32
|
+
def total_count
|
33
|
+
@runnable_count
|
34
|
+
end
|
35
|
+
|
36
|
+
# Descending order on count, ascending on depth of nodes
|
37
|
+
def order_for_pruning(y)
|
38
|
+
[-runnable_count, depth] <=> [-y.runnable_count, y.depth]
|
39
|
+
end
|
40
|
+
|
41
|
+
include NewRelic::Coerce
|
42
|
+
|
43
|
+
def to_array
|
44
|
+
[[
|
45
|
+
string(@file),
|
46
|
+
string(@method),
|
47
|
+
int(@line_no)
|
48
|
+
],
|
49
|
+
int(@runnable_count),
|
50
|
+
0,
|
51
|
+
@children.map {|c| c.to_array}]
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_child(child)
|
55
|
+
child.depth = @depth + 1
|
56
|
+
@children << child unless @children.include? child
|
57
|
+
end
|
58
|
+
|
59
|
+
def prune!
|
60
|
+
BacktraceNode.prune!(@children)
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.prune!(kids)
|
64
|
+
kids.delete_if { |child| child.to_prune }
|
65
|
+
kids.each { |child| child.prune! }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,172 @@
|
|
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
|
+
require 'new_relic/agent/worker_loop'
|
6
|
+
require 'new_relic/agent/threading/backtrace_node'
|
7
|
+
|
8
|
+
# Intent is for this to be a data structure for representing a thread profile
|
9
|
+
# TODO: Get rid of the running/sampling in this class, externalize it elsewhere
|
10
|
+
|
11
|
+
module NewRelic
|
12
|
+
module Agent
|
13
|
+
module Threading
|
14
|
+
|
15
|
+
class ThreadProfile
|
16
|
+
|
17
|
+
attr_reader :profile_id,
|
18
|
+
:traces,
|
19
|
+
:profile_agent_code,
|
20
|
+
:interval, :duration,
|
21
|
+
:poll_count, :sample_count,
|
22
|
+
:start_time, :stop_time
|
23
|
+
|
24
|
+
def initialize(agent_command)
|
25
|
+
arguments = agent_command.arguments
|
26
|
+
@profile_id = arguments.fetch('profile_id', -1)
|
27
|
+
@profile_agent_code = arguments.fetch('profile_agent_code', true)
|
28
|
+
|
29
|
+
@duration = arguments.fetch('duration', 120)
|
30
|
+
@worker_loop = NewRelic::Agent::WorkerLoop.new(:duration => duration)
|
31
|
+
@interval = arguments.fetch('sample_period', 0.1)
|
32
|
+
@finished = false
|
33
|
+
|
34
|
+
@traces = {
|
35
|
+
:agent => [],
|
36
|
+
:background => [],
|
37
|
+
:other => [],
|
38
|
+
:request => []
|
39
|
+
}
|
40
|
+
@flattened_nodes = []
|
41
|
+
|
42
|
+
@poll_count = 0
|
43
|
+
@sample_count = 0
|
44
|
+
@failure_count = 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def run
|
48
|
+
NewRelic::Agent.logger.debug("Starting thread profile. profile_id=#{profile_id}, duration=#{duration}")
|
49
|
+
|
50
|
+
Threading::AgentThread.new('Thread Profiler') do
|
51
|
+
@start_time = now_in_millis
|
52
|
+
|
53
|
+
@worker_loop.run(@interval) do
|
54
|
+
NewRelic::Agent.instance.stats_engine.
|
55
|
+
record_supportability_metric_timed("ThreadProfiler/PollingTime") do
|
56
|
+
|
57
|
+
@poll_count += 1
|
58
|
+
Threading::AgentThread.list.each do |t|
|
59
|
+
bucket = Threading::AgentThread.bucket_thread(t, @profile_agent_code)
|
60
|
+
if bucket != :ignore
|
61
|
+
backtrace = Threading::AgentThread.scrub_backtrace(t, @profile_agent_code)
|
62
|
+
if backtrace.nil?
|
63
|
+
@failure_count += 1
|
64
|
+
else
|
65
|
+
@sample_count += 1
|
66
|
+
aggregate(backtrace, @traces[bucket])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
mark_done
|
74
|
+
NewRelic::Agent.logger.debug("Finished thread profile. #{@sample_count} backtraces, #{@failure_count} failures. Will send with next harvest.")
|
75
|
+
NewRelic::Agent.instance.stats_engine.
|
76
|
+
record_supportability_metric_count("ThreadProfiler/BacktraceFailures", @failure_count)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def stop
|
81
|
+
@worker_loop.stop
|
82
|
+
mark_done
|
83
|
+
NewRelic::Agent.logger.debug("Stopping thread profile.")
|
84
|
+
end
|
85
|
+
|
86
|
+
def aggregate(trace, trees=@traces[:request], parent=nil)
|
87
|
+
return nil if trace.nil? || trace.empty?
|
88
|
+
node = Threading::BacktraceNode.new(trace.last)
|
89
|
+
existing = trees.find {|n| n == node}
|
90
|
+
|
91
|
+
if existing.nil?
|
92
|
+
existing = node
|
93
|
+
@flattened_nodes << node
|
94
|
+
end
|
95
|
+
|
96
|
+
if parent
|
97
|
+
parent.add_child(node)
|
98
|
+
else
|
99
|
+
trees << node unless trees.include? node
|
100
|
+
end
|
101
|
+
|
102
|
+
existing.runnable_count += 1
|
103
|
+
aggregate(trace[0..-2], existing.children, existing)
|
104
|
+
|
105
|
+
existing
|
106
|
+
end
|
107
|
+
|
108
|
+
def prune!(count_to_keep)
|
109
|
+
@flattened_nodes.sort!(&:order_for_pruning)
|
110
|
+
|
111
|
+
NewRelic::Agent.instance.stats_engine.
|
112
|
+
record_supportability_metric_count("ThreadProfiler/NodeCount", @flattened_nodes.size)
|
113
|
+
|
114
|
+
mark_for_pruning(@flattened_nodes, count_to_keep)
|
115
|
+
|
116
|
+
traces.each { |_, nodes| Threading::BacktraceNode.prune!(nodes) }
|
117
|
+
end
|
118
|
+
|
119
|
+
THREAD_PROFILER_NODES = 20_000
|
120
|
+
|
121
|
+
include NewRelic::Coerce
|
122
|
+
|
123
|
+
def to_collector_array(encoder)
|
124
|
+
prune!(THREAD_PROFILER_NODES)
|
125
|
+
|
126
|
+
traces = {
|
127
|
+
"OTHER" => @traces[:other].map{|t| t.to_array },
|
128
|
+
"REQUEST" => @traces[:request].map{|t| t.to_array },
|
129
|
+
"AGENT" => @traces[:agent].map{|t| t.to_array },
|
130
|
+
"BACKGROUND" => @traces[:background].map{|t| t.to_array }
|
131
|
+
}
|
132
|
+
|
133
|
+
[[
|
134
|
+
int(@profile_id),
|
135
|
+
float(@start_time),
|
136
|
+
float(@stop_time),
|
137
|
+
int(@poll_count),
|
138
|
+
string(encoder.encode(traces)),
|
139
|
+
int(@sample_count),
|
140
|
+
0
|
141
|
+
]]
|
142
|
+
end
|
143
|
+
|
144
|
+
def now_in_millis
|
145
|
+
Time.now.to_f * 1_000
|
146
|
+
end
|
147
|
+
|
148
|
+
def finished?
|
149
|
+
@finished
|
150
|
+
end
|
151
|
+
|
152
|
+
def mark_done
|
153
|
+
@finished = true
|
154
|
+
@stop_time = now_in_millis
|
155
|
+
end
|
156
|
+
|
157
|
+
def mark_for_pruning(nodes, count_to_keep)
|
158
|
+
to_prune = nodes[count_to_keep..-1] || []
|
159
|
+
to_prune.each { |n| n.to_prune = true }
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.parse_backtrace(trace)
|
163
|
+
trace.map do |line|
|
164
|
+
line =~ /(.*)\:(\d+)\:in `(.*)'/
|
165
|
+
{ :method => $3, :line_no => $2.to_i, :file => $1 }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
4
|
|
5
5
|
require 'new_relic/agent/transaction/pop'
|
6
|
+
require 'new_relic/agent/transaction_timings'
|
6
7
|
|
7
8
|
# A struct holding the information required to measure a controller
|
8
9
|
# action. This is put on the thread local. Handles the issue of
|
@@ -30,7 +31,6 @@ module NewRelic
|
|
30
31
|
# as a Rack::Request or an ActionController::AbstractRequest.
|
31
32
|
attr_accessor :request
|
32
33
|
|
33
|
-
|
34
34
|
# Return the currently active transaction, or nil.
|
35
35
|
def self.current
|
36
36
|
self.stack.last
|
@@ -54,7 +54,7 @@ module NewRelic
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.stack
|
57
|
-
|
57
|
+
TransactionState.get.current_transaction_stack
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.in_transaction?
|
@@ -104,7 +104,11 @@ module NewRelic
|
|
104
104
|
@request = options[:request]
|
105
105
|
@exceptions = {}
|
106
106
|
@stats_hash = StatsHash.new
|
107
|
-
|
107
|
+
TransactionState.get.transaction = self
|
108
|
+
end
|
109
|
+
|
110
|
+
def noticed_error_ids
|
111
|
+
@noticed_error_ids ||= []
|
108
112
|
end
|
109
113
|
|
110
114
|
def name=(name)
|
@@ -290,7 +294,6 @@ module NewRelic
|
|
290
294
|
return unless recording_web_transaction? && NewRelic::Agent.is_execution_traced?
|
291
295
|
|
292
296
|
freeze_name
|
293
|
-
apdex_t = TransactionInfo.get.apdex_t
|
294
297
|
action_duration = end_time - start_time
|
295
298
|
total_duration = end_time - apdex_start
|
296
299
|
is_error = is_error.nil? ? !exceptions.empty? : is_error
|
@@ -303,6 +306,15 @@ module NewRelic
|
|
303
306
|
@stats_hash.record(txn_apdex_metric, apdex_bucket_txn, apdex_t)
|
304
307
|
end
|
305
308
|
|
309
|
+
def apdex_t
|
310
|
+
transaction_specific_apdex_t || Agent.config[:apdex_t]
|
311
|
+
end
|
312
|
+
|
313
|
+
def transaction_specific_apdex_t
|
314
|
+
key = :web_transactions_apdex
|
315
|
+
Agent.config[key] && Agent.config[key][self.name]
|
316
|
+
end
|
317
|
+
|
306
318
|
# Yield to a block that is run with a database metric name context. This means
|
307
319
|
# the Database instrumentation will use this for the metric name if it does not
|
308
320
|
# otherwise know about a model. This is re-entrant.
|
@@ -110,13 +110,23 @@ module NewRelic
|
|
110
110
|
@sample.params[:custom_params] ||= {}
|
111
111
|
@sample.params[:custom_params].merge!(normalize_params(custom_params))
|
112
112
|
|
113
|
-
|
114
|
-
@sample.
|
115
|
-
@sample.threshold = txn_info.transaction_trace_threshold
|
113
|
+
@sample.force_persist = sample.force_persist_sample?
|
114
|
+
@sample.threshold = transaction_trace_threshold
|
116
115
|
@sample.freeze
|
117
116
|
@current_segment = nil
|
118
117
|
end
|
119
118
|
|
119
|
+
TT_THRESHOLD_KEY = :'transaction_tracer.transaction_threshold'
|
120
|
+
|
121
|
+
def transaction_trace_threshold
|
122
|
+
source_class = Agent.config.source(TT_THRESHOLD_KEY).class
|
123
|
+
if source_class == Configuration::DefaultSource && TransactionState.get.transaction
|
124
|
+
TransactionState.get.transaction.apdex_t * 4
|
125
|
+
else
|
126
|
+
Agent.config[TT_THRESHOLD_KEY]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
120
130
|
def scope_depth
|
121
131
|
depth = -1 # have to account for the root
|
122
132
|
current = @current_segment
|