Skip to content

Commit

Permalink
Issue #209: parse jvm_args in unified header.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgm3746 committed Nov 26, 2024
1 parent b5722ed commit bd97d7b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,26 @@
public class UnifiedHeaderEvent implements LogEvent, UnifiedLogging {

/**
* Regular expressions defining the garbage collector information.
* Regular expression for garbage collector information.
*/
private static final String __REGEX_GARBAGE_COLLECTOR = "Using (Concurrent Mark Sweep|G1|Parallel|Serial|"
+ "Shenandoah|The Z Garbage Collector)";

/**
* Regular expressions defining JDK version information.
* Regular expression for JDK version information.
*/
private static final String __REGEX_VERSION = "Version: " + UnifiedRegEx.RELEASE_STRING + " \\(release\\)";

/**
* Regular expression for jvm_args information.
*/
private static final String __REGEX_JVM_ARGS = "jvm_args:[ ]{0,1}(.*)";

/**
* Regular expressions defining the logging.
*/
private static final String _REGEX = "^" + UnifiedRegEx.DECORATOR + " (" + __REGEX_GARBAGE_COLLECTOR + "|"
+ __REGEX_VERSION
+ __REGEX_VERSION + "|" + __REGEX_JVM_ARGS
+ "| - (commit_granule_bytes|commit_granule_words|enlarge_chunks_in_place|use_allocation_guard|"
+ "virtual_space_node_default_size)|Activate regions|Address Space (Size|Type)|Alignments|"
+ "Available space on backing filesystem|(Initial|Max|Min) Capacity|CardTable entry size|"
Expand All @@ -195,7 +200,7 @@ public class UnifiedHeaderEvent implements LogEvent, UnifiedLogging {
+ "Heap Backing Filesystem|Heap Backing File|Heap [Rr]egion (Count|[Ss]ize)|Heuristics|"
+ "Heuristics ergonomically sets |Humongous [oO]bject [tT]hreshold|Initialize mark stack|"
+ "Initial Refinement Zones|Initialize Shenandoah heap|Initializing The Z Garbage Collector|"
+ "java_class_path \\(initial\\)|java_command|jvm_args|Large Page Support|Launcher Type|"
+ "java_class_path \\(initial\\)|java_command|Large Page Support|Launcher Type|"
+ "Mark (closed|open) archive regions in map|Max TLAB size|Medium Page Size|Memory|Mode|"
+ "Min heap equals to max heap, disabling ShenandoahUncommit|Minimum heap|Narrow klass base|NUMA Nodes|"
+ "NUMA Support|Pacer for Idle|ParallelGCThreads|Parallel Workers|Periodic GC|Pre-touch|"
Expand Down Expand Up @@ -348,6 +353,18 @@ public int getJdkVersionMinor() {
return jdkVersionMinor;
}

/**
* @return The jvm_args string.
*/
public String getJvmArgs() {
String jvmArgs = null;
Matcher matcher = PATTERN.matcher(logEntry);
if (matcher.find()) {
jvmArgs = matcher.group(UnifiedRegEx.DECORATOR_SIZE + 8);
}
return jvmArgs;
}

public String getLogEntry() {
return logEntry;
}
Expand Down Expand Up @@ -384,6 +401,20 @@ public boolean isGarbageCollector() {
return isGarbageCollector;
}

/**
* @return true if the header contains jvm_args information, false otherwise.
*/
public boolean isJvmArgs() {
boolean isJvmArgs = false;
Matcher matcher = PATTERN.matcher(logEntry);
if (matcher.matches()) {
if (matcher.group(UnifiedRegEx.DECORATOR_SIZE + 1) != null) {
isJvmArgs = matcher.group(UnifiedRegEx.DECORATOR_SIZE + 1).matches(__REGEX_JVM_ARGS);
}
}
return isJvmArgs;
}

/**
* @return true if the header contains JDK version information, false otherwise.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,8 @@ public void store(List<String> logLines, boolean reorder) {
jvmDao.setVmInfo(((UnifiedHeaderEvent) event).getJdkReleaseString());
} else if (((UnifiedHeaderEvent) event).isGarbageCollector()) {
collectorFamily = ((UnifiedHeaderEvent) event).getCollectorFamily();
} else if (((UnifiedHeaderEvent) event).isJvmArgs()) {
jvmDao.getJvmContext().setOptions((((UnifiedHeaderEvent) event).getJvmArgs()));
}
if (event.getLogEntry().matches(
"^" + UnifiedRegEx.DECORATOR + " Min heap equals to max heap, disabling ShenandoahUncommit$")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
*/
class TestOomeMetaspaceEvent {

@Test
void testBlankLine() {
LogEvent priorLogEvent = new OomeMetaspaceEvent(null);
String logLine = "[2022-02-08T07:33:14.540+0000][7732788ms]";
assertEquals(JdkUtil.LogEventType.OOME_METASPACE,
JdkUtil.identifyEventType(logLine, priorLogEvent, CollectorFamily.UNKNOWN),
JdkUtil.LogEventType.OOME_METASPACE + "not identified.");
}

@Test
void testClassAllocation() {
String logLine = "[2024-05-06T13:01:18.988+0300][3619401490ms] Metaspace (class) allocation failed for size "
Expand Down Expand Up @@ -110,15 +119,6 @@ void testMetaspaceReclaimPolicy() {
JdkUtil.LogEventType.OOME_METASPACE + "not identified.");
}

@Test
void testBlankLine() {
LogEvent priorLogEvent = new OomeMetaspaceEvent(null);
String logLine = "[2022-02-08T07:33:14.540+0000][7732788ms]";
assertEquals(JdkUtil.LogEventType.OOME_METASPACE,
JdkUtil.identifyEventType(logLine, priorLogEvent, CollectorFamily.UNKNOWN),
JdkUtil.LogEventType.OOME_METASPACE + "not identified.");
}

@Test
void testParseLogLine() {
String logLine = "[2022-02-08T07:33:14.540+0000][7732788ms] Metaspace (data) allocation failed for size 11";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,13 +588,16 @@ void testJavaCommand() {
@Test
void testJvmArgs() {
UnifiedHeaderEvent priorLogEvent = new UnifiedHeaderEvent("");
String logLine = "[0.005s][info][arguments] jvm_args: -Djava.awt.headless=true";
String logLine = "[0.005s][info][arguments] jvm_args: -Xmx1g";
assertEquals(JdkUtil.LogEventType.UNIFIED_HEADER,
JdkUtil.identifyEventType(logLine, priorLogEvent, CollectorFamily.UNKNOWN),
JdkUtil.LogEventType.UNIFIED_HEADER + " not identified.");
assertNotEquals(JdkUtil.LogEventType.GC_INFO,
JdkUtil.identifyEventType(logLine, priorLogEvent, CollectorFamily.UNKNOWN),
JdkUtil.LogEventType.GC_INFO + " not identified.");
UnifiedHeaderEvent event = new UnifiedHeaderEvent(logLine);
assertTrue(event.isJvmArgs(), "jvm_args information not identified.");
assertEquals("-Xmx1g", event.getJvmArgs(), "jvm_args not correct.");
}

@Test
Expand All @@ -620,7 +623,7 @@ void testLauncherType() {
JdkUtil.identifyEventType(logLine, priorLogEvent, CollectorFamily.UNKNOWN),
JdkUtil.LogEventType.GC_INFO + " not identified.");
}

@Test
void testLineWithSpaces() {
UnifiedHeaderEvent priorLogEvent = new UnifiedHeaderEvent("");
Expand All @@ -631,6 +634,7 @@ void testLineWithSpaces() {
JdkUtil.identifyEventType(logLine, priorLogEvent, CollectorFamily.UNKNOWN),
JdkUtil.LogEventType.GC_INFO + " not identified.");
}

@Test
void testLogLine() {
UnifiedHeaderEvent priorLogEvent = new UnifiedHeaderEvent("");
Expand All @@ -643,6 +647,7 @@ void testLogLine() {
JdkUtil.identifyEventType(logLine, priorLogEvent, CollectorFamily.UNKNOWN),
JdkUtil.LogEventType.GC_INFO + " not identified.");
}

@Test
void testMarkClosedArchiveRegionsInMap() {
UnifiedHeaderEvent priorLogEvent = new UnifiedHeaderEvent("");
Expand All @@ -654,6 +659,7 @@ void testMarkClosedArchiveRegionsInMap() {
JdkUtil.identifyEventType(logLine, priorLogEvent, CollectorFamily.UNKNOWN),
JdkUtil.LogEventType.GC_INFO + " not identified.");
}

@Test
void testMarkOpenArchiveRegionsInMap() {
UnifiedHeaderEvent priorLogEvent = new UnifiedHeaderEvent("");
Expand Down

0 comments on commit bd97d7b

Please sign in to comment.