Skip to content

Commit

Permalink
support ZGC log
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuke committed Sep 25, 2021
1 parent f90cb26 commit 1ca2d9d
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class GCParser implements LineGraphDataSourceParser {
private final LineGraphDataSourceParser[] gcParsers = new LineGraphDataSourceParser[]{new BEAGCParser(),
new SunGCParser(), new IBMGCParser(), new OpenJDKGCParser()};
new SunGCParser(), new IBMGCParser(), new OpenJDKGCParser(), new OpenJDKZGCParser()};
private LineGraphDataSourceParser finalParser = null;

public GCParser() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public boolean parse(String line, LineGraphRenderer renderer) {
if (line.contains("[gc] GC(")) {
try {
int pauseIndex = line.indexOf(") Pause ");
if (pauseIndex == -1) {
return false;
}
int beforeEnd = line.indexOf("M->");
if (beforeEnd == -1) {
return false;
Expand All @@ -55,7 +58,7 @@ public boolean parse(String line, LineGraphRenderer renderer) {
break;
}
}
if (beforeStart == 1) {
if (beforeStart == -1) {
return false;
}
int afterStart = beforeEnd + 3;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2003-2012 Yusuke Yamamoto
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package one.cafebabe.samurai.gc;

import one.cafebabe.samurai.util.GUIResourceBundle;
import one.cafebabe.samurai.util.LineGraphDataSourceParser;

import java.awt.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* supports OpenJDK ZGC log
*/
public class OpenJDKZGCParser implements LineGraphDataSourceParser {
public OpenJDKZGCParser() {
}

private static final GUIResourceBundle resources = GUIResourceBundle.getInstance();
private LineGraph lineGraph = null;
private int memoryMax = 0;

// [1.190s][info][gc] GC(0) Garbage Collection (Warmup) 14M(11%)->6M(5%)
private final static Pattern pattern = Pattern.compile("([0-9]+)M\\(([0-9]+)%\\)->([0-9]+)M\\(([0-9]+)%\\)");

/**
* parse
*
* @param line String
* @return boolean
*/
public boolean parse(String line, LineGraphRenderer renderer) {
int gcIndex = line.indexOf(") Garbage Collection (");
if (gcIndex != -1) {
try {
Matcher matcher = pattern.matcher(line);
if (!matcher.find() || matcher.groupCount() != 4) {
return false;
}

int memoryBefore = Integer.parseInt(matcher.group(1));
int memoryAfter = Integer.parseInt(matcher.group(3));
int percentageBefore = Integer.parseInt(matcher.group(2));

int currentMemoryMax = memoryBefore * 100 / percentageBefore;
if (null == lineGraph) {
lineGraph = renderer.addLineGraph(resources.getMessage("GraphPanel.memory"), new String[]{
resources.getMessage("GraphPanel.memoryBeforeGC"),
resources.getMessage("GraphPanel.memoryAfterGC")});
lineGraph.setColorAt(0, Color.RED);
lineGraph.setColorAt(1, Color.YELLOW);
}
try {
if (memoryMax < currentMemoryMax) {
memoryMax = currentMemoryMax;
lineGraph.setYMax(0, memoryMax);
lineGraph.setYMax(1, memoryMax);
}
lineGraph.addValues(new double[]{memoryBefore, memoryAfter});
return true;
} catch (NumberFormatException wasNotGC) {
// wasNotGC.printStackTrace();
//does nothing
}
} catch (StringIndexOutOfBoundsException sioobe) {
// System.err.println("unexpected format:" + line);
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
AboutSamuraiDialog.copyright=Copyright (c) 2003-2021 Yusuke Yamamoto
AboutSamuraiDialog.version=Samurai 2021.5(build 2021/9/24)
AboutSamuraiDialog.version=Samurai 2021.6(build 2021/9/25)
AboutSamuraiDialog.title=About Samurai
AboutSamuraiDialog.releaseNote=<html><body><pre>This software is powered by open-source software.\n\
<a href="https://www.thymeleaf.org">Thymeleaf</a> - <a href="https://www.apache.org/licenses/LICENSE-2.0.html">Apache 2.0</a?\n\
<a href="https://bell-sw.com/pages/libericajdk/">Liberica JDK</a> - <a href="https://github.com/bell-sw/Liberica/blob/master/LICENSE">GNU General Public License, version 2, with the Classpath Exception</a>\n\
\n\
Release note\n\
2021/9/25(Version2021.6)\n\
- support OpenJDK ZGC log format\n\
- support OpenJDK G1GC log format\n\
- support OpenJDK parallel GC log format\n\
2021/9/24(Version2021.5)\n\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ AboutSamuraiDialog.releaseNote=<html><body><pre>This software is powered by open
\n\
\u30EA\u30EA\u30FC\u30B9\u30CE\u30FC\u30C8\n\
2021/9/25(Version2021.6)\n\
\u30FBOpenJDK ZGC\u30ED\u30B0\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8\u3092\u30B5\u30DD\u30FC\u30C8\n\
\u30FBOpenJDK G1GC\u30ED\u30B0\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8\u3092\u30B5\u30DD\u30FC\u30C8\n\
\u30FBOpenJDK parallel GC\u30ED\u30B0\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8\u3092\u30B5\u30DD\u30FC\u30C8\n\
2021/9/24(Version2021.5)\n\
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2021 Yusuke Yamamoto
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package one.cafebabe.samurai.gc;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static org.junit.jupiter.api.Assertions.assertEquals;

@SuppressWarnings("ConstantConditions")
@Execution(ExecutionMode.CONCURRENT)
class TestOpenJDKZGCParser extends AbstractGraphTest {

@Test
void zgc() throws IOException {
OpenJDKZGCParser parser = new OpenJDKZGCParser();

try (var br = new BufferedReader(
new InputStreamReader(
TestOpenJDKZGCParser.class.
getResourceAsStream("/one/cafebabe/samurai/gc/jdk17-verbosegc-ZGC.log")))) {
parser.parse(br.readLine(), this);
parser.parse(br.readLine(), this);
//[1.190s][info][gc] GC(0) Garbage Collection (Warmup) 14M(11%)->6M(5%)
expected.add(new double[]{
14d, 6d
});
expectedMax.add(127d);
expectedMax.add(127d);
parser.parse(br.readLine(), this);
//[2.816s][info][gc] GC(1) Garbage Collection (Warmup) 28M(22%)->28M(22%)
expected.add(new double[]{
28d, 28d
});
parser.parse(br.readLine(), this);
parser.parse(br.readLine(), this);
parser.parse(br.readLine(), this);
parser.parse(br.readLine(), this);

assertEquals(2, count);

}
}


}

0 comments on commit 1ca2d9d

Please sign in to comment.