Skip to content

Commit

Permalink
merge "chewiebug#112/fix-datestamps" into master
Browse files Browse the repository at this point in the history
  • Loading branch information
chewiebug committed Jan 10, 2015
2 parents abde52e + 2df7740 commit 553e664
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .classpath
Expand Up @@ -27,12 +27,12 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
7 changes: 4 additions & 3 deletions pom.xml
Expand Up @@ -110,9 +110,6 @@
<source.plugin.version>2.2.1</source.plugin.version>
<javadoc.plugin.version>2.9</javadoc.plugin.version>
<gpg.plugin.version>1.4</gpg.plugin.version>
<!-- system property for maven-compiler-plugin -->
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<scm>
Expand Down Expand Up @@ -201,6 +198,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tagtraum/perf/gcviewer/ModelChartImpl.java
Expand Up @@ -173,7 +173,7 @@ public void maybePopup(MouseEvent e) {
else {
long suggestedStartDate = model.getLastModified();
if (model.hasDateStamp()) {
suggestedStartDate = model.getFirstDateStamp().getTime();
suggestedStartDate = model.getFirstDateStamp().toInstant().toEpochMilli();
}
else if (model.hasCorrectTimestamp()) {
suggestedStartDate -= (long)(model.getRunningTime() * 1000.0d);
Expand Down Expand Up @@ -351,7 +351,7 @@ public void setShowConcurrentCollectionBeginEnd(boolean showConcurrentCollection
@Override
public void setShowDateStamp(boolean showDateStamp) {
if (showDateStamp && model.hasDateStamp()) {
timeOffsetPanel.setDate(model.getFirstDateStamp());
timeOffsetPanel.setDate(Date.from(model.getFirstDateStamp().toInstant()));
timestampRuler.setOffset(timeOffsetPanel.getDate().getTime() / 1000);
timeOffsetPanel.setOffsetSet(true);
timestampRuler.revalidate();
Expand Down
Expand Up @@ -37,7 +37,7 @@ public void write(GCModel model) throws IOException {

// If the true timestamp is present, output the unix timestamp
if (model.hasDateStamp()) {
out.print(event.getDatestamp().getTime());
out.print(event.getDatestamp());
} else if (model.hasCorrectTimestamp()) {
// we have the timestamps therefore we can correct it with the pause time
out.print((event.getTimestamp() - event.getPause()));
Expand Down
@@ -1,26 +1,24 @@
package com.tagtraum.perf.gcviewer.imp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.tagtraum.perf.gcviewer.model.AbstractGCEvent;
import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.ExtendedType;
import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.GcPattern;
import com.tagtraum.perf.gcviewer.model.GCEvent;
import com.tagtraum.perf.gcviewer.util.NumberParser;
import com.tagtraum.perf.gcviewer.util.ParseInformation;

import java.io.*;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* <p>The AbstractDataReaderSun is the base class of most Sun / Oracle parser implementations.
* It contains a lot of helper methods to do the actual parsing of the details of a gc event.
Expand All @@ -33,19 +31,13 @@
*/
public abstract class AbstractDataReaderSun implements DataReader {

/**
* Datestamps are parsed without timezone information. I assume that if two people
* discuss a gc log, it is easier for them to use the same timestamps without
* timezone adjustments.
*/
public static final String DATE_STAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.S";
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
private static final int LENGTH_OF_DATESTAMP = 29;

private static Logger LOG = Logger.getLogger(AbstractDataReaderSun.class.getName());

private static final String CMS_PRINT_PROMOTION_FAILURE = "promotion failure size";
private final SimpleDateFormat dateParser = new SimpleDateFormat(DATE_STAMP_FORMAT);


private static Pattern parenthesesPattern = Pattern.compile("\\([^()]*\\) ?");

// java 8 log output
Expand Down Expand Up @@ -435,7 +427,7 @@ private double parseTimestamp(String line, ParseInformation pos) throws ParseExc
* @return timestamp (either parsed or derived from datestamp)
* @throws ParseException it seemed to be a timestamp but still couldn't be parsed
*/
protected double getTimestamp(final String line, final ParseInformation pos, final Date datestamp)
protected double getTimestamp(final String line, final ParseInformation pos, final ZonedDateTime datestamp)
throws ParseException {

double timestamp = 0;
Expand All @@ -444,7 +436,7 @@ protected double getTimestamp(final String line, final ParseInformation pos, fin
}
else if (datestamp != null && pos.getFirstDateStamp() != null) {
// if no timestamp was present, calculate difference between last and this date
timestamp = (datestamp.getTime() - pos.getFirstDateStamp().getTime()) / (double)1000;
timestamp = pos.getFirstDateStamp().until(datestamp, ChronoUnit.MILLIS) / (double) 1000;
}
return timestamp;
}
Expand Down Expand Up @@ -478,24 +470,23 @@ protected boolean startsWith(String line, List<String> lineStartStrings, boolean
* @param line current line
* @param pos current parse position
* @return returns parsed datestamp if found one, <code>null</code> otherwise
* @throws ParseException datestamp could not be parsed
*/
protected Date parseDatestamp(String line, ParseInformation pos) throws ParseException {
Date date = null;
protected ZonedDateTime parseDatestamp(String line, ParseInformation pos) throws ParseException {
ZonedDateTime zonedDateTime = null;
if (nextIsDatestamp(line, pos)) {
try {
date = dateParser.parse(line.substring(pos.getIndex(), pos.getIndex()+LENGTH_OF_DATESTAMP-1));
zonedDateTime = ZonedDateTime.parse(line.substring(pos.getIndex(), pos.getIndex() + LENGTH_OF_DATESTAMP - 1),
DATE_TIME_FORMATTER);
pos.setIndex(pos.getIndex() + LENGTH_OF_DATESTAMP);
if (pos.getFirstDateStamp() == null) {
pos.setFirstDateStamp(date);
pos.setFirstDateStamp(zonedDateTime);
}
}
catch (java.text.ParseException e) {
throw new ParseException(e.toString(), line);
} catch (DateTimeParseException e){
throw new ParseException(e.toString(), line);
}
}

return date;
return zonedDateTime;
}

/**
Expand Down Expand Up @@ -534,7 +525,7 @@ protected void parseDetailEventsIfExist(final String line, final ParseInformatio
detailEvent.setTimestamp(event.getTimestamp());
}
else {
Date datestamp = parseDatestamp(line, pos);
ZonedDateTime datestamp = parseDatestamp(line, pos);
detailEvent.setDateStamp(datestamp);
detailEvent.setTimestamp(getTimestamp(line, pos, datestamp));
}
Expand Down
Expand Up @@ -4,7 +4,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.time.ZonedDateTime;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -507,7 +507,7 @@ protected AbstractGCEvent<?> parseLine(String line, ParseInformation pos) throws
// parse collection type "[TYPE"
// either GC data or another collection type starting with timestamp
// pre-used->post-used, total, time
Date datestamp = parseDatestamp(line, pos);
ZonedDateTime datestamp = parseDatestamp(line, pos);
double timestamp = getTimestamp(line, pos, datestamp);
ExtendedType type = parseType(line, pos);
// special provision for CMS events
Expand Down
Expand Up @@ -4,7 +4,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.time.ZonedDateTime;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
Expand Down Expand Up @@ -244,7 +244,7 @@ else if (isPrintTenuringDistribution(line)) {
// detailed G1 events start with GC_MEMORY pattern, but are of type GC_MEMORY_PAUSE

gcEvent = new G1GcEvent();
Date datestamp = parseDatestamp(gcPauseMatcher.group(GC_PAUSE_GROUP_DATESTAMP), parsePosition);
ZonedDateTime datestamp = parseDatestamp(gcPauseMatcher.group(GC_PAUSE_GROUP_DATESTAMP), parsePosition);
gcEvent.setDateStamp(datestamp);
double timestamp = 0;
if (gcPauseMatcher.group(GC_PAUSE_GROUP_TIMESTAMP) == null) {
Expand Down Expand Up @@ -348,7 +348,6 @@ private boolean isPrintTenuringDistribution(String line) {
* @param beginningOfLine GC_PAUSE lines are sometimes mixed lines; the extracted parts
* of such a line are stored inside "beginningOfLine"
* @return line number of last line read in this method
* @throws ParseException Problem parsing a part of the details
* @throws IOException problem reading from file
*/
private int parseDetails(BufferedReader in,
Expand Down Expand Up @@ -501,7 +500,7 @@ protected AbstractGCEvent<?> parseLine(String line, ParseInformation pos) throws
// parse timestamp "double:"
// parse collection type "[TYPE"
// pre-used->post-used, total, time
Date datestamp = parseDatestamp(line, pos);
ZonedDateTime datestamp = parseDatestamp(line, pos);
double timestamp = getTimestamp(line, pos, datestamp);
ExtendedType type = parseType(line, pos);
// special provision for concurrent events
Expand Down Expand Up @@ -555,7 +554,7 @@ else if (type.getCollectionType().equals(CollectionType.VM_OPERATION)) {
* @throws ParseException
*/
private AbstractGCEvent<?> parseConcurrentEvent(String line,
ParseInformation pos, Date datestamp,
ParseInformation pos, ZonedDateTime datestamp,
double timestamp, final ExtendedType type) throws ParseException {

ConcurrentGCEvent event = new ConcurrentGCEvent();
Expand Down
@@ -1,9 +1,9 @@
package com.tagtraum.perf.gcviewer.model;

import java.io.Serializable;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand All @@ -22,7 +22,7 @@
*/
public abstract class AbstractGCEvent<T extends AbstractGCEvent<T>> implements Serializable {
private final Iterator<T> EMPTY_ITERATOR = Collections.emptyIterator();
private Date datestamp;
private ZonedDateTime datestamp;
private double timestamp;
private ExtendedType extendedType = ExtendedType.UNDEFINED;
private boolean tenuredDetail;
Expand Down Expand Up @@ -60,7 +60,7 @@ public boolean hasTenuredDetail() {
return tenuredDetail;
}

public void setDateStamp(Date datestamp) {
public void setDateStamp(ZonedDateTime datestamp) {
this.datestamp = datestamp;
}

Expand Down Expand Up @@ -148,7 +148,7 @@ public double getTimestamp() {
return timestamp;
}

public Date getDatestamp() {
public ZonedDateTime getDatestamp() {
return datestamp;
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/tagtraum/perf/gcviewer/model/GCModel.java
Expand Up @@ -7,9 +7,10 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.time.Duration;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -489,12 +490,11 @@ private void adjustTimeStamp(AbstractGCEvent<?> previousEvent, VmOperationEvent
if (previousEvent.getTimestamp() + previousEvent.getPause() > vmOpEvent.getTimestamp()) {
vmOpEvent.setTimestamp(previousEvent.getTimestamp() + previousEvent.getPause());
if (previousEvent.getDatestamp() != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(previousEvent.getDatestamp());
cal.add(Calendar.MINUTE, (int)Math.rint(previousEvent.getPause() / 60));
cal.add(Calendar.SECOND, (int)Math.rint(previousEvent.getPause()));
cal.add(Calendar.MILLISECOND, (int)Math.rint(previousEvent.getPause() * 1000));
vmOpEvent.setDateStamp(cal.getTime());
Duration adjustment = Duration.ofMinutes((long) Math.rint(previousEvent.getPause() / 60))
.plus((long) Math.rint(previousEvent.getPause()), ChronoUnit.SECONDS)
.plus((long) Math.rint(previousEvent.getPause() * 1000), ChronoUnit.MILLIS);
ZonedDateTime adjustedDatestamp = previousEvent.getDatestamp().plus(adjustment);
vmOpEvent.setDateStamp(adjustedDatestamp);
}
}
}
Expand Down Expand Up @@ -887,7 +887,7 @@ public boolean hasDateStamp() {
: false;
}

public Date getFirstDateStamp() {
public ZonedDateTime getFirstDateStamp() {
return allEvents.size() > 0
? get(0).getDatestamp()
: null;
Expand Down
@@ -1,7 +1,7 @@
package com.tagtraum.perf.gcviewer.util;

import java.text.ParsePosition;
import java.util.Date;
import java.time.ZonedDateTime;

/**
* This class holds information about the current parsing process.
Expand All @@ -11,22 +11,22 @@
*/
public class ParseInformation extends ParsePosition {

private Date firstDateStamp;
private ZonedDateTime firstDateStamp;
private int lineNumber;

public ParseInformation(int index) {
super(index);
}

public Date getFirstDateStamp() {
public ZonedDateTime getFirstDateStamp() {
return firstDateStamp;
}

public int getLineNumber() {
return lineNumber;
}

public void setFirstDateStamp(Date firstDateStamp) {
public void setFirstDateStamp(ZonedDateTime firstDateStamp) {
this.firstDateStamp = firstDateStamp;
}

Expand Down
Expand Up @@ -3,7 +3,6 @@
import java.awt.Component;
import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.awt.Frame;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -51,7 +50,7 @@ public static void displayUrl(Component parent, String url) {
/**
* Convenience method to display an url.
*
* @see #displayUrl(Frame, String)
* @see #displayUrl(Component, String)
*/
public static void displayUrl(Component parent, URL url) {
displayUrl(parent, url.toString());
Expand Down
Expand Up @@ -7,6 +7,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mockito;

import java.time.ZonedDateTime;
import java.util.Date;

import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void shouldShowOrNotDateStampAccordingToModelAndSettings(TestCase testCas
GCPreferences preferences = new GCPreferences();
GCModel gcModel = Mockito.mock(GCModel.class);
Mockito.when(gcModel.hasDateStamp()).thenReturn(testCase.hasDateStamp());
Mockito.when(gcModel.getFirstDateStamp()).thenReturn(new Date());
Mockito.when(gcModel.getFirstDateStamp()).thenReturn(ZonedDateTime.now());
preferences.setShowDateStamp(testCase.isShowDateStamp());

//when
Expand Down

0 comments on commit 553e664

Please sign in to comment.