Module: ProcPath

Defined in:
lib/rbbt/util/procpath.rb

Class Method Summary collapse

Class Method Details

.monitor(pid, path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rbbt/util/procpath.rb', line 37

def self.monitor(pid, path)
  database, options_str = path.split("#")
  options = options_str.nil? ? {} : Misc.string2hash(options_str)

  database = File.expand_path database
  Log.low "ProcPath monitor #{pid} in #{database} (#{Misc.fingerprint options})"

  ProcPath.record(pid, database + '.sqlite3', options)
  ProcPath.plot(database + '.sqlite3', database + '.cpu.svg', options.merge("query-name" => 'cpu'))
  ProcPath.plot(database + '.sqlite3', database + '.rss.svg', options.merge("query-name" => 'rss'))
end

.plot(path, output, options = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/rbbt/util/procpath.rb', line 29

def self.plot(path, output, options = {})
  IndiferentHash.setup(options)
  options = Misc.add_defaults options, "query-name" => 'rss', 'epsilon' => 0.5, "moving-average-window" => 10

  cmd_options = %w(query-name epsilon monitor-average-window title logarithmic after before custom-query-file custom-value-expr).inject({}){|acc,k| acc[k] = options[k]; acc}
  CMD.cmd_log(:procpath, "plot --database-file '#{path}' --plot-file '#{output}' ", cmd_options.merge(:nofail => true, :add_option_dashes => true))
end

.record(pid, path, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rbbt/util/procpath.rb', line 7

def self.record(pid, path, options = {})
  IndiferentHash.setup(options)
  options = Misc.add_defaults options, "interval" => 30

  cmd_options = %w(interval recnum reevalnum).inject({}){|acc,k| acc[k] = options[k]; acc}

  Log.debug "ProcPath recording #{pid} in #{path} (#{Misc.fingerprint options})"
  procpath_thread = Thread.new do 
    begin
      procpath_pid = CMD.cmd_pid(:procpath, "record --database-file '#{path}' '$..children[?(@.stat.pid == #{pid})]'", cmd_options.merge(:nofail => true, :add_option_dashes => true))
    rescue Exception
      Log.exceptions $!
      Process.kill "INT", procpath_pid
    end
  end

  procpath_thread.report_on_exception = false

  Process.wait pid.to_i
  procpath_thread.raise Interrupt
end