Class: JvmGcGraph::ParseMemoryLog

Inherits:
Object
  • Object
show all
Defined in:
lib/jvm_gc_graph.rb

Constant Summary collapse

GC_REGEX =
/^(([0-9]|\.)*):\s\[(GC\s([0-9]*)K->([0-9]*)K\(([0-9]*)K\)),\s(([0-9]|\.)*).*\]/
FULL_GC_REGEX =
/^(([0-9]|\.)*):\s\[(Full GC\s([0-9]*)K->([0-9]*)K\(([0-9]*)K\)),\s(([0-9]|\.)*).*\]/
ANY_GC_REGEX =
/^(([0-9]|\.)*):\s\[((Full )?GC\s([0-9]*)K->([0-9]*)K\(([0-9]*)K\)),\s(([0-9]|\.)*).*\]/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ ParseMemoryLog

Returns a new instance of ParseMemoryLog.



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

def initialize(opts)
  File.open(opts[:file], "r") do |f|
    @lines = f.readlines
  end
  if m = @lines.last.match(ANY_GC_REGEX)
    @start_time = Time.now.to_i - m[0].to_f
  end
  @data = []
  @gc_data = []
  self.class.send(:define_method, :title) {opts[:title]}
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



35
36
37
# File 'lib/jvm_gc_graph.rb', line 35

def data
  @data
end

#gc_dataObject

Returns the value of attribute gc_data.



35
36
37
# File 'lib/jvm_gc_graph.rb', line 35

def gc_data
  @gc_data
end

#linesObject

Returns the value of attribute lines.



35
36
37
# File 'lib/jvm_gc_graph.rb', line 35

def lines
  @lines
end

#start_timeObject

Returns the value of attribute start_time.



35
36
37
# File 'lib/jvm_gc_graph.rb', line 35

def start_time
  @start_time
end

Instance Method Details

#add_gc_arrays(matches) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/jvm_gc_graph.rb', line 60

def add_gc_arrays(matches)
  add_to_array(@data, matches[0].to_i,
               [matches[4].to_f, nil,nil,
                matches[5].to_f, nil,nil,
                matches[6].to_f, nil,nil])
  add_to_array(@gc_data, matches[0].to_i, [(matches[7].to_f*1000), nil,nil])
end

#add_to_array(data_values, time, values) ⇒ Object



68
69
70
71
# File 'lib/jvm_gc_graph.rb', line 68

def add_to_array(data_values, time, values)
  d = [((@start_time + time)*1000)]
  data_values << (d + values)
end

#get_bindingObject



78
79
80
# File 'lib/jvm_gc_graph.rb', line 78

def get_binding
  binding
end

#jsonObject



73
74
75
76
# File 'lib/jvm_gc_graph.rb', line 73

def json
  parse_lines
  @data
end

#parse_linesObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/jvm_gc_graph.rb', line 49

def parse_lines
  lines.each do |line|
    if m = line.match(GC_REGEX)
      add_gc_arrays(m)
    elsif m = line.match(FULL_GC_REGEX)
      # might want to do something different with Full GC
      add_gc_arrays(m)
    end
  end
end