Skip to content

Commit

Permalink
Capture elapsed time from the GC output
Browse files Browse the repository at this point in the history
  • Loading branch information
kouno committed Oct 23, 2015
1 parent c47b141 commit 4a11124
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
51 changes: 32 additions & 19 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

const (
GCRegexpGo14 = `gc\d+\(\d+\): ([\d.]+\+?)+ us, \d+ -> (?P<Heap1>\d+) MB, \d+ \(\d+-\d+\) objects,( \d+ goroutines,)? \d+\/\d+\/\d+ sweeps, \d+\(\d+\) handoff, \d+\(\d+\) steal, \d+\/\d+\/\d+ yields`
GCRegexpGo15 = `gc #?\d+ @[\d.]+s \d+%: [\d.+/]+ ms clock, [\d.+/]+ ms cpu, \d+->\d+->\d+ MB, (?P<Heap1>\d+) MB goal, \d+ P`
GCRegexpGo15 = `gc #?\d+ @(?P<ElapsedTime>[\d.]+)s \d+%: [\d.+/]+ ms clock, [\d.+/]+ ms cpu, \d+->\d+->\d+ MB, (?P<Heap1>\d+) MB goal, \d+ P`
SCVGRegexp = `scvg\d+: inuse: (?P<inuse>\d+), idle: (?P<idle>\d+), sys: (?P<sys>\d+), released: (?P<released>\d+), consumed: (?P<consumed>\d+) \(MB\)`
)

Expand Down Expand Up @@ -74,39 +74,52 @@ func parseGCTrace(gcre *regexp.Regexp, matches []string) *gctrace {
matchMap := getMatchMap(gcre, matches)

return &gctrace{
Heap1: matchMap["Heap1"],
Heap1: silentParseInt(matchMap["Heap1"]),
ElapsedTime: silentParseFloat(matchMap["ElapsedTime"]),
}
}

func parseSCVGTrace(matches []string) *scvgtrace {
matchMap := getMatchMap(scvgre, matches)

return &scvgtrace{
inuse: matchMap["inuse"],
idle: matchMap["idle"],
sys: matchMap["sys"],
released: matchMap["released"],
consumed: matchMap["consumed"],
inuse: silentParseInt(matchMap["inuse"]),
idle: silentParseInt(matchMap["idle"]),
sys: silentParseInt(matchMap["sys"]),
released: silentParseInt(matchMap["released"]),
consumed: silentParseInt(matchMap["consumed"]),
}
}

// Transform our matches in a readable hash map.
//
// The resulting hash map will be something like { "Heap1": 123 }
func getMatchMap(re *regexp.Regexp, matches []string) map[string]int64 {
matchingNames := re.SubexpNames()
matchMap := map[string]int64{}
for i, value := range matches {
intVal, err := strconv.ParseInt(value, 10, 64)
if err != nil {
// Happens on first element of range and any matching parenthesis
// that includes non-parseable string
//
// For example a matching array would contain:
// [ "scvg1: inuse:3 ..." "3" ]
func getMatchMap(re *regexp.Regexp, matches []string) map[string]string {
matchingNames := re.SubexpNames()[1:]
matchMap := map[string]string{}
for i, value := range matches[1:] {
if matchingNames[i] == "" {
continue
}
matchMap[matchingNames[i]] = intVal
matchMap[matchingNames[i]] = value
}
return matchMap
}

func silentParseInt(value string) int64 {
intVal, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return 0
}

return intVal
}

func silentParseFloat(value string) float32 {
floatVal, err := strconv.ParseFloat(value, 32)
if err != nil {
return float32(0)
}

return float32(floatVal)
}
6 changes: 4 additions & 2 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func TestParserWithMatchingInputGo16(t *testing.T) {
runParserWith(line)

expectedGCTrace := &gctrace{
Heap1: 33,
Heap1: 33,
ElapsedTime: 3.243,
}

select {
Expand All @@ -41,7 +42,8 @@ func TestParserWithMatchingInputGo15(t *testing.T) {
runParserWith(line)

expectedGCTrace := &gctrace{
Heap1: 33,
Heap1: 33,
ElapsedTime: 3.243,
}

select {
Expand Down
1 change: 1 addition & 0 deletions tracedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type scvgtrace struct {
}

type gctrace struct {
ElapsedTime float32 // in seconds
NumGC int64
Nproc int64
t1 int64
Expand Down

0 comments on commit 4a11124

Please sign in to comment.