File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
main/java/com/microsoft/gctoolkit/time
test/java/com/microsoft/gctoolkit/time Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ private static double ageFromString(String doubleFormat) {
65
65
private static final String TIME = INTEGER + DECIMAL_POINT + "\\ d{3}" ;
66
66
67
67
// Unified Tokens
68
- private static final String DATE_TAG = "\\ [" + DATE + "]" ;
68
+ private static final String DATE_TAG = "\\ [( " + DATE + ") ]" ;
69
69
private static final String UPTIME_TAG = "\\ [(" + TIME + ")s]" ;
70
70
71
71
// Pre-unified tokens
@@ -81,15 +81,20 @@ private static double ageFromString(String doubleFormat) {
81
81
82
82
public static DateTimeStamp fromGCLogLine (String line ) {
83
83
Matcher matcher ;
84
- int captureGroup = 2 ;
84
+ int dateCaptureGroup ;
85
+ int ageCaptureGroup ;
85
86
if ( line .startsWith ("[" )) {
86
87
matcher = UNIFIED_DATE_TIMESTAMP .matcher (line );
87
- captureGroup = 3 ;
88
- } else
88
+ dateCaptureGroup = 2 ;
89
+ ageCaptureGroup = 4 ;
90
+ } else {
89
91
matcher = PREUNIFIED_DATE_TIMESTAMP .matcher (line );
92
+ dateCaptureGroup = 1 ;
93
+ ageCaptureGroup = 2 ;
94
+ }
90
95
91
96
if ( matcher .find ())
92
- return new DateTimeStamp (dateFromString (matcher .group (1 )), ageFromString (matcher .group (captureGroup )));
97
+ return new DateTimeStamp (dateFromString (matcher .group (dateCaptureGroup )), ageFromString (matcher .group (ageCaptureGroup )));
93
98
else
94
99
return EMPTY_DATE ;
95
100
}
Original file line number Diff line number Diff line change @@ -483,4 +483,12 @@ void malformedDateTimeStampThrowsException() {
483
483
assertThrows (IllegalStateException .class , () -> onlyDate .after (onlyTime ));
484
484
}
485
485
486
+ @ Test
487
+ void shouldParseGCLogLineWithBrackets () {
488
+ final String dateTimeString = "2025-05-08T11:07:55.681+0530" ;
489
+ final String gcLogLine = "[" + dateTimeString + "][gc,phases ] GC(4) Other: 0.2ms" ;
490
+ final DateTimeStamp dateTimeStamp = DateTimeStamp .fromGCLogLine (gcLogLine );
491
+ final ZonedDateTime expected = ZonedDateTime .from (formatter .parse (dateTimeString ));
492
+ assertTrue (expected .isEqual (dateTimeStamp .getDateTime ()));
493
+ }
486
494
}
You can’t perform that action at this time.
0 commit comments