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)


61
62
63
# File 'lib/new_relic/agent/thread_profiler.rb', line 61

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
# 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"]

  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
end

#running?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/new_relic/agent/thread_profiler.rb', line 57

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?
    log.debug("Not starting thread profile as it isn't supported on this environment")
    @profile = nil
  else
    log.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