Skip to content

Instantly share code, notes, and snippets.

@johntdyer
Last active August 29, 2015 14:21
Show Gist options
  • Save johntdyer/d5f6f19e96e68dddbe91 to your computer and use it in GitHub Desktop.
Save johntdyer/d5f6f19e96e68dddbe91 to your computer and use it in GitHub Desktop.
Heka LPEG grammar to parse JVM GC Log ( http://lpeg.trink.com/share/2229225886834348027 )
Benchmark
samples: 10000
seconds per match: 7.084e-06
max memory (bytes): 220474
max Lua instructions: 1188
2015-04-23T14:21:31.891+0000: 241151.284: [Full GC 3461M->1984M(5120M), 16.4529350 secs]
2015-04-23T19:06:50.286+0000: 258269.679: [Full GC 3026M->576M(5120M), 10.6780340 secs]
2015-04-23T19:47:44.878+0000: 260724.271: [Full GC 3481M->1974M(5120M), 16.1043050 secs]
2015-04-23T23:28:58.881+0000: 273998.274: [Full GC 4410M->1636M(5120M), 17.5298570 secs]
2015-04-24T16:51:40.994+0000: 336560.387: [Full GC 3193M->982M(5120M), 12.3815300 secs]
local dt = require "date_time"
local l = require 'lpeg'
l.locale(l)
local colon = l.P(":")
local period = l.P(".")
local m = l.P("M")
local gc_prefix = l.P("[Full GC") * l.space
local gc_suffix = l.space * l.P("secs]")
local timestamp = l.Cg(dt.build_strftime_grammar("%Y-%m-%dT%H:%M:%S.%s") / dt.time_to_ns, "Timestamp")
local jvm_seconds = l.Cg((l.R"09"^1 * l.P(".") * l.R("09")^1) / tonumber, "GCPause")
local heap_before = l.Cg((l.R"09"^1 / tonumber), "HeapBefore")
local heap_after = l.Cg((l.R"09"^1 / tonumber), "HeapAfter")
local heap_total = l.Cg((l.R"09"^1 / tonumber), "HeapTotal")
local cs = colon * l.space
-- 2015-04-24T16:51:40.994: 336560.234: [Full GC 3193M->982M(5120M), 12.3815300 secs]
local gc_pattern = timestamp * cs * jvm_seconds * cs * gc_prefix * heap_before * m * "->" * heap_after * m * "(" * heap_total * m * ")," * l.space * jvm_seconds * gc_suffix
grammar = l.Ct(gc_pattern)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment