Class: NewRelic::Agent::ThreadProfiler

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/thread_profiler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#profileObject (readonly)

Returns the value of attribute profile.



9
10
11
# File 'lib/new_relic/agent/thread_profiler.rb', line 9

def profile
  @profile
end

Class Method Details

.is_supported?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/new_relic/agent/thread_profiler.rb', line 11

def self.is_supported?
  RUBY_VERSION >= "1.9.2"
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/new_relic/agent/thread_profiler.rb', line 74

def finished?
  @profile && @profile.finished?
end

#harvestObject



31
32
33
34
35
# File 'lib/new_relic/agent/thread_profiler.rb', line 31

def harvest
  profile = @profile
  @profile = nil
  profile
end

#respond_to_commands(commands, &notify_results) ⇒ Object



37
38
39
40
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
# File 'lib/new_relic/agent/thread_profiler.rb', line 37

def respond_to_commands(commands, &notify_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, &notify_results)

      when "stop_profiler"
        stop_and_notify(command_id, arguments, &notify_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

Returns:

  • (Boolean)


70
71
72
# File 'lib/new_relic/agent/thread_profiler.rb', line 70

def running?
  !@profile.nil?
end

#start(profile_id, duration, interval, profile_agent_code) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/new_relic/agent/thread_profiler.rb', line 15

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



26
27
28
29
# File 'lib/new_relic/agent/thread_profiler.rb', line 26

def stop(report_data)
  @profile.stop unless @profile.nil?
  @profile = nil if !report_data
end