From b0f9e44d59bf4352fa02cfb50ba36c22f59079dc Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Thu, 3 May 2012 13:03:31 -0400 Subject: [PATCH] Improve CTF timestamp output, will now output in y/m/d, h:m:s.ns or ns or s (double) Signed-off-by: Matthew Khouzam --- .../ctfadaptor/headless/RequestBenchmark.java | 14 +-- .../tmf/core/ctfadaptor/CtfTmfEvent.java | 2 +- .../tmf/core/ctfadaptor/CtfTmfTimestamp.java | 112 +++++++++++++----- 3 files changed, 88 insertions(+), 40 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java index 5268c439d5..8876d7fb45 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java @@ -32,7 +32,7 @@ public class RequestBenchmark extends TmfEventRequest { } // Path of the trace - public static final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m1"; + public static final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel"; // *** Change this to run several time over the same trace public static final int NB_OF_PASS = 100; @@ -61,10 +61,8 @@ public class RequestBenchmark extends TmfEventRequest { // Create a new time range from -infinity to +infinity // That way, we will get "everything" in the trace - final CtfTmfTimestamp ts1 = new CtfTmfTimestamp(Long.MIN_VALUE, - (CtfTmfTrace) traces[0]); - final CtfTmfTimestamp ts2 = new CtfTmfTimestamp(Long.MAX_VALUE, - (CtfTmfTrace) traces[0]); + final CtfTmfTimestamp ts1 = new CtfTmfTimestamp(Long.MIN_VALUE); + final CtfTmfTimestamp ts2 = new CtfTmfTimestamp(Long.MAX_VALUE); final TmfTimeRange tmpRange = new TmfTimeRange(ts1, ts2); // We will issue a request for each "pass". @@ -106,16 +104,18 @@ public class RequestBenchmark extends TmfEventRequest { nbEvent = 0; prev = next; benchs.add(val); - if (benchs.size() == NB_OF_PASS) + if (benchs.size() == NB_OF_PASS) { try { System.out.println("Nb events : " + nbEvent2); - for (final double value : benchs) + for (final double value : benchs) { System.out.print(value + ", "); + } fExperiment.sendRequest(null); } catch (final Exception e) { } + } } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java index 1500c504ae..ea42c0e303 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java @@ -239,7 +239,7 @@ public final class CtfTmfEvent implements ITmfEvent { @Override public ITmfTimestamp getTimestamp() { if (fTimestamp == null) { - fTimestamp = new CtfTmfTimestamp(timestamp, fTrace); + fTimestamp = new CtfTmfTimestamp(timestamp); } return fTimestamp; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java index 284635ac6b..80b428cd3a 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java @@ -1,54 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + *******************************************************************************/ + package org.eclipse.linuxtools.tmf.core.ctfadaptor; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; +import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; public class CtfTmfTimestamp extends TmfTimestamp { - final private CtfTmfTrace fTrace; + public enum TimestampType { + FULL_DATE, DAY, NANOS, SECONDS + } + + private TimestampType type; - public CtfTmfTimestamp(long timestamp, CtfTmfTrace trace) { - fTrace = trace; + public CtfTmfTimestamp(long timestamp) { setValue(timestamp, -9, 0); + type = TimestampType.DAY; } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = (prime * result) + ((fTrace == null) ? 0 : fTrace.hashCode()); - return result; + public void setType(TimestampType value) { + type = value; + } + + public TimestampType getType() { + return type; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse + * .linuxtools.tmf.core.event.ITmfTimestamp) */ @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof CtfTmfTimestamp)) { - return false; + public ITmfTimestamp getDelta(ITmfTimestamp ts) { + TmfTimestamp parent = (TmfTimestamp) super.getDelta(ts); + long value = parent.getValue(); + long exp = parent.getScale(); + long diff = exp + 9; + for (int i = 0; i < diff; i++) { + value *= 10; } - CtfTmfTimestamp other = (CtfTmfTimestamp) obj; - if (fTrace == null) { - if (other.fTrace != null) { - return false; - } - } else if (!fTrace.equals(other.fTrace)) { - return false; + CtfTmfTimestamp retVal = new CtfTmfTimestamp(value); + if (value > 100000000) { + retVal.type = TimestampType.SECONDS; + } else { + retVal.type = TimestampType.NANOS; } - return true; + return retVal; } /* @@ -58,6 +71,41 @@ public class CtfTmfTimestamp extends TmfTimestamp { */ @Override public String toString() { + switch (type) { + case DAY: { + return dateToString(); + } + case FULL_DATE: { + return toFullDateString(); + } + case NANOS: { + return nanoToString(); + } + case SECONDS:{ + return secondsToString(); + } + } + return super.toString(); + } + + private String secondsToString() { + double timestamp = getValue(); + timestamp /= 1000000000; + StringBuilder retVal = new StringBuilder(); + retVal.append(timestamp); + retVal.append(" s"); //$NON-NLS-1$ + return retVal.toString(); + } + + private String nanoToString() { + final long timestamp = getValue(); + StringBuilder retVal = new StringBuilder(); + retVal.append(timestamp); + retVal.append(" ns"); //$NON-NLS-1$ + return retVal.toString(); + } + + private String dateToString() { final long timestamp = getValue(); final Date d = new Date(timestamp / 1000000); final DateFormat df = new SimpleDateFormat("HH:mm:ss."); //$NON-NLS-1$ @@ -68,7 +116,7 @@ public class CtfTmfTimestamp extends TmfTimestamp { return output.toString(); } - public String toFullDateString(){ + private String toFullDateString() { final long timestamp = getValue(); final Date d = new Date(timestamp / 1000000); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$ -- 2.34.1