Sha256: 016c6702e8fb9ea93406a4dba2bb2ca51246febd8a39e7d0dba22b6b6442e406

Contents?: true

Size: 1.89 KB

Versions: 132

Compression:

Stored size: 1.89 KB

Contents

require 'rbbt/util/cmd'
module ProcPath
  CMD.tool :procpath do
    'pip install procpath'
  end

  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

  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

  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
end

Version data entries

132 entries across 132 versions & 1 rubygems

Version Path
rbbt-util-5.33.17 lib/rbbt/util/procpath.rb
rbbt-util-5.33.16 lib/rbbt/util/procpath.rb
rbbt-util-5.33.15 lib/rbbt/util/procpath.rb
rbbt-util-5.33.14 lib/rbbt/util/procpath.rb
rbbt-util-5.33.13 lib/rbbt/util/procpath.rb
rbbt-util-5.33.12 lib/rbbt/util/procpath.rb
rbbt-util-5.33.11 lib/rbbt/util/procpath.rb
rbbt-util-5.33.9 lib/rbbt/util/procpath.rb
rbbt-util-5.33.8 lib/rbbt/util/procpath.rb
rbbt-util-5.33.7 lib/rbbt/util/procpath.rb
rbbt-util-5.33.6 lib/rbbt/util/procpath.rb
rbbt-util-5.33.5 lib/rbbt/util/procpath.rb
rbbt-util-5.33.4 lib/rbbt/util/procpath.rb
rbbt-util-5.33.3 lib/rbbt/util/procpath.rb
rbbt-util-5.33.2 lib/rbbt/util/procpath.rb
rbbt-util-5.33.1 lib/rbbt/util/procpath.rb
rbbt-util-5.33.0 lib/rbbt/util/procpath.rb
rbbt-util-5.32.30 lib/rbbt/util/procpath.rb
rbbt-util-5.32.28 lib/rbbt/util/procpath.rb
rbbt-util-5.32.27 lib/rbbt/util/procpath.rb