Class: NewRelic::Agent::ThreadProfiler
- Inherits:
-
Object
- Object
- NewRelic::Agent::ThreadProfiler
- Defined in:
- lib/new_relic/agent/thread_profiler.rb
Instance Attribute Summary collapse
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
Class Method Summary collapse
Instance Method Summary collapse
- #finished? ⇒ Boolean
- #harvest ⇒ Object
- #respond_to_commands(commands, ¬ify_results) ⇒ Object
- #running? ⇒ Boolean
- #start(profile_id, duration, interval, profile_agent_code) ⇒ Object
- #stop(report_data) ⇒ Object
Instance Attribute Details
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
13 14 15 |
# File 'lib/new_relic/agent/thread_profiler.rb', line 13 def profile @profile end |
Class Method Details
.is_supported? ⇒ Boolean
15 16 17 |
# File 'lib/new_relic/agent/thread_profiler.rb', line 15 def self.is_supported? RUBY_VERSION >= "1.9.2" end |
Instance Method Details
#finished? ⇒ Boolean
78 79 80 |
# File 'lib/new_relic/agent/thread_profiler.rb', line 78 def finished? @profile && @profile.finished? end |
#harvest ⇒ Object
35 36 37 38 39 |
# File 'lib/new_relic/agent/thread_profiler.rb', line 35 def harvest profile = @profile @profile = nil profile end |
#respond_to_commands(commands, ¬ify_results) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/new_relic/agent/thread_profiler.rb', line 41 def respond_to_commands(commands, ¬ify_results) return if commands.empty? || commands.first.size < 2 # Doesn't deal with multiple commands in the return set as # we currently only have start/stop of thread profiling command_id = commands.first[0] command = commands.first[1] name = command["name"] arguments = command["arguments"] if (ThreadProfiler.is_supported?) case name when "start_profiler" start_unless_running_and_notify(command_id, arguments, ¬ify_results) when "stop_profiler" stop_and_notify(command_id, arguments, ¬ify_results) end else msg = <<-EOF Thread profiling is only supported on 1.9.2 and greater versions of Ruby. We detected running agents capable of profiling, but the profile started with an agent running Ruby #{RUBY_VERSION}. Profiling again might select an appropriate agent, but we recommend running a consistent version of Ruby across your application for better results. EOF ::NewRelic::Agent.logger.debug(msg) notify_results.call(command_id, msg) if !notify_results.nil? end end |
#running? ⇒ Boolean
74 75 76 |
# File 'lib/new_relic/agent/thread_profiler.rb', line 74 def running? !@profile.nil? end |
#start(profile_id, duration, interval, profile_agent_code) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/new_relic/agent/thread_profiler.rb', line 19 def start(profile_id, duration, interval, profile_agent_code) if !ThreadProfiler.is_supported? ::NewRelic::Agent.logger.debug("Not starting thread profile as it isn't supported on this environment") @profile = nil else ::NewRelic::Agent.logger.debug("Starting thread profile. profile_id=#{profile_id}, duration=#{duration}") @profile = ThreadProfile.new(profile_id, duration, interval, profile_agent_code) @profile.run end end |
#stop(report_data) ⇒ Object
30 31 32 33 |
# File 'lib/new_relic/agent/thread_profiler.rb', line 30 def stop(report_data) @profile.stop unless @profile.nil? @profile = nil if !report_data end |