forked from chewiebug/GCViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pull/chewiebug#196/golang' into develop
- Loading branch information
Showing
9 changed files
with
802 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/main/java/com/tagtraum/perf/gcviewer/imp/DataReaderGo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.tagtraum.perf.gcviewer.imp; | ||
|
||
import com.tagtraum.perf.gcviewer.model.AbstractGCEvent; | ||
import com.tagtraum.perf.gcviewer.model.GCEvent; | ||
import com.tagtraum.perf.gcviewer.model.GCModel; | ||
import com.tagtraum.perf.gcviewer.model.GCResource; | ||
import com.tagtraum.perf.gcviewer.util.ParseInformation; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.LineNumberReader; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.logging.Level; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Parses GC log output from Go 1.9. | ||
* | ||
* @author <a href="mailto:[email protected]">Roland Illig</a> | ||
* @see <a href="https://golang.org/pkg/runtime/#hdr-Environment_Variables">Go documentation</a> | ||
*/ | ||
public class DataReaderGo extends AbstractDataReader { | ||
|
||
private static final Pattern GCLINE = Pattern.compile("" | ||
+ "gc " | ||
+ "(\\d+) " | ||
+ "@(\\d+\\.\\d+)s " | ||
+ "(\\d+)%: " | ||
+ "(\\d+(?:\\.\\d+)?)\\+" | ||
+ "(\\d+(?:\\.\\d+)?)\\+" | ||
+ "(\\d+(?:\\.\\d+)?) ms clock, " | ||
+ "(\\d+(?:\\.\\d+)?)\\+" | ||
+ "(\\d+(?:\\.\\d+)?)/" | ||
+ "(\\d+(?:\\.\\d+)?)/" | ||
+ "(\\d+(?:\\.\\d+)?)\\+" | ||
+ "(\\d+(?:\\.\\d+)?) ms cpu, " | ||
+ "(\\d+)->" | ||
+ "(\\d+)->" | ||
+ "(\\d+) MB, " | ||
+ "(\\d+) MB goal, " | ||
+ "(\\d+) P"); | ||
|
||
public DataReaderGo(GCResource gcResource, InputStream in) throws UnsupportedEncodingException { | ||
super(gcResource, in); | ||
} | ||
|
||
public GCModel read() throws IOException { | ||
if (getLogger().isLoggable(Level.INFO)) getLogger().info("Reading Go format..."); | ||
|
||
try (LineNumberReader in = this.in) { | ||
GCModel model = new GCModel(); | ||
model.setFormat(GCModel.Format.GO); | ||
ParseInformation parsePosition = new ParseInformation(0); | ||
|
||
Matcher matcher = GCLINE.matcher(""); | ||
String line; | ||
while ((line = in.readLine()) != null && shouldContinue()) { | ||
parsePosition.setIndex(0); | ||
parsePosition.setLineNumber(in.getLineNumber()); | ||
if (!matcher.reset(line).matches()) { | ||
continue; | ||
} | ||
|
||
try { | ||
AbstractGCEvent<?> gcEvent = parseMatch(matcher); | ||
model.add(gcEvent); | ||
} catch (Exception pe) { | ||
if (getLogger().isLoggable(Level.WARNING)) getLogger().warning(pe.toString()); | ||
if (getLogger().isLoggable(Level.FINE)) getLogger().log(Level.FINE, pe.getMessage(), pe); | ||
} | ||
} | ||
return model; | ||
} finally { | ||
if (getLogger().isLoggable(Level.INFO)) getLogger().info("Done reading."); | ||
} | ||
} | ||
|
||
private AbstractGCEvent<?> parseMatch(Matcher matcher) { | ||
double relativeTime = Double.parseDouble(matcher.group(2)); | ||
double stopTheWorld1Time = Double.parseDouble(matcher.group(4)) / 1000.0; | ||
double stopTheWorld2Time = Double.parseDouble(matcher.group(6)) / 1000.0; | ||
int preUsed = Integer.parseInt(matcher.group(12)) * 1024; | ||
int alive = Integer.parseInt(matcher.group(13)) * 1024; | ||
int postUsed = Integer.parseInt(matcher.group(14)) * 1024; | ||
|
||
double pause = stopTheWorld1Time + stopTheWorld2Time; | ||
return new GCEvent(relativeTime, preUsed, postUsed, alive, pause, AbstractGCEvent.Type.GC); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/test/java/com/tagtraum/perf/gcviewer/imp/TestDataReaderGo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.tagtraum.perf.gcviewer.imp; | ||
|
||
import static org.hamcrest.Matchers.closeTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.logging.Level; | ||
|
||
import com.tagtraum.perf.gcviewer.UnittestHelper; | ||
import com.tagtraum.perf.gcviewer.model.AbstractGCEvent; | ||
import com.tagtraum.perf.gcviewer.model.GCModel; | ||
import com.tagtraum.perf.gcviewer.model.GCResource; | ||
import com.tagtraum.perf.gcviewer.model.GcResourceFile; | ||
import org.junit.Test; | ||
|
||
public class TestDataReaderGo { | ||
|
||
@Test | ||
public void test() throws IOException { | ||
TestLogHandler handler = new TestLogHandler(); | ||
handler.setLevel(Level.WARNING); | ||
GCResource gcResource = new GcResourceFile("byteArray"); | ||
gcResource.getLogger().addHandler(handler); | ||
|
||
String gcLog = "" | ||
+ "gc starting...\n" // Such a line is not produced by the Go GC; it is just for testing | ||
+ "gc 1 @0.058s 0%: 0+1.9+0 ms clock, 0+0.94/1.9/2.9+0 ms cpu, 4->5->1 MB, 5 MB goal, 4 P\n" | ||
+ "a line unrelated to GC logging\n" | ||
+ "gc 2 @0.073s 3%: 68+0.36+0.51 ms clock, 205+0/16/89+1.5 ms cpu, 11111111111111111111111111111111111->84->42 MB, 86 MB goal, 3 P\n" | ||
+ "gc 58 @17.837s 0%: 0.48+17+0 ms clock, 1.9+9.3/7.9/15+0 ms cpu, 30->30->15 MB, 31 MB goal, 4 P\n"; | ||
ByteArrayInputStream in = new ByteArrayInputStream(gcLog.getBytes("US-ASCII")); | ||
DataReader reader = new DataReaderGo(gcResource, in); | ||
GCModel model = reader.read(); | ||
|
||
assertThat("gc 2 -> warning", handler.getCount(), is(1)); | ||
assertThat("size", model.size(), is(2)); | ||
|
||
AbstractGCEvent<?> event1 = model.get(0); | ||
assertThat("timestamp", event1.getTimestamp(), closeTo(0.058, 0.0001)); | ||
assertThat("pause", event1.getPause(), closeTo(0 + 0, 0.1)); | ||
assertThat("preused", event1.getPreUsed(), is(4096)); | ||
assertThat("postused", event1.getPostUsed(), is(1024)); | ||
assertThat("heap", event1.getTotal(), is(5120)); | ||
} | ||
|
||
@Test | ||
public void exampleLog() throws IOException { | ||
TestLogHandler handler = new TestLogHandler(); | ||
handler.setLevel(Level.WARNING); | ||
GCResource gcResource = new GcResourceFile("go1.9.txt"); | ||
gcResource.getLogger().addHandler(handler); | ||
|
||
InputStream in = UnittestHelper.getResourceAsStream(UnittestHelper.FOLDER.GO, gcResource.getResourceName()); | ||
DataReader reader = new DataReaderGo(gcResource, in); | ||
GCModel model = reader.read(); | ||
|
||
assertThat("warnings", handler.getCount(), is(0)); | ||
assertThat("size", model.size(), is(635)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.