-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
156 additions
and
3 deletions.
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
84 changes: 84 additions & 0 deletions
84
samurai-swing/src/main/java/one/cafebabe/samurai/gc/OpenJDKZGCParser.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,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; | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
samurai-swing/src/main/resources/one/cafebabe/samurai/swing/messages.properties
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
64 changes: 64 additions & 0 deletions
64
samurai-swing/src/test/java/one/cafebabe/samurai/gc/TestOpenJDKZGCParser.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,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); | ||
|
||
} | ||
} | ||
|
||
|
||
} |