Skip to content

Instantly share code, notes, and snippets.

@first-developer
Last active August 29, 2015 14:22
Show Gist options
  • Save first-developer/8b42067c4db824769263 to your computer and use it in GitHub Desktop.
Save first-developer/8b42067c4db824769263 to your computer and use it in GitHub Desktop.
go script to parse JVM GC log
// jummy project main.go
package main
import (
"fmt"
"regexp"
"time"
)
const (
sizeOfLiveObjectsBeforeMinorGC = iota
sizeOfLiveObjectsAfterMinorGC
)
type value struct {
Val int64
Unit rune
}
type YoungGenCollectorData struct {
timestamp time.Duration
YoungGenSizeBeforeGC value
YoungGenSizeAfterGC value
YoungGenTotalSize value
HeapSizeBeforeGC value
HeapSizeAfterGC value
HeapTotalSize value
GCelapsedTime time.Duration
}
const (
youngGenEventPattern string = `([\d\.]+):\s*\[GC\s*\[PSYoungGen:\s*(\d+)(\w)->(\d+)(\w)\((\d+)(\w)\)\]\s*(\d+)(\w)->(\d+)(\w)\((\d+)(\w)\),\s*([\d\.]+).*`
)
var GCeventLog string = "46299.040: [GC [PSYoungGen: 628585K->86124K(788928K)] 1534686K->1004395K(1903040K), 0.0733620 secs] [Times: user=0.79 sys=0.00, real=0.07 secs]"
func main() {
r := regexp.MustCompile(youngGenEventPattern)
event := r.FindAllStringSubmatch(GCeventLog, -1)
fmt.Printf("%#v", event[0][1:])
}
` Test sample
46299.040: [GC [PSYoungGen: 628585K->86124K(788928K)] 1534686K->1004395K(1903040K), 0.0733620 secs] [Times: user=0.79 sys=0.00, real=0.07 secs]
46327.854: [GC [PSYoungGen: 671852K->96259K(779840K)] 1590123K->1032063K(1893952K), 0.0858220 secs] [Times: user=0.91 sys=0.00, real=0.09 secs]
46352.932: [GC [PSYoungGen: 681987K->104066K(803968K)] 1617791K->1058002K(1918080K), 0.1056060 secs] [Times: user=1.04 sys=0.00, real=0.11 secs]
46389.392: [GC [PSYoungGen: 723330K->102342K(798336K)] 1677266K->1075490K(1912448K), 0.0924620 secs] [Times: user=0.88 sys=0.00, real=0.10 secs]
46419.528: [GC [PSYoungGen: 721606K->108764K(813120K)] 1694754K->1104663K(1927232K), 0.0990010 secs] [Times: user=1.05 sys=0.00, real=0.10 secs]
46451.616: [GC [PSYoungGen: 748764K->112174K(809920K)] 1744663K->1134777K(1924032K), 0.1026450 secs] [Times: user=1.10 sys=0.01, real=0.09 secs]
46478.835: [GC [PSYoungGen: 752174K->107753K(818752K)] 1774777K->1148178K(1932864K), 0.0919570 secs] [Times: user=1.03 sys=0.00, real=0.10 secs]
46512.148: [GC [PSYoungGen: 758441K->102671K(814976K)] 1798866K->1166273K(1929088K), 0.1009660 secs] [Times: user=0.95 sys=0.00, real=0.10 secs]
46548.572: [GC [PSYoungGen: 753359K->125169K(817536K)] 1816961K->1188771K(1931648K), 0.1160990 secs] [Times: user=0.96 sys=0.01, real=0.12 secs]
46584.673: [GC [PSYoungGen: 783857K->140904K(799616K)] 1847459K->1204506K(1913728K), 0.1204390 secs] [Times: user=1.23 sys=0.00, real=0.12 secs]
46617.448: [GC [PSYoungGen: 799592K->166551K(781120K)] 1863194K->1230152K(1895232K), 0.1160800 secs] [Times: user=1.15 sys=0.00, real=0.12 secs]
46653.345: [GC [PSYoungGen: 777367K->159819K(751424K)] 1840968K->1252167K(1865536K), 0.1507370 secs] [Times: user=1.46 sys=0.00, real=0.15 secs]
46679.178: [GC [PSYoungGen: 591552K->39300K(776064K)] 1367028K->814777K(1890176K), 0.0375830 secs] [Times: user=0.29 sys=0.00, real=0.04 secs]
46707.416: [GC [PSYoungGen: 619122K->56754K(781440K)] 1394599K->832231K(1895552K), 0.0472550 secs] [Times: user=0.48 sys=0.00, real=0.04 secs]
46737.704: [GC [PSYoungGen: 636594K->84020K(787904K)] 1412071K->859497K(1902016K), 0.0664290 secs] [Times: user=0.74 sys=0.00, real=0.07 secs]
46762.449: [GC [PSYoungGen: 670516K->102435K(781632K)] 1445993K->877912K(1895744K), 0.0814320 secs] [Times: user=0.84 sys=0.01, real=0.07 secs]
46794.578: [GC [PSYoungGen: 688931K->124236K(797376K)] 1464408K->899713K(1911488K), 0.0965700 secs] [Times: user=1.01 sys=0.00, real=0.09 secs]
46826.836: [GC [PSYoungGen: 735692K->148014K(759488K)] 1511169K->923491K(1873600K), 0.1084820 secs] [Times: user=1.17 sys=0.00, real=0.10 secs]
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment