Skip to content

Commit ec877d1

Browse files
committed
#194 improve detection of G1 gc logfiles
1 parent 7ec56ac commit ec877d1

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/main/java/com/tagtraum/perf/gcviewer/imp/DataReaderFactory.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private String getChunkOfLastLine(String currentTextBlock) {
108108

109109
private DataReader getDataReaderBySample(String s, GCResource gcResource, InputStream in) throws IOException {
110110
// if there is a [memory ] somewhere in the first chunk of the logs, it is JRockit
111-
if (s.indexOf("[memory ]") != -1) {
111+
if (s.contains("[memory ]")) {
112112
int startOfRealLog = s.lastIndexOf("<");
113113
// skip ahead of <start>-<end>: <type> <before>KB-><after>KB (<heap>KB
114114
String realLog;
@@ -123,7 +123,7 @@ private DataReader getDataReaderBySample(String s, GCResource gcResource, InputS
123123
return null; // No GC logs of format 1641728K->148365K (3145728K) yet, read next chunk
124124
}
125125
// JRockit 1.5 and 1.6 logs look like: [memory ][Tue Nov 13 08:39:01 2012][01684] [OC#1]
126-
if ((realLog.indexOf("[YC#") != -1) ||(realLog.indexOf("[OC#") != -1)) {
126+
if ((realLog.indexOf("[YC#") != -1) || (realLog.indexOf("[OC#") != -1)) {
127127
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: JRockit 1.6");
128128
return new DataReaderJRockit1_6_0(gcResource, in);
129129
}
@@ -139,15 +139,15 @@ else if ((realLog.indexOf("\n[memory") == -1) && (realLog.indexOf("[INFO ][memor
139139
return new DataReaderJRockit1_5_0(gcResource, in);
140140
}
141141
}
142-
else if (s.indexOf("since last AF or CON>") != -1) {
142+
else if (s.contains("since last AF or CON>")) {
143143
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: IBM 1.4.2");
144144
return new DataReaderIBM1_4_2(gcResource, in);
145145
}
146-
else if (s.indexOf("GC cycle started") != -1) {
146+
else if (s.contains("GC cycle started")) {
147147
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: IBM 1.3.1");
148148
return new DataReaderIBM1_3_1(gcResource, in);
149149
}
150-
else if (s.indexOf("<AF") != -1) {
150+
else if (s.contains("<AF")) {
151151
// this should be an IBM JDK < 1.3.0
152152
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: IBM <1.3.0");
153153
return new DataReaderIBM1_3_0(gcResource, in);
@@ -157,53 +157,53 @@ else if (s.contains("][gc")) {
157157
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: Oracle / OpenJDK unified jvm logging");
158158
return new DataReaderUnifiedJvmLogging(gcResource, in);
159159
}
160-
else if (s.indexOf(" (young)") > 0 || s.indexOf("G1Ergonomics") > 0) {
160+
else if (s.contains(" (young)") || s.contains("G1Ergonomics") || s.contains(" (mixed)")) {
161161
// G1 logger usually starts with "<timestamp>: [GC pause (young)...]"
162162
// but can start with <timestamp>: [G1Ergonomics (Heap Sizing) expand the heap...
163163
// with certain logging flaggs.
164164
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: Sun 1.6.x G1 collector");
165165
return new DataReaderSun1_6_0G1(gcResource, in, GcLogType.SUN1_6G1);
166166
}
167-
else if (s.indexOf("[Times:") > 0) {
167+
else if (s.contains("[Times:")) {
168168
// all 1.6 lines end with a block like this "[Times: user=1.13 sys=0.08, real=0.95 secs]"
169169
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: Sun 1.6.x");
170170
return new DataReaderSun1_6_0(gcResource, in, GcLogType.SUN1_6);
171171
}
172-
else if (s.indexOf("CMS-initial-mark") != -1 || s.indexOf("PSYoungGen") != -1) {
172+
else if (s.contains("CMS-initial-mark") || s.contains("PSYoungGen")) {
173173
// format is 1.5, but datareader for 1_6_0 can handle it
174174
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: Sun 1.5.x");
175175
return new DataReaderSun1_6_0(gcResource, in, GcLogType.SUN1_5);
176176
}
177-
else if (s.indexOf(": [GC") != -1) {
177+
else if (s.contains(": [GC")) {
178178
// format is 1.4, but datareader for 1_6_0 can handle it
179179
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: Sun 1.4.x");
180180
return new DataReaderSun1_6_0(gcResource, in, GcLogType.SUN1_4);
181181
}
182-
else if (s.indexOf("[GC") != -1 || s.indexOf("[Full GC") != -1 || s.indexOf("[Inc GC")!=-1) {
182+
else if (s.contains("[GC") || s.contains("[Full GC") || s.contains("[Inc GC")) {
183183
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: Sun 1.3.1");
184184
return new DataReaderSun1_3_1(gcResource, in, GcLogType.SUN1_3_1);
185185
}
186-
else if (s.indexOf("<GC: managing allocation failure: need ") != -1) {
186+
else if (s.contains("<GC: managing allocation failure: need ")) {
187187
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: Sun 1.2.2");
188188
return new DataReaderSun1_2_2(gcResource, in);
189189
}
190-
else if (s.indexOf("<GC: ") == 0 && s.indexOf('>') != -1 && new StringTokenizer(s.substring(0, s.indexOf('>')+1), " ").countTokens() == 20) {
190+
else if (s.indexOf("<GC: ") == 0 && s.contains(">") && new StringTokenizer(s.substring(0, s.indexOf(">")+1), " ").countTokens() == 20) {
191191
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: HP-UX 1.2/1.3/1.4.0");
192192
return new DataReaderHPUX1_2(gcResource, in);
193193
}
194-
else if (s.indexOf("<GC: ") == 0 && s.indexOf('>') != -1 && new StringTokenizer(s.substring(0, s.indexOf('>')+1), " ").countTokens() == 22) {
194+
else if (s.startsWith("<GC: ") && s.contains(">") && new StringTokenizer(s.substring(0, s.indexOf(">")+1), " ").countTokens() == 22) {
195195
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: HP-UX 1.4.1/1.4.2");
196196
return new DataReaderHPUX1_4_1(gcResource, in);
197197
}
198198
else if (s.contains("<verbosegc") && (s.contains("version=\"R26_Java6") || s.contains("version=\"R27_Java7") || s.contains("version=\"R28_Java8"))) {
199199
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: IBM J9 R26 / R27 / R28");
200200
return new DataReaderIBM_J9_R28(gcResource, in);
201201
}
202-
else if (s.indexOf("<verbosegc version=\"") != -1) {
202+
else if (s.contains("<verbosegc version=\"")) {
203203
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: IBM J9 5.0");
204204
return new DataReaderIBM_J9_5_0(gcResource, in);
205205
}
206-
else if (s.indexOf("starting collection, threshold allocation reached.") != -1) {
206+
else if (s.contains("starting collection, threshold allocation reached.")) {
207207
if (getLogger().isLoggable(Level.INFO)) getLogger().info("File format: IBM i5/OS 1.4.2");
208208
return new DataReaderIBMi5OS1_4_2(gcResource, in);
209209
}

src/test/java/com/tagtraum/perf/gcviewer/imp/TestDataReaderFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,14 @@ public void testSun1_4_0() throws Exception {
313313
assertDataReader(DataReaderSun1_6_0.class, dr.getClass());
314314
}
315315

316+
@Test
317+
public void testOracleG1J8() throws Exception {
318+
DataReaderFactory factory = new DataReaderFactory();
319+
DataReader dr = factory.getDataReader(new GcResourceFile("byteArray"), new ByteArrayInputStream(("Java HotSpot(TM) 64-Bit Server VM (25.112-b15) for windows-amd64 JRE (1.8.0_112-b15), built on Sep 22 2016 21:31:56 by \"java_re\" with MS VC++ 10.0 (VS2010)\n" +
320+
"Memory: 4k page, physical 50331128k(13997304k free), swap 60569268k(13009848k free)\n" +
321+
"CommandLine flags: -XX:CICompilerCount=4 -XX:ConcGCThreads=3 -XX:G1HeapRegionSize=2097152 -XX:GCLogFileSize=1048576 -XX:InitialHeapSize=4294967296 -XX:+ManagementServer -XX:MarkStackSize=4194304 -XX:MaxHeapSize=8589934592 -XX:MaxNewSize=5152702464 -XX:MinHeapDeltaBytes=2097152 -XX:NumberOfGCLogFiles=5 -XX:-OmitStackTraceInFastThrow -XX:+ParallelRefProcEnabled -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:+ReduceSignalUsage -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseG1GC -XX:+UseGCLogFileRotation -XX:-UseLargePagesIndividualAllocation\n" +
322+
"2017-12-01T14:14:50.781-0600: 1501608.217: [GC pause (G1 Evacuation Pause) (mixed)\n").getBytes()));
323+
assertDataReader(DataReaderSun1_6_0G1.class, dr.getClass());
324+
}
325+
316326
}

0 commit comments

Comments
 (0)