Class: JVMGCLog

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

Instance Method Summary collapse

Constructor Details

#initializeJVMGCLog

Returns a new instance of JVMGCLog.



4
5
6
# File 'lib/jvm_gclog.rb', line 4

def initialize
  @regexp_prefix = Regexp.compile('^(?<time>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d+\+\d{4}): (?<uptime>\d+\.\d*): ')
end

Instance Method Details

#adjust_type(value) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/jvm_gclog.rb', line 8

def adjust_type(value)
  if value =~ /^\d+\.\d+$/
    return value.to_f
  elsif value =~ /^\d+$/
    return value.to_i
  end
  value
end

#match_fields_to_hash(m) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jvm_gclog.rb', line 17

def match_fields_to_hash(m)
  record = {}
  if m == nil
    return nil
  else
    m.names.each {|name|
      record[name] = adjust_type(m[name])
    }    
  end
  record
end

#parse(data) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/jvm_gclog.rb', line 61

def parse(data)
  if data.class == String
    data = [data]
  end
  record = {}
  m = @regexp_prefix.match(data[0])
  body = $'
  unless m
    record["type"] = "Unknown"
    record["unknown"] = data.join(" ")
    return record
  end

  record["time"] = Time.parse(m[:time]).to_i
  record["uptime"] = adjust_type(m["uptime"])

  case body
  when /^\[GC pause/
    line = data.join(" ")
    fields = [
      /\[GC Worker Total \(ms\):  (?<gctime_total>\d+\.\d+)/,
      /\[Eden: (?<eden_before>\d+\.\d+.)\((?<eden_total_before>\d+\.\d+.)\)->(?<eden_after>\d+\.\d+.)\((?<eden_total_after>\d+\.\d+.)\) Survivors: (?<survivors_before>\d+\.\d+.)->(?<survivors_after>\d+\.\d+.) Heap: (?<heap_before>\d+\.\d+.)\((?<heap_total_before>\d+\.\d+.)\)->(?<heap_after>\d+\.\d+.)\((?<heap_total_after>\d+\.\d+.)\)\]/,
      /\[Times: user=(?<gctime_user>[\d\.]+) sys=(?<gctime_sys>[\d\.]+), real=(?<gctime_real>[\d\.]+) secs\]/
    ]
    fields.each { |f|
      if fields_match = f.match(line)
        fields_match.names.each {|name|
          record[name] = adjust_type(fields_match[name])
        }
      end
    }
    record["type"] = "G1GC"
    return record

  when /^Total time for which application threads were stopped/
    # ignore this kind of line.
    return nil

  when /^\[GC.+ParNew: (?<new_before>\d+)K-\>(?<new_after>\d+)K\((?<new_total>\d+)K\), (?<new_gctime>[\d\.]+) secs\] (?<heap_before>\d+)K\-\>(?<heap_after>\d+)K\((?<heap_total>\d+)K\)( icms_dc=(?<icms_dc>\d+) )?, (?<gctime>[\d\.]+) secs\]/
    m = Regexp.last_match
    record.update(match_fields_to_hash(m))
    record["type"] = "YoungGC"

  when /^\[GC \[PSYoungGen: (?<new_before>\d+)K-\>(?<new_after>\d+)K\((?<new_total>\d+)K\)\] (?<heap_before>\d+)K\-\>(?<heap_after>\d+)K\((?<heap_total>\d+)K\), (?<gctime>[\d\.]+) secs\]/
    m = Regexp.last_match
    record.update(match_fields_to_hash(m))
    record["type"] = "YoungGC"
    
  when /^\[GC \[1 CMS-initial-mark: (?<old_before>\d+)K\((?<old_threshold>\d+)K\)\] (?<heap_before>\d+)K\((?<heap_total>\d+)K\), (?<gctime>[\d\.]+) secs\]/
    m = Regexp.last_match
    record.update(match_fields_to_hash(m))
    record["type"] = "CMS-initial-mark"

  when /^\[GC\[YG occupancy: (?<new_before>\d+) K \((?<new_threshold>\d+) K\)\].+\[1 CMS-remark: (?<old_before>\d+)K\((?<old_threshold>\d+)K\)\] (?<heap_before>\d+)K\((?<heap_total>\d+)K\), (?<gctime>[\d\.]+) secs\]/
    m = Regexp.last_match
    record.update(match_fields_to_hash(m))
    record["type"] = "CMS-parallel-remark"

  when /\[Full GC.+\(concurrent mode failure\).+ (?<gctime>[\d\.]+) secs\]/
    m = Regexp.last_match
    record.update(match_fields_to_hash(m))
    record["type"] = "FullGC-CMS-failure"

  when /\[Full GC.+ (?<gctime>[\d\.]+) secs\]/
    m = Regexp.last_match
    record.update(match_fields_to_hash(m))
    record["type"] = "FullGC"

  when /^\[(?<type>[A-Za-z\-]+)(: (?<time_cpu>[\d\.]+)\/(?<time_wall>[\d\.]+) secs)?\]/
    m = Regexp.last_match
    record.update(match_fields_to_hash(m))

  else
    record["type"] = "Unknown"
    record["unknown"] = body
  end

  if m = $'.match('\[Times: user=(?<gctime_user>[\d\.]+) sys=(?<gctime_sys>[\d\.]+), real=(?<gctime_real>[\d\.]+) secs\]')
    record.update(match_fields_to_hash(m))
  end

  return record
end

#parse_chunks(chunks) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/jvm_gclog.rb', line 53

def parse_chunks(chunks)
  res = []
  while (chunk = chunks.shift) != nil
    res.push parse(chunk)
  end
  res.compact
end

#recognize_chunks(lines) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jvm_gclog.rb', line 29

def recognize_chunks(lines)
  chunks = []

  line = lines.shift
  while line
    chunk = []

    if line != nil && @regexp_prefix.match(line)
      chunk << line.strip
      line = lines.shift
    end

    details = []
    while line != nil && !@regexp_prefix.match(line)
      chunk << line.strip
      line = lines.shift
    end

    chunks << chunk
  end

  chunks
end