Class: StackProf::Remote::ProcessReportCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/stackprof/remote/process_report_collector.rb

Overview

ProcessReportCollector handles the work of actually starting, stopping, and collecting the dumps from the StackProf profiler.

Internally it uses RBTrace to execute the start/stop methods against all runnign processes that match pids found by the :pid_finder option. By default this matches unicorn workers.

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :pid_finder => -> {
    `pgrep -f 'unicorn worker'`.strip.split.collect {|p| p.to_i }
  },
  :mode => :cpu,
  :interval => 1000,
  :raw => true,
  :path => 'tmp'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ProcessReportCollector

Returns a new instance of ProcessReportCollector.



23
24
25
26
# File 'lib/stackprof/remote/process_report_collector.rb', line 23

def initialize(options = {})
  @options = DEFAULT_OPTIONS.merge(options)
  collect_pids
end

Class Method Details

.report_from_marshaled_results(marshaled_data) ⇒ Object



56
57
58
59
# File 'lib/stackprof/remote/process_report_collector.rb', line 56

def self.report_from_marshaled_results(marshaled_data)
  data = Marshal.load(marshaled_data)
  report = data.inject(nil) {|sum, d| sum ? StackProf::Report.new(d) + sum : StackProf::Report.new(d) }
end

Instance Method Details

#loggerObject



28
29
30
# File 'lib/stackprof/remote/process_report_collector.rb', line 28

def logger
  StackProf::Remote::Middleware.logger
end

#marshaled_resultsObject



47
48
49
50
51
52
53
54
# File 'lib/stackprof/remote/process_report_collector.rb', line 47

def marshaled_results
  if @saved_files
    saved_data = @saved_files.collect {|f|
      Marshal.load(File.read(f))
    }
    Marshal.dump(saved_data)
  end
end

#saveObject



42
43
44
45
# File 'lib/stackprof/remote/process_report_collector.rb', line 42

def save
  command = "StackProf::Remote::ReportSaver.save('#{@options[:path]}')"
  @saved_files = execute(command)
end

#startObject



32
33
34
35
# File 'lib/stackprof/remote/process_report_collector.rb', line 32

def start
  command = "StackProf.start(mode: #{@options[:mode].inspect}, interval: #{@options[:interval].inspect}, raw: #{@options[:raw].inspect})"
  execute(command)
end

#stopObject



37
38
39
40
# File 'lib/stackprof/remote/process_report_collector.rb', line 37

def stop
  command = "StackProf.stop"
  execute(command)
end