Class: ServerScripts::Parser::Cubex

Inherits:
Object
  • Object
show all
Defined in:
lib/server_scripts/parser/cubex.rb

Instance Method Summary collapse

Constructor Details

#initialize(fname) ⇒ Cubex

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

Raises:

  • (RuntimeError)


6
7
8
9
10
11
12
# 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

Instance Method Details

#all_metricsObject

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



35
36
37
38
# File 'lib/server_scripts/parser/cubex.rb', line 35

def all_metrics
  output = `cube_info #{@fname} -l`
  output.split("\n")
end

#call_treeObject

Get the call tree of the file as a string.



15
16
17
# File 'lib/server_scripts/parser/cubex.rb', line 15

def call_tree
  `cube_info #{@fname}`
end

#parse(metric:, event:) ⇒ Object

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.



21
22
23
24
25
26
27
28
29
30
31
32
# 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