class ServerScripts::Parser::Cubex

Public Class Methods

new(fname) click to toggle source

Supply the folder name of the cubex file. There should be a profile.cubex file inside this folder.

# File lib/server_scripts/parser/cubex.rb, line 6
def initialize(fname)
  ['cube_stat', 'cube_info'].each do |cmd|
    raise RuntimeError, "Must have #{cmd} installed." unless File.which(cmd)
  end
  @fname = "#{fname}/profile.cubex"
  raise RuntimeError, "#{@fname} does not exist!"  unless File.exists?(@fname)
end

Public Instance Methods

all_metrics() click to toggle source

Return an array of all the metrics available for the given cubex file.

# File lib/server_scripts/parser/cubex.rb, line 35
def all_metrics
  output = `cube_info #{@fname} -l`
  output.split("\n")
end
call_tree() click to toggle source

Get the call tree of the file as a string.

# File lib/server_scripts/parser/cubex.rb, line 15
def call_tree
  `cube_info #{@fname}`
end
parse(metric: , event: tree = `cube_info -m click to toggle source

Read the call tree and get the value for the given metric. Will return nil if the said metric does not exist for the given event.

# File lib/server_scripts/parser/cubex.rb, line 21
def parse metric: , event:
  tree = `cube_info -m #{metric} #{@fname}`
  tree.each_line do |line|
    if /\s+#{event}\s+/.match(line)
      wo_space = line.gsub(" ", "")
      value = (/\|(\d+\.?\d+?)\|/.match(wo_space)[1]).to_f
      return value
    end
  end

  nil
end