From cbdacf036a44ec3145f8e508643cddb4901541fc Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Fri, 13 Apr 2012 14:05:21 -0400 Subject: [PATCH] Refactor ITmfContext and fix dependencies --- .../internal/lttng/core/trace/LTTngTrace.java | 424 ++++++++---------- .../core/tests/event/TmfEventFieldTest.java | 2 + .../tmf/core/tests/trace/TmfContextTest.java | 357 ++++++++------- .../tmf/core/ctfadaptor/CtfIterator.java | 6 +- .../tmf/core/experiment/TmfExperiment.java | 383 ++++++++-------- .../core/experiment/TmfExperimentContext.java | 231 +++++----- .../tmf/core/trace/ITmfContext.java | 71 ++- .../tmf/core/trace/TmfCheckpoint.java | 73 ++- .../linuxtools/tmf/core/trace/TmfContext.java | 155 +++++-- .../tmf/core/trace/TmfLocation.java | 3 +- .../linuxtools/tmf/core/trace/TmfTrace.java | 6 +- .../tmf/ui/parsers/custom/CustomTxtTrace.java | 2 +- .../tmf/ui/parsers/custom/CustomXmlTrace.java | 2 +- 13 files changed, 915 insertions(+), 800 deletions(-) diff --git a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java index a373f9cf3f..eee82825f8 100644 --- a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java +++ b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java @@ -44,14 +44,14 @@ import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; -import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; class LTTngTraceException extends LttngException { + static final long serialVersionUID = -1636648737081868146L; - public LTTngTraceException(String errMsg) { + public LTTngTraceException(final String errMsg) { super(errMsg); } } @@ -60,8 +60,8 @@ class LTTngTraceException extends LttngException { * LTTngTrace *

* - * LTTng trace implementation. It accesses the C trace handling library (seeking, reading and parsing) through the JNI - * component. + * LTTng trace implementation. It accesses the C trace handling library + * (seeking, reading and parsing) through the JNI component. */ public class LTTngTrace extends TmfTrace { @@ -91,34 +91,35 @@ public class LTTngTrace extends TmfTrace { // Hashmap of the possible types of events (Tracefile/CPU/Marker in the JNI) HashMap traceTypes; - + // This vector will be used to quickly find a marker name from a position Vector traceTypeNames; - + private String traceLibPath; public LTTngTrace() { } @Override - public boolean validate(IProject project, String path) { + public boolean validate(final IProject project, final String path) { if (super.validate(project, path)) { - String traceLibPath = TraceHelper.getTraceLibDirFromProject(project); + final String traceLibPath = TraceHelper.getTraceLibDirFromProject(project); try { - LTTngTraceVersion version = new LTTngTraceVersion(path, traceLibPath); + final LTTngTraceVersion version = new LTTngTraceVersion(path, traceLibPath); return version.isValidLttngTrace(); - } catch (LttngException e) { + } catch (final LttngException e) { } } return false; } @Override - public synchronized void initTrace(String name, String path, Class eventType) throws FileNotFoundException { + public synchronized void initTrace(final String name, final String path, final Class eventType) + throws FileNotFoundException { super.initTrace(name, path, eventType); try { currentJniTrace = JniTraceFactory.getJniTrace(path, traceLibPath, SHOW_LTT_DEBUG_DEFAULT); - } catch (Exception e) { + } catch (final Exception e) { throw new FileNotFoundException(e.getMessage()); } @@ -157,27 +158,29 @@ public class LTTngTrace extends TmfTrace { } private void initializeStreamingMonitor() { - JniTrace jniTrace = getCurrentJniTrace(); - if (jniTrace == null || (!jniTrace.isLiveTraceSupported() || !LiveTraceManager.isLiveTrace(jniTrace.getTracepath()))) { + final JniTrace jniTrace = getCurrentJniTrace(); + if (jniTrace == null + || (!jniTrace.isLiveTraceSupported() || !LiveTraceManager.isLiveTrace(jniTrace.getTracepath()))) { // Set the time range of the trace - TmfContext context = seekLocation(null); - LttngEvent event = getNextEvent(context); - LttngTimestamp startTime = new LttngTimestamp(event.getTimestamp()); - LttngTimestamp endTime = new LttngTimestamp(currentJniTrace.getEndTime().getTime()); + final TmfContext context = seekLocation(null); + final LttngEvent event = getNextEvent(context); + final LttngTimestamp startTime = new LttngTimestamp(event.getTimestamp()); + final LttngTimestamp endTime = new LttngTimestamp(currentJniTrace.getEndTime().getTime()); setTimeRange(new TmfTimeRange(startTime, endTime)); - TmfTraceUpdatedSignal signal = new TmfTraceUpdatedSignal(this, this, getTimeRange()); + final TmfTraceUpdatedSignal signal = new TmfTraceUpdatedSignal(this, this, getTimeRange()); broadcast(signal); return; } // Set the time range of the trace - TmfContext context = seekLocation(null); - LttngEvent event = getNextEvent(context); + final TmfContext context = seekLocation(null); + final LttngEvent event = getNextEvent(context); setEndTime(TmfTimestamp.BIG_BANG); final long startTime = event != null ? event.getTimestamp().getValue() : TmfTimestamp.BIG_BANG.getValue(); fStreamingInterval = LTTNG_STREAMING_INTERVAL; final Thread thread = new Thread("Streaming Monitor for trace " + getName()) { //$NON-NLS-1$ + LttngTimestamp safeTimestamp = null; TmfTimeRange timeRange = null; @@ -185,10 +188,12 @@ public class LTTngTrace extends TmfTrace { @Override public void run() { while (!fExecutor.isShutdown()) { - TmfExperiment experiment = TmfExperiment.getCurrentExperiment(); + final TmfExperiment experiment = TmfExperiment.getCurrentExperiment(); if (experiment != null) { @SuppressWarnings("rawtypes") - final TmfEventRequest request = new TmfEventRequest(TmfEvent.class, TmfTimeRange.ETERNITY, 0, ExecutionType.FOREGROUND) { + final TmfEventRequest request = new TmfEventRequest(TmfEvent.class, + TmfTimeRange.ETERNITY, 0, ExecutionType.FOREGROUND) { + @Override public void handleCompleted() { updateJniTrace(); @@ -199,35 +204,32 @@ public class LTTngTrace extends TmfTrace { } try { request.waitForCompletion(); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { e.printStackTrace(); } - } else { + } else updateJniTrace(); - } try { Thread.sleep(LTTNG_STREAMING_INTERVAL); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { e.printStackTrace(); } } } - + private void updateJniTrace() { - JniTrace jniTrace = getCurrentJniTrace(); + final JniTrace jniTrace = getCurrentJniTrace(); currentJniTrace.updateTrace(); - long endTime = jniTrace.getEndTime().getTime(); - LttngTimestamp startTimestamp = new LttngTimestamp(startTime); - LttngTimestamp endTimestamp = new LttngTimestamp(endTime); - if (safeTimestamp != null && safeTimestamp.compareTo(getTimeRange().getEndTime(), false) > 0) { + final long endTime = jniTrace.getEndTime().getTime(); + final LttngTimestamp startTimestamp = new LttngTimestamp(startTime); + final LttngTimestamp endTimestamp = new LttngTimestamp(endTime); + if (safeTimestamp != null && safeTimestamp.compareTo(getTimeRange().getEndTime(), false) > 0) timeRange = new TmfTimeRange(startTimestamp, safeTimestamp); - } else { + else timeRange = null; - } safeTimestamp = endTimestamp; - if (timeRange != null) { + if (timeRange != null) setTimeRange(timeRange); - } } }; thread.start(); @@ -236,16 +238,14 @@ public class LTTngTrace extends TmfTrace { /** * Default Constructor. *

- * - * @param name - * Name of the trace - * @param path - * Path to a directory that contain an LTTng trace. * - * @exception Exception - * (most likely LTTngTraceException or FileNotFoundException) + * @param name Name of the trace + * @param path Path to a directory that contain an LTTng trace. + * + * @exception Exception (most likely LTTngTraceException or + * FileNotFoundException) */ - public LTTngTrace(String name, String path) throws Exception { + public LTTngTrace(final String name, final String path) throws Exception { // Call with "wait for completion" true and "skip indexing" false this(name, path, null, true, false); } @@ -254,41 +254,39 @@ public class LTTngTrace extends TmfTrace { * Constructor, with control over the indexing. *

* - * @param name - * Name of the trace - * @param path - * Path to a directory that contain an LTTng trace. - * @param waitForCompletion - * Should we wait for indexign to complete before moving on. + * @param name Name of the trace + * @param path Path to a directory that contain an LTTng trace. + * @param waitForCompletion Should we wait for indexign to complete before + * moving on. * - * @exception Exception - * (most likely LTTngTraceException or FileNotFoundException) + * @exception Exception (most likely LTTngTraceException or + * FileNotFoundException) */ - public LTTngTrace(String name, String path, boolean waitForCompletion) throws Exception { + public LTTngTrace(final String name, final String path, final boolean waitForCompletion) throws Exception { // Call with "skip indexing" false this(name, path, null, waitForCompletion, true); } /** - * Default constructor, with control over the indexing and possibility to bypass indexation + * Default constructor, with control over the indexing and possibility to + * bypass indexation *

* - * @param name - * Name of the trace - * @param path - * Path to a directory that contain an LTTng trace. - * @param traceLibPath - * Path to a directory that contains LTTng trace libraries. - * @param waitForCompletion - * Should we wait for indexign to complete before moving on. - * @param bypassIndexing - * Should we bypass indexing completly? This is should only be useful for unit testing. + * @param name Name of the trace + * @param path Path to a directory that contain an LTTng trace. + * @param traceLibPath Path to a directory that contains LTTng trace + * libraries. + * @param waitForCompletion Should we wait for indexign to complete before + * moving on. + * @param bypassIndexing Should we bypass indexing completly? This is should + * only be useful for unit testing. * - * @exception Exception - * (most likely LTTngTraceException or FileNotFoundException) + * @exception Exception (most likely LTTngTraceException or + * FileNotFoundException) * */ - public LTTngTrace(String name, String path, String traceLibPath, boolean waitForCompletion, boolean bypassIndexing) + public LTTngTrace(final String name, final String path, final String traceLibPath, final boolean waitForCompletion, + final boolean bypassIndexing) throws Exception { super(name, LttngEvent.class, path, CHECKPOINT_PAGE_SIZE, false); initTrace(name, path, LttngEvent.class); @@ -300,7 +298,7 @@ public class LTTngTrace extends TmfTrace { /* * Copy constructor is forbidden for LttngEvenmStream */ - public LTTngTrace(LTTngTrace other) throws Exception { + public LTTngTrace(final LTTngTrace other) throws Exception { this(other.getName(), other.getPath(), other.getTraceLibPath(), false, true); this.fCheckpoints = other.fCheckpoints; setTimeRange(new TmfTimeRange(new LttngTimestamp(other.getStartTime()), new LttngTimestamp(other.getEndTime()))); @@ -313,7 +311,7 @@ public class LTTngTrace extends TmfTrace { try { clone.currentJniTrace = JniTraceFactory.getJniTrace(getPath(), getTraceLibPath(), SHOW_LTT_DEBUG_DEFAULT); - } catch (JniException e) { + } catch (final JniException e) { // e.printStackTrace(); } @@ -355,7 +353,7 @@ public class LTTngTrace extends TmfTrace { * * This should be called at construction once the trace is open */ - private void initialiseEventTypes(JniTrace trace) { + private void initialiseEventTypes(final JniTrace trace) { // Work variables LttngEventType tmpType = null; String[] markerFieldsLabels = null; @@ -367,14 +365,14 @@ public class LTTngTrace extends TmfTrace { JniMarker newMarker = null; // First, obtain an iterator on TRACEFILES of owned by the TRACE - Iterator tracefileItr = trace.getTracefilesMap().keySet().iterator(); + final Iterator tracefileItr = trace.getTracefilesMap().keySet().iterator(); while (tracefileItr.hasNext()) { newTracefileKey = tracefileItr.next(); newTracefile = trace.getTracefilesMap().get(newTracefileKey); // From the TRACEFILE read, obtain its MARKER - Iterator markerItr = newTracefile.getTracefileMarkersMap().keySet().iterator(); + final Iterator markerItr = newTracefile.getTracefileMarkersMap().keySet().iterator(); while (markerItr.hasNext()) { newMarkerKey = markerItr.next(); newMarker = newTracefile.getTracefileMarkersMap().get(newMarkerKey); @@ -396,17 +394,19 @@ public class LTTngTrace extends TmfTrace { /* * Add a new type to the HashMap * - * As the hashmap use a key format that is a bit dangerous to use, we should always add using this function. + * As the hashmap use a key format that is a bit dangerous to use, we should + * always add using this function. */ - private void addEventTypeToMap(LttngEventType newEventType) { - int newTypeKey = EventTypeKey.getEventTypeHash(newEventType); + private void addEventTypeToMap(final LttngEventType newEventType) { + final int newTypeKey = EventTypeKey.getEventTypeHash(newEventType); this.traceTypes.put(newTypeKey, newEventType); this.traceTypeNames.add(newTypeKey); } /** - * Return the latest saved location. Note : Modifying the returned location may result in buggy positionning! + * Return the latest saved location. Note : Modifying the returned location + * may result in buggy positionning! * * @return The LttngLocation as it was after the last operation. * @@ -420,12 +420,12 @@ public class LTTngTrace extends TmfTrace { /** * Position the trace to the event at the given location. *

- * NOTE : Seeking by location is very fast compare to seeking by position but is still slower than "ReadNext", avoid - * using it for small interval. + * NOTE : Seeking by location is very fast compare to seeking by position + * but is still slower than "ReadNext", avoid using it for small interval. * - * @param location - * Location of the event in the trace. If no event available at this exact location, we will position - * ourself to the next one. + * @param location Location of the event in the trace. If no event available + * at this exact location, we will position ourself to the next + * one. * * @return The TmfContext that point to this event * @@ -433,38 +433,35 @@ public class LTTngTrace extends TmfTrace { * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext */ @Override - public synchronized TmfContext seekLocation(ITmfLocation location) { + public synchronized TmfContext seekLocation(final ITmfLocation location) { // // [lmcfrch] // lastTime = 0; - if (PRINT_DEBUG) { + if (PRINT_DEBUG) System.out.println("seekLocation(location) location -> " + location); //$NON-NLS-1$ - } // If the location in context is null, create a new one LttngLocation curLocation = null; if (location == null) { curLocation = new LttngLocation(); - TmfContext context = seekEvent(curLocation.getOperationTime()); + final TmfContext context = seekEvent(curLocation.getOperationTime()); context.setRank(ITmfContext.INITIAL_RANK); return context; - } else { + } else curLocation = (LttngLocation) location; - } // *** NOTE : // Update to location should (and will) be done in SeekEvent. // The only seek valid in LTTng is with the time, we call // seekEvent(timestamp) - TmfContext context = seekEvent(curLocation.getOperationTime()); + final TmfContext context = seekEvent(curLocation.getOperationTime()); // If the location is marked with the read next flag // then it is pointing to the next event following the operation time - if (curLocation.isLastOperationReadNext()) { + if (curLocation.isLastOperationReadNext()) getNextEvent(context); - } return context; } @@ -472,12 +469,11 @@ public class LTTngTrace extends TmfTrace { /** * Position the trace to the event at the given time. *

- * NOTE : Seeking by time is very fast compare to seeking by position but is still slower than "ReadNext", avoid - * using it for small interval. + * NOTE : Seeking by time is very fast compare to seeking by position but is + * still slower than "ReadNext", avoid using it for small interval. * - * @param timestamp - * Time of the event in the trace. If no event available at this exact time, we will position ourself to - * the next one. + * @param timestamp Time of the event in the trace. If no event available at + * this exact time, we will position ourself to the next one. * * @return The TmfContext that point to this event * @@ -485,11 +481,10 @@ public class LTTngTrace extends TmfTrace { * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext */ @Override - public synchronized TmfContext seekEvent(ITmfTimestamp timestamp) { + public synchronized TmfContext seekEvent(final ITmfTimestamp timestamp) { - if (PRINT_DEBUG) { + if (PRINT_DEBUG) System.out.println("seekEvent(timestamp) timestamp -> " + timestamp); //$NON-NLS-1$ - } // Call JNI to seek currentJniTrace.seekToTime(new JniTime(timestamp.getValue())); @@ -500,7 +495,7 @@ public class LTTngTrace extends TmfTrace { // this event previousLocation.setLastOperationSeek(); - LttngLocation curLocation = new LttngLocation(previousLocation); + final LttngLocation curLocation = new LttngLocation(previousLocation); return new TmfContext(curLocation); } @@ -508,10 +503,10 @@ public class LTTngTrace extends TmfTrace { /** * Position the trace to the event at the given position (rank). *

- * NOTE : Seeking by position is very slow in LTTng, consider seeking by timestamp. + * NOTE : Seeking by position is very slow in LTTng, consider seeking by + * timestamp. * - * @param position - * Position (or rank) of the event in the trace, starting at 0. + * @param rank Position (or rank) of the event in the trace, starting at 0. * * @return The TmfContext that point to this event * @@ -519,29 +514,24 @@ public class LTTngTrace extends TmfTrace { * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext */ @Override - public synchronized TmfContext seekEvent(long position) { + public synchronized TmfContext seekEvent(final long rank) { - if (PRINT_DEBUG) { - System.out.println("seekEvent(position) position -> " + position); //$NON-NLS-1$ - } + if (PRINT_DEBUG) + System.out.println("seekEvent(rank) rank -> " + rank); //$NON-NLS-1$ ITmfTimestamp timestamp = null; - long index = position / getIndexPageSize(); + long index = rank / getIndexPageSize(); // Get the timestamp of the closest check point to the given position if (fCheckpoints.size() > 0) { - if (index >= fCheckpoints.size()) { + if (index >= fCheckpoints.size()) index = fCheckpoints.size() - 1; - } timestamp = fCheckpoints.elementAt((int) index).getTimestamp(); - } - // If none, take the start time of the trace - else { + } else timestamp = getStartTime(); - } // Seek to the found time - TmfContext tmpContext = seekEvent(timestamp); + final TmfContext tmpContext = seekEvent(timestamp); tmpContext.setRank((index + 1) * fIndexPageSize); previousLocation = (LttngLocation) tmpContext.getLocation(); @@ -555,15 +545,14 @@ public class LTTngTrace extends TmfTrace { // Now that we are positionned at the checkpoint, // we need to "readNext" (Position - CheckpointPosition) times or until // trace "run out" - while ((tmpJniEvent != null) && (currentPosition < position)) { + while ((tmpJniEvent != null) && (currentPosition < rank)) { tmpJniEvent = currentJniTrace.readNextEvent(); currentPosition++; } // If we found our event, save its timestamp - if (tmpJniEvent != null) { + if (tmpJniEvent != null) lastTimeValueRead = tmpJniEvent.getEventTime().getTime(); - } // Set the operation marker as seek, to be able to detect we did "seek" // this event @@ -576,30 +565,31 @@ public class LTTngTrace extends TmfTrace { // // We don't trust what upper level could do with our internal location // so we create a new one to return instead - LttngLocation curLocation = new LttngLocation(previousLocation); + final LttngLocation curLocation = new LttngLocation(previousLocation); - return new TmfContext(curLocation); + return new TmfContext(curLocation, rank); } @Override - public TmfContext seekLocation(double ratio) { + public TmfContext seekLocation(final double ratio) { // TODO Auto-generated method stub return null; } @Override - public double getLocationRatio(ITmfLocation location) { + public double getLocationRatio(final ITmfLocation location) { // TODO Auto-generated method stub return 0; } /** - * Return the event in the trace according to the given context. Read it if necessary. + * Return the event in the trace according to the given context. Read it if + * necessary. *

- * Similar (same?) as ParseEvent except that calling GetNext twice read the next one the second time. + * Similar (same?) as ParseEvent except that calling GetNext twice read the + * next one the second time. * - * @param context - * Current TmfContext where to get the event + * @param context Current TmfContext where to get the event * * @return The LttngEvent we read of null if no event are available * @@ -610,21 +600,19 @@ public class LTTngTrace extends TmfTrace { public int nbEventsRead = 0; @Override - public synchronized LttngEvent getNextEvent(ITmfContext context) { + public synchronized LttngEvent getNextEvent(final ITmfContext context) { - if (PRINT_DEBUG) { + if (PRINT_DEBUG) System.out.println("getNextEvent(context) context.getLocation() -> " //$NON-NLS-1$ + context.getLocation()); - } LttngEvent returnedEvent = null; LttngLocation curLocation = null; curLocation = (LttngLocation) context.getLocation(); // If the location in context is null, create a new one - if (curLocation == null) { + if (curLocation == null) curLocation = getCurrentLocation(context); - } // *** Positioning trick : // GetNextEvent only read the trace if : @@ -635,11 +623,10 @@ public class LTTngTrace extends TmfTrace { if ((!(curLocation.isLastOperationParse())) || (previousLocation.getOperationTimeValue() != curLocation.getOperationTimeValue())) { if (previousLocation.getOperationTimeValue() != curLocation.getOperationTimeValue()) { - if (PRINT_DEBUG) { + if (PRINT_DEBUG) System.out.println("\t\tSeeking in getNextEvent. [ LastTime : " //$NON-NLS-1$ + previousLocation.getOperationTimeValue() + " CurrentTime" //$NON-NLS-1$ + curLocation.getOperationTimeValue() + " ]"); //$NON-NLS-1$ - } seekEvent(curLocation.getOperationTime()); } // Read the next event from the trace. The last one will NO LONGER @@ -659,52 +646,47 @@ public class LTTngTrace extends TmfTrace { // If we read an event, set it's time to the locations (both previous // and current) - if (returnedEvent != null) { + if (returnedEvent != null) setPreviousAndCurrentTimes(context, returnedEvent, curLocation); - } return returnedEvent; } // this method was extracted for profiling purposes - private synchronized void setPreviousAndCurrentTimes(ITmfContext context, LttngEvent returnedEvent, LttngLocation curLocation) { + private synchronized void setPreviousAndCurrentTimes(final ITmfContext context, final LttngEvent returnedEvent, + final LttngLocation curLocation) { - ITmfTimestamp eventTimestamp = returnedEvent.getTimestamp(); + final ITmfTimestamp eventTimestamp = returnedEvent.getTimestamp(); // long eventTime = eventTimestamp.getValue(); previousLocation.setOperationTime(eventTimestamp.getValue()); curLocation.setOperationTime(eventTimestamp.getValue()); updateIndex(context, context.getRank(), eventTimestamp); - context.updateRank(1); - } - - protected void updateIndex(TmfContext context, long rank, ITmfTimestamp timestamp) { - - if (getStartTime().compareTo(timestamp, false) > 0) - setStartTime(timestamp); - if (getEndTime().compareTo(timestamp, false) < 0) - setEndTime(timestamp); - if (rank != ITmfContext.UNKNOWN_RANK) { - if (fNbEvents <= rank) - fNbEvents = rank + 1; - // Build the index as we go along - if ((rank % fIndexPageSize) == 0) { - // Determine the table position - long position = rank / fIndexPageSize; - // Add new entry at proper location (if empty) - if (fCheckpoints.size() == position) { - addCheckPoint(context, timestamp); - } - } - } + context.increaseRank(); } - private void addCheckPoint(TmfContext context, ITmfTimestamp timestamp) { - ITmfLocation location = context.getLocation().clone(); - fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location)); - } +// protected void updateIndex(TmfContext context, long rank, ITmfTimestamp timestamp) { +// +// if (getStartTime().compareTo(timestamp, false) > 0) +// setStartTime(timestamp); +// if (getEndTime().compareTo(timestamp, false) < 0) +// setEndTime(timestamp); +// if (rank != ITmfContext.UNKNOWN_RANK) { +// if (fNbEvents <= rank) +// fNbEvents = rank + 1; +// // Build the index as we go along +// if ((rank % fIndexPageSize) == 0) { +// // Determine the table position +// long position = rank / fIndexPageSize; +// // Add new entry at proper location (if empty) +// if (fCheckpoints.size() == position) { +// addCheckPoint(context, timestamp); +// } +// } +// } +// } // this method was extracted for profiling purposes - private synchronized LttngEvent readNextEvent(LttngLocation curLocation) { + private synchronized LttngEvent readNextEvent(final LttngLocation curLocation) { LttngEvent returnedEvent; // Read the next event from the trace. The last one will NO LONGER BE // VALID. @@ -719,7 +701,7 @@ public class LTTngTrace extends TmfTrace { } // this method was extracted for profiling purposes - private LttngLocation getCurrentLocation(ITmfContext context) { + private LttngLocation getCurrentLocation(final ITmfContext context) { LttngLocation curLocation; curLocation = new LttngLocation(); context.setLocation(curLocation); @@ -727,12 +709,13 @@ public class LTTngTrace extends TmfTrace { } /** - * Return the event in the trace according to the given context. Read it if necessary. + * Return the event in the trace according to the given context. Read it if + * necessary. *

- * Similar (same?) as GetNextEvent except that calling ParseEvent twice will return the same event + * Similar (same?) as GetNextEvent except that calling ParseEvent twice will + * return the same event * - * @param context - * Current TmfContext where to get the event + * @param context Current TmfContext where to get the event * * @return The LttngEvent we read of null if no event are available * @@ -740,12 +723,11 @@ public class LTTngTrace extends TmfTrace { * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext */ @Override - public synchronized LttngEvent parseEvent(ITmfContext context) { + public synchronized LttngEvent parseEvent(final ITmfContext context) { - if (PRINT_DEBUG) { + if (PRINT_DEBUG) System.out.println("parseEvent(context) context.getLocation() -> " //$NON-NLS-1$ + context.getLocation()); - } LttngEvent returnedEvent = null; LttngLocation curLocation = null; @@ -754,12 +736,8 @@ public class LTTngTrace extends TmfTrace { if (context.getLocation() == null) { curLocation = new LttngLocation(); context.setLocation(curLocation); - } - // Otherwise, we use the one in context; it should be a valid - // LttngLocation - else { + } else curLocation = (LttngLocation) context.getLocation(); - } // *** HACK *** // TMF assumes it is possible to read (GetNextEvent) to the next Event @@ -784,22 +762,20 @@ public class LTTngTrace extends TmfTrace { // Previous time != Current time : We need to reposition to the // current time if (previousLocation.getOperationTimeValue() != curLocation.getOperationTimeValue()) { - if (PRINT_DEBUG) { + if (PRINT_DEBUG) System.out.println("\t\tSeeking in getNextEvent. [ LastTime : " //$NON-NLS-1$ + previousLocation.getOperationTimeValue() + " CurrentTime" //$NON-NLS-1$ + curLocation.getOperationTimeValue() + " ]"); //$NON-NLS-1$ - } seekEvent(curLocation.getOperationTime()); } // Read the next event from the trace. The last one will NO LONGER // BE VALID. returnedEvent = readEvent(curLocation); - } else { + } else // No event was read, just return the one currently loaded (the last // one we read) returnedEvent = currentLttngEvent; - } // If we read an event, set it's time to the locations (both previous // and current) @@ -819,7 +795,8 @@ public class LTTngTrace extends TmfTrace { /* * Read the next event from the JNI and convert it as Lttng Event

* - * @param location Current LttngLocation that to be updated with the event timestamp + * @param location Current LttngLocation that to be updated with the event + * timestamp * * @return The LttngEvent we read of null if no event are available * @@ -827,7 +804,7 @@ public class LTTngTrace extends TmfTrace { * * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniTrace */ - private synchronized LttngEvent readEvent(LttngLocation location) { + private synchronized LttngEvent readEvent(final LttngLocation location) { LttngEvent returnedEvent = null; JniEvent tmpEvent = null; @@ -841,15 +818,8 @@ public class LTTngTrace extends TmfTrace { returnedEvent = convertJniEventToTmf(tmpEvent); location.setOperationTime((LttngTimestamp) returnedEvent.getTimestamp()); - } - // *** NOTE - // If the read failed (likely the last event in the trace), set the - // LastReadTime to the JNI time - // That way, even if we try to read again, we will step over the bogus - // seek and read - else { + } else location.setOperationTime(getEndTime().getValue() + 1); - } return returnedEvent; } @@ -858,18 +828,17 @@ public class LTTngTrace extends TmfTrace { * Method to convert a JniEvent into a LttngEvent. *

* - * Note : This method will call LttngEvent convertEventJniToTmf(JniEvent, boolean) with a default value for - * isParsingNeeded + * Note : This method will call LttngEvent convertEventJniToTmf(JniEvent, + * boolean) with a default value for isParsingNeeded * - * @param newEvent - * The JniEvent to convert into LttngEvent + * @param newEvent The JniEvent to convert into LttngEvent * * @return The converted LttngEvent * * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent * @see org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent */ - public synchronized LttngEvent convertJniEventToTmf(JniEvent newEvent) { + public synchronized LttngEvent convertJniEventToTmf(final JniEvent newEvent) { currentLttngEvent = convertJniEventToTmf(newEvent, IS_PARSING_NEEDED_DEFAULT); return currentLttngEvent; @@ -878,17 +847,16 @@ public class LTTngTrace extends TmfTrace { /** * Method to convert a JniEvent into a LttngEvent * - * @param jniEvent - * The JniEvent to convert into LttngEvent - * @param isParsingNeeded - * A boolean value telling if the event should be parsed or not. + * @param jniEvent The JniEvent to convert into LttngEvent + * @param isParsingNeeded A boolean value telling if the event should be + * parsed or not. * * @return The converted LttngEvent * * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent * @see org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent */ - public synchronized LttngEvent convertJniEventToTmf(JniEvent jniEvent, boolean isParsingNeeded) { + public synchronized LttngEvent convertJniEventToTmf(final JniEvent jniEvent, final boolean isParsingNeeded) { if (UNIQUE_EVENT) { @@ -907,8 +875,8 @@ public class LTTngTrace extends TmfTrace { eventType = traceTypes.get(EventTypeKey.getEventTypeHash(jniEvent)); - String fullTracePath = getName(); - String reference = fullTracePath.substring(fullTracePath.lastIndexOf('/') + 1); + final String fullTracePath = getName(); + final String reference = fullTracePath.substring(fullTracePath.lastIndexOf('/') + 1); currentLttngEvent.setReference(reference); eventContent.emptyContent(); @@ -919,26 +887,25 @@ public class LTTngTrace extends TmfTrace { // Parse now if was asked // Warning : THIS IS SLOW - if (isParsingNeeded) { + if (isParsingNeeded) eventContent.getFields(); - } return currentLttngEvent; - } else { + } else return convertJniEventToTmfMultipleEventEvilFix(jniEvent, isParsingNeeded); - } } /** - * This method is a temporary fix to support multiple events at once in TMF This is expected to be slow and should - * be fixed in another way. See comment in convertJniEventToTmf(); + * This method is a temporary fix to support multiple events at once in TMF + * This is expected to be slow and should be fixed in another way. See + * comment in convertJniEventToTmf(); * - * @param jniEvent - * The current JNI Event + * @param jniEvent The current JNI Event * @return Current Lttng Event fully parsed */ - private synchronized LttngEvent convertJniEventToTmfMultipleEventEvilFix(JniEvent jniEvent, boolean isParsingNeeded) { + private synchronized LttngEvent convertJniEventToTmfMultipleEventEvilFix(final JniEvent jniEvent, + final boolean isParsingNeeded) { // *** HACK *** // Below : the "fix" with all the new and the full-parse // Allocating new memory is slow. @@ -960,9 +927,8 @@ public class LTTngTrace extends TmfTrace { // *** WARNING *** // ONLY for testing, NOT parsing events with non-unique events WILL // result in segfault in the JVM - if (isParsingNeeded) { + if (isParsingNeeded) eventContent.getFields(); - } return currentLttngEvent; } @@ -971,7 +937,8 @@ public class LTTngTrace extends TmfTrace { * Reference to the current LttngTrace we are reading from. *

* - * Note : This bypass the framework and should not be use, except for testing! + * Note : This bypass the framework and should not be use, except for + * testing! * * @return Reference to the current LttngTrace * @@ -1001,11 +968,10 @@ public class LTTngTrace extends TmfTrace { * */ public short getVersionMajor() { - if (currentJniTrace != null) { + if (currentJniTrace != null) return currentJniTrace.getLttMajorVersion(); - } else { + else return -1; - } } /** @@ -1017,11 +983,10 @@ public class LTTngTrace extends TmfTrace { * */ public short getVersionMinor() { - if (currentJniTrace != null) { + if (currentJniTrace != null) return currentJniTrace.getLttMinorVersion(); - } else { + else return -1; - } } /** @@ -1033,11 +998,10 @@ public class LTTngTrace extends TmfTrace { * */ public int getCpuNumber() { - if (currentJniTrace != null) { + if (currentJniTrace != null) return currentJniTrace.getCpuNumber(); - } else { + else return -1; - } } /** @@ -1088,9 +1052,11 @@ public class LTTngTrace extends TmfTrace { /* * EventTypeKey inner class * - * This class is used to make the process of generating the HashMap key more transparent and so less error prone to use + * This class is used to make the process of generating the HashMap key more + * transparent and so less error prone to use */ final class EventTypeKey { + // *** WARNING *** // These two getEventTypeKey() functions should ALWAYS construct the key the // same ways! @@ -1099,19 +1065,19 @@ final class EventTypeKey { // added final to encourage inlining. // generating a hash code by hand to avoid a string creation - final static public int getEventTypeHash(LttngEventType newEventType) { + final static public int getEventTypeHash(final LttngEventType newEventType) { return generateHash(newEventType.getTracefileName(), newEventType.getCpuId(), newEventType.getMarkerName()); } - final private static int generateHash(String traceFileName, long cpuNumber, String markerName) { + final private static int generateHash(final String traceFileName, final long cpuNumber, final String markerName) { // 0x1337 is a prime number. The number of CPUs is always under 8192 on // the current kernel, so this will work with the current linux kernel. - int cpuHash = (int) (cpuNumber * (0x1337)); + final int cpuHash = (int) (cpuNumber * (0x1337)); return traceFileName.hashCode() ^ (cpuHash) ^ markerName.hashCode(); } // generating a hash code by hand to avoid a string creation - final static public int getEventTypeHash(JniEvent newEvent) { + final static public int getEventTypeHash(final JniEvent newEvent) { return generateHash(newEvent.getParentTracefile().getTracefileName(), newEvent.getParentTracefile() .getCpuNumber(), newEvent.requestEventMarker().getName()); } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java index 713fb3713d..4ecf554fd7 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java @@ -217,6 +217,8 @@ public class TmfEventFieldTest extends TestCase { assertSame("getValue", fValue1, myField.getValue()); myField.setValue(fValue2, null); assertSame("getValue", fValue2, myField.getValue()); + myField.setValue(fValue2, new TmfEventField[] { field }); + assertSame("getValue", fValue2, myField.getValue()); } // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java index 54812aa796..558211dd7f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 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 @@ -16,6 +16,7 @@ import junit.framework.TestCase; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; +import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; @@ -27,212 +28,248 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; @SuppressWarnings("nls") public class TmfContextTest extends TestCase { - // ------------------------------------------------------------------------ - // Variables - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // Variables + // ------------------------------------------------------------------------ + + final String aString = "some location"; + final Long aLong = 12345L; + final TmfTimestamp aTimestamp = new TmfTimestamp(); - final String aString = "some location"; - final Long aLong = 12345L; - final TmfTimestamp aTimestamp = new TmfTimestamp(); + final TmfLocation fLocation1 = new TmfLocation(aString); + final TmfLocation fLocation2 = new TmfLocation(aLong); + final TmfLocation fLocation3 = new TmfLocation(aTimestamp); - final TmfLocation fLocation1 = new TmfLocation(aString); - final TmfLocation fLocation2 = new TmfLocation(aLong); - final TmfLocation fLocation3 = new TmfLocation(aTimestamp); + final long fRank1 = 1; + final long fRank2 = 2; + final long fRank3 = 3; + + final TmfContext fContext1 = new TmfContext(fLocation1, fRank1); + final TmfContext fContext2 = new TmfContext(fLocation2, fRank2); + final TmfContext fContext3 = new TmfContext(fLocation3, fRank3); - final long fRank1 = 1; - final long fRank2 = 2; - final long fRank3 = 3; - - final TmfContext fContext1 = new TmfContext(fLocation1, fRank1); - final TmfContext fContext2 = new TmfContext(fLocation2, fRank2); - final TmfContext fContext3 = new TmfContext(fLocation3, fRank3); - // ------------------------------------------------------------------------ // Housekeeping // ------------------------------------------------------------------------ - /** - * @param name the test name - */ - public TmfContextTest(String name) { - super(name); - } + /** + * @param name the test name + */ + public TmfContextTest(final String name) { + super(name); + } - @Override - protected void setUp() throws Exception { - super.setUp(); - } + @Override + protected void setUp() throws Exception { + super.setUp(); + } - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ - public void testTmfContextDefault() { - TmfContext context = new TmfContext(); - assertEquals("getLocation", null, context.getLocation()); - assertEquals("getRank", TmfContext.UNKNOWN_RANK, context.getRank()); - } + public void testTmfContextDefault() { + final TmfContext context = new TmfContext(); + assertEquals("getLocation", null, context.getLocation()); + assertEquals("getRank", TmfContext.UNKNOWN_RANK, context.getRank()); + } + + public void testTmfContextNoRank() { + final TmfContext context1 = new TmfContext(fLocation1); + final TmfContext context2 = new TmfContext(fLocation2); + final TmfContext context3 = new TmfContext(fLocation3); + + assertEquals("getLocation", fLocation1, context1.getLocation()); + assertEquals("getLocation", fLocation2, context2.getLocation()); + assertEquals("getLocation", fLocation3, context3.getLocation()); + + assertEquals("getRank", TmfContext.UNKNOWN_RANK, context1.getRank()); + assertEquals("getRank", TmfContext.UNKNOWN_RANK, context2.getRank()); + assertEquals("getRank", TmfContext.UNKNOWN_RANK, context3.getRank()); + } + + public void testTmfContext() { + assertEquals("getLocation", fLocation1, fContext1.getLocation()); + assertEquals("getLocation", fLocation2, fContext2.getLocation()); + assertEquals("getLocation", fLocation3, fContext3.getLocation()); + + assertEquals("getRank", fRank1, fContext1.getRank()); + assertEquals("getRank", fRank2, fContext2.getRank()); + assertEquals("getRank", fRank3, fContext3.getRank()); + } + + public void testTmfContextCopy() { + final TmfContext context1 = new TmfContext(fContext1); + final TmfContext context2 = new TmfContext(fContext2); + final TmfContext context3 = new TmfContext(fContext3); + + assertEquals("getLocation", fLocation1, context1.getLocation()); + assertEquals("getLocation", fLocation2, context2.getLocation()); + assertEquals("getLocation", fLocation3, context3.getLocation()); + + assertEquals("getRank", fRank1, context1.getRank()); + assertEquals("getRank", fRank2, context2.getRank()); + assertEquals("getRank", fRank3, context3.getRank()); + } + + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ + + public void testEqualsReflexivity() throws Exception { + assertTrue("equals", fContext1.equals(fContext1)); + assertTrue("equals", fContext2.equals(fContext2)); + + assertFalse("equals", fContext1.equals(fContext2)); + assertFalse("equals", fContext2.equals(fContext1)); + } + + public void testEqualsSymmetry() throws Exception { + final TmfContext context1 = new TmfContext(fContext1); + final TmfContext context2 = new TmfContext(fContext2); - public void testTmfContextNoRank() { - TmfContext context1 = new TmfContext(fLocation1); - TmfContext context2 = new TmfContext(fLocation2); - TmfContext context3 = new TmfContext(fLocation3); + assertTrue("equals", context1.equals(fContext1)); + assertTrue("equals", fContext1.equals(context1)); - assertEquals("getLocation", fLocation1, context1.getLocation()); - assertEquals("getLocation", fLocation2, context2.getLocation()); - assertEquals("getLocation", fLocation3, context3.getLocation()); + assertTrue("equals", context2.equals(fContext2)); + assertTrue("equals", fContext2.equals(context2)); + } - assertEquals("getRank", TmfContext.UNKNOWN_RANK, context1.getRank()); - assertEquals("getRank", TmfContext.UNKNOWN_RANK, context2.getRank()); - assertEquals("getRank", TmfContext.UNKNOWN_RANK, context3.getRank()); - } + public void testEqualsTransivity() throws Exception { + final TmfContext context1 = new TmfContext(fContext1); + final TmfContext context2 = new TmfContext(context1); + final TmfContext context3 = new TmfContext(context2); - public void testTmfContext() { - assertEquals("getLocation", fLocation1, fContext1.getLocation()); - assertEquals("getLocation", fLocation2, fContext2.getLocation()); - assertEquals("getLocation", fLocation3, fContext3.getLocation()); + assertTrue("equals", context1.equals(context2)); + assertTrue("equals", context2.equals(context3)); + assertTrue("equals", context1.equals(context3)); + } - assertEquals("getRank", fRank1, fContext1.getRank()); - assertEquals("getRank", fRank2, fContext2.getRank()); - assertEquals("getRank", fRank3, fContext3.getRank()); - } + public void testEqualsNull() throws Exception { + assertFalse("equals", fContext1.equals(null)); + assertFalse("equals", fContext2.equals(null)); + } - public void testTmfContextCopy() { - TmfContext context1 = new TmfContext(fContext1); - TmfContext context2 = new TmfContext(fContext2); - TmfContext context3 = new TmfContext(fContext3); + public class MyContext extends TmfContext { + } - assertEquals("getLocation", fLocation1, context1.getLocation()); - assertEquals("getLocation", fLocation2, context2.getLocation()); - assertEquals("getLocation", fLocation3, context3.getLocation()); + public void testNonEquals() throws Exception { - assertEquals("getRank", fRank1, context1.getRank()); - assertEquals("getRank", fRank2, context2.getRank()); - assertEquals("getRank", fRank3, context3.getRank()); - } + // Different classes + final MyContext myContext = new MyContext(); + assertFalse("equals", fContext1.equals(myContext)); + assertFalse("equals", myContext.equals(fContext1)); + + // Different locations + TmfContext context1 = new TmfContext(fContext1); + TmfContext context2 = new TmfContext(fContext1); + context1.setLocation(null); + context2.setLocation(null); + + assertFalse("equals", fContext1.equals(context1)); + assertFalse("equals", context1.equals(fContext1)); + assertTrue("equals", context1.equals(context2)); + + // Different ranks + context1 = new TmfContext(fContext1); + context2 = new TmfContext(fContext1); + context1.setRank(fContext1.getRank() + 1); + context2.setRank(fContext1.getRank() + 2); + + assertFalse("equals", fContext1.equals(context1)); + assertFalse("equals", context1.equals(fContext1)); + assertFalse("equals", context1.equals(context2)); + } // ------------------------------------------------------------------------ - // equals + // hashCode // ------------------------------------------------------------------------ - public void testEqualsReflexivity() throws Exception { - assertTrue("equals", fContext1.equals(fContext1)); - assertTrue("equals", fContext2.equals(fContext2)); - - assertTrue("equals", !fContext1.equals(fContext2)); - assertTrue("equals", !fContext2.equals(fContext1)); - } - - public void testEqualsSymmetry() throws Exception { - TmfContext context1 = new TmfContext(fContext1); - TmfContext context2 = new TmfContext(fContext2); - - assertTrue("equals", context1.equals(fContext1)); - assertTrue("equals", fContext1.equals(context1)); - - assertTrue("equals", context2.equals(fContext2)); - assertTrue("equals", fContext2.equals(context2)); - } - - public void testEqualsTransivity() throws Exception { - TmfContext context1 = new TmfContext(fContext1); - TmfContext context2 = new TmfContext(context1); - TmfContext context3 = new TmfContext(context2); - - assertTrue("equals", context1.equals(context2)); - assertTrue("equals", context2.equals(context3)); - assertTrue("equals", context1.equals(context3)); - } - - public void testEqualsNull() throws Exception { - assertTrue("equals", !fContext1.equals(null)); - assertTrue("equals", !fContext2.equals(null)); - } - - // ------------------------------------------------------------------------ - // hashCode - // ------------------------------------------------------------------------ - - public void testHashCode() throws Exception { - TmfContext context1 = new TmfContext(fContext1); - TmfContext context2 = new TmfContext(fContext2); - - assertTrue("hashCode", fContext1.hashCode() == context1.hashCode()); - assertTrue("hashCode", fContext2.hashCode() == context2.hashCode()); - - assertTrue("hashCode", fContext1.hashCode() != context2.hashCode()); - assertTrue("hashCode", fContext2.hashCode() != context1.hashCode()); - } - + public void testHashCode() throws Exception { + final TmfContext context1 = new TmfContext(fContext1); + final TmfContext context2 = new TmfContext(fContext2); + + assertEquals("hashCode", fContext1.hashCode(), context1.hashCode()); + assertEquals("hashCode", fContext2.hashCode(), context2.hashCode()); + + assertFalse("hashCode", fContext1.hashCode() == context2.hashCode()); + assertFalse("hashCode", fContext2.hashCode() == context1.hashCode()); + + final TmfContext nullContext1 = new TmfContext(); + final TmfContext nullContext2 = new TmfContext(nullContext1); + assertEquals("hashCode", nullContext1.hashCode(), nullContext2.hashCode()); + } + // ------------------------------------------------------------------------ // toString // ------------------------------------------------------------------------ - public void testToString() { - String expected1 = "[TmfContext(" + fLocation1 + "," + 1 + ")]"; - String expected2 = "[TmfContext(" + fLocation2 + "," + 2 + ")]"; - String expected3 = "[TmfContext(" + fLocation3 + "," + 3 + ")]"; + public void testToString() { + final String expected1 = "TmfContext [fLocation=" + fLocation1 + ", fRank=" + 1 + "]"; + final String expected2 = "TmfContext [fLocation=" + fLocation2 + ", fRank=" + 2 + "]"; + final String expected3 = "TmfContext [fLocation=" + fLocation3 + ", fRank=" + 3 + "]"; - assertEquals("toString", expected1, fContext1.toString()); - assertEquals("toString", expected2, fContext2.toString()); - assertEquals("toString", expected3, fContext3.toString()); - } + assertEquals("toString", expected1, fContext1.toString()); + assertEquals("toString", expected2, fContext2.toString()); + assertEquals("toString", expected3, fContext3.toString()); + } // ------------------------------------------------------------------------ // clone // ------------------------------------------------------------------------ - public void testClone() { - try { - TmfContext context1 = fContext1.clone(); - TmfContext context2 = fContext2.clone(); - TmfContext context3 = fContext3.clone(); + public void testClone() { + try { + final TmfContext context1 = fContext1.clone(); + final TmfContext context2 = fContext2.clone(); + final TmfContext context3 = fContext3.clone(); - assertEquals("clone", context1, fContext1); - assertEquals("clone", context2, fContext2); - assertEquals("clone", context3, fContext3); - } - catch (InternalError e) { - fail("clone()"); - } - } + assertEquals("clone", context1, fContext1); + assertEquals("clone", context2, fContext2); + assertEquals("clone", context3, fContext3); + } catch (final InternalError e) { + fail("clone()"); + } + } // ------------------------------------------------------------------------ // setLocation, setRank, updateRank // ------------------------------------------------------------------------ - public void testSetLocation() { - TmfContext context1 = new TmfContext(fContext1); - context1.setLocation(fContext2.getLocation()); - - assertEquals("getLocation", fLocation2, context1.getLocation()); - assertEquals("getRank", 1, context1.getRank()); - } + public void testSetLocation() { + final TmfContext context1 = new TmfContext(fContext1); + context1.setLocation(fContext2.getLocation()); - public void testSetRank() { - TmfContext context1 = new TmfContext(fContext1); - context1.setRank(fContext2.getRank()); + assertEquals("getLocation", fLocation2, context1.getLocation()); + assertEquals("getRank", 1, context1.getRank()); + } - assertEquals("getLocation", fLocation1, context1.getLocation()); - assertEquals("getRank", fRank2, context1.getRank()); - } + public void testSetRank() { + final TmfContext context1 = new TmfContext(fContext1); + context1.setRank(fContext2.getRank()); - public void testUpdatetRank() { - TmfContext context1 = new TmfContext(fContext1); + assertEquals("getLocation", fLocation1, context1.getLocation()); + assertEquals("getRank", fRank2, context1.getRank()); + } - context1.updateRank(0); - assertEquals("getRank", fRank1, context1.getRank()); + public void testIncreaseRank() { + final TmfContext context1 = new TmfContext(fContext1); - context1.updateRank(-1); - assertEquals("getRank", fRank1 - 1, context1.getRank()); + context1.increaseRank(); + assertEquals("getRank", fRank1 + 1, context1.getRank()); + context1.increaseRank(); + assertEquals("getRank", fRank1 + 2, context1.getRank()); - context1.updateRank(2); - assertEquals("getRank", fRank1 + 1, context1.getRank()); - } + context1.setRank(ITmfContext.UNKNOWN_RANK); + context1.increaseRank(); + assertEquals("getRank", ITmfContext.UNKNOWN_RANK, context1.getRank()); + context1.increaseRank(); + assertEquals("getRank", ITmfContext.UNKNOWN_RANK, context1.getRank()); + } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java index 8a7a12b3e8..8b56ceb34a 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java @@ -108,12 +108,12 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, } @Override - public void updateRank(int rank) { - curRank = rank; + public void increaseRank() { + curRank++; } @Override - public boolean isValidRank() { + public boolean hasValidRank() { return true; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java index 1aa669b2d4..bbaa8fe085 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java @@ -47,7 +47,8 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfContext; /** * TmfExperiment *

- * TmfExperiment presents a time-ordered, unified view of a set of TmfTraces that are part of a tracing experiment. + * TmfExperiment presents a time-ordered, unified view of a set of TmfTraces + * that are part of a tracing experiment. *

*/ public class TmfExperiment extends TmfEventProvider implements ITmfTrace { @@ -96,12 +97,12 @@ public class TmfExperiment extends TmfEventProvider impl } @Override - public boolean validate(IProject project, String path) { + public boolean validate(final IProject project, final String path) { return true; } @Override - public void initTrace(String name, String path, Class eventType) { + public void initTrace(final String name, final String path, final Class eventType) { } /** @@ -111,11 +112,13 @@ public class TmfExperiment extends TmfEventProvider impl * @param epoch * @param indexPageSize */ - public TmfExperiment(Class type, String id, ITmfTrace[] traces, ITmfTimestamp epoch, int indexPageSize) { + public TmfExperiment(final Class type, final String id, final ITmfTrace[] traces, final ITmfTimestamp epoch, + final int indexPageSize) { this(type, id, traces, TmfTimestamp.ZERO, indexPageSize, false); } - public TmfExperiment(Class type, String id, ITmfTrace[] traces, ITmfTimestamp epoch, int indexPageSize, boolean preIndexExperiment) { + public TmfExperiment(final Class type, final String id, final ITmfTrace[] traces, final ITmfTimestamp epoch, + final int indexPageSize, final boolean preIndexExperiment) { super(id, type); fTraces = traces; @@ -129,7 +132,7 @@ public class TmfExperiment extends TmfEventProvider impl } } - protected TmfExperiment(String id, Class type) { + protected TmfExperiment(final String id, final Class type) { super(id, type); } @@ -138,7 +141,7 @@ public class TmfExperiment extends TmfEventProvider impl * @param id * @param traces */ - public TmfExperiment(Class type, String id, ITmfTrace[] traces) { + public TmfExperiment(final Class type, final String id, final ITmfTrace[] traces) { this(type, id, traces, TmfTimestamp.ZERO, DEFAULT_INDEX_PAGE_SIZE); } @@ -148,7 +151,7 @@ public class TmfExperiment extends TmfEventProvider impl * @param traces * @param indexPageSize */ - public TmfExperiment(Class type, String id, ITmfTrace[] traces, int indexPageSize) { + public TmfExperiment(final Class type, final String id, final ITmfTrace[] traces, final int indexPageSize) { this(type, id, traces, TmfTimestamp.ZERO, indexPageSize); } @@ -159,21 +162,18 @@ public class TmfExperiment extends TmfEventProvider impl @SuppressWarnings("rawtypes") public synchronized void dispose() { - TmfExperimentDisposedSignal signal = new TmfExperimentDisposedSignal(this, this); + final TmfExperimentDisposedSignal signal = new TmfExperimentDisposedSignal(this, this); broadcast(signal); - if (fCurrentExperiment == this) { + if (fCurrentExperiment == this) fCurrentExperiment = null; - } if (fTraces != null) { - for (ITmfTrace trace : fTraces) { + for (final ITmfTrace trace : fTraces) trace.dispose(); - } fTraces = null; } - if (fCheckpoints != null) { + if (fCheckpoints != null) fCheckpoints.clear(); - } super.dispose(); } @@ -214,10 +214,9 @@ public class TmfExperiment extends TmfEventProvider impl // Accessors // ------------------------------------------------------------------------ - public static void setCurrentExperiment(TmfExperiment experiment) { - if (fCurrentExperiment != null && fCurrentExperiment != experiment) { + public static void setCurrentExperiment(final TmfExperiment experiment) { + if (fCurrentExperiment != null && fCurrentExperiment != experiment) fCurrentExperiment.dispose(); - } fCurrentExperiment = experiment; } @@ -234,27 +233,28 @@ public class TmfExperiment extends TmfEventProvider impl } /** - * Returns the rank of the first event with the requested timestamp. If none, returns the index of the next event - * (if any). + * Returns the rank of the first event with the requested timestamp. If + * none, returns the index of the next event (if any). * * @param timestamp the event timestamp * @return the corresponding event rank */ @Override - public long getRank(ITmfTimestamp timestamp) { - TmfExperimentContext context = seekEvent(timestamp); + public long getRank(final ITmfTimestamp timestamp) { + final TmfExperimentContext context = seekEvent(timestamp); return context.getRank(); } /** - * Returns the timestamp of the event at the requested index. If none, returns null. + * Returns the timestamp of the event at the requested index. If none, + * returns null. * * @param index the event index (rank) * @return the corresponding event timestamp */ - public ITmfTimestamp getTimestamp(int index) { - TmfExperimentContext context = seekEvent(index); - ITmfEvent event = getNextEvent(context); + public ITmfTimestamp getTimestamp(final int index) { + final TmfExperimentContext context = seekEvent(index); + final ITmfEvent event = getNextEvent(context); return (event != null) ? event.getTimestamp() : null; } @@ -266,14 +266,15 @@ public class TmfExperiment extends TmfEventProvider impl * Update the global time range */ protected void updateTimeRange() { - ITmfTimestamp startTime = fTimeRange != TmfTimeRange.NULL_RANGE ? fTimeRange.getStartTime() : TmfTimestamp.BIG_CRUNCH; + ITmfTimestamp startTime = fTimeRange != TmfTimeRange.NULL_RANGE ? fTimeRange.getStartTime() + : TmfTimestamp.BIG_CRUNCH; ITmfTimestamp endTime = fTimeRange != TmfTimeRange.NULL_RANGE ? fTimeRange.getEndTime() : TmfTimestamp.BIG_BANG; - for (ITmfTrace trace : fTraces) { - ITmfTimestamp traceStartTime = trace.getStartTime(); + for (final ITmfTrace trace : fTraces) { + final ITmfTimestamp traceStartTime = trace.getStartTime(); if (traceStartTime.compareTo(startTime, true) < 0) startTime = traceStartTime; - ITmfTimestamp traceEndTime = trace.getEndTime(); + final ITmfTimestamp traceEndTime = trace.getEndTime(); if (traceEndTime.compareTo(endTime, true) > 0) endTime = traceEndTime; } @@ -284,39 +285,35 @@ public class TmfExperiment extends TmfEventProvider impl // TmfProvider // ------------------------------------------------------------------------ @Override - public ITmfContext armRequest(ITmfDataRequest request) { + public ITmfContext armRequest(final ITmfDataRequest request) { // Tracer.trace("Ctx: Arming request - start"); - ITmfTimestamp timestamp = (request instanceof ITmfEventRequest) ? ((ITmfEventRequest) request).getRange().getStartTime() + ITmfTimestamp timestamp = (request instanceof ITmfEventRequest) ? ((ITmfEventRequest) request).getRange() + .getStartTime() : null; - if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0) { + if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0) timestamp = null; // use request index - } TmfExperimentContext context = null; if (timestamp != null) { // seek by timestamp context = seekEvent(timestamp); ((ITmfEventRequest) request).setStartIndex((int) context.getRank()); - } else { - // Seek by rank - if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex()) { - // We are already at the right context -> no need to seek - context = fExperimentContext; - } else { - context = seekEvent(request.getIndex()); - } - } + } else // Seek by rank + if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex()) + // We are already at the right context -> no need to seek + context = fExperimentContext; + else + context = seekEvent(request.getIndex()); // Tracer.trace("Ctx: Arming request - done"); return context; } @SuppressWarnings("unchecked") @Override - public T getNext(ITmfContext context) { - if (context instanceof TmfExperimentContext) { - return (T) getNextEvent((TmfExperimentContext) context); - } + public T getNext(final ITmfContext context) { + if (context instanceof TmfExperimentContext) + return (T) getNextEvent(context); return null; } @@ -327,29 +324,28 @@ public class TmfExperiment extends TmfEventProvider impl // Returns a brand new context based on the location provided // and initializes the event queues @Override - public synchronized TmfExperimentContext seekLocation(ITmfLocation location) { + public synchronized TmfExperimentContext seekLocation(final ITmfLocation location) { // Validate the location - if (location != null && !(location instanceof TmfExperimentLocation)) { + if (location != null && !(location instanceof TmfExperimentLocation)) return null; // Throw an exception? - } - if (fTraces == null) { // experiment has been disposed + if (fTraces == null) return null; - } // Instantiate the location - TmfExperimentLocation expLocation = (location == null) ? new TmfExperimentLocation(new TmfLocationArray( - new ITmfLocation[fTraces.length]), new long[fTraces.length]) : (TmfExperimentLocation) location.clone(); + final TmfExperimentLocation expLocation = (location == null) ? new TmfExperimentLocation(new TmfLocationArray( + new ITmfLocation[fTraces.length]), new long[fTraces.length]) : (TmfExperimentLocation) location + .clone(); // Create and populate the context's traces contexts - TmfExperimentContext context = new TmfExperimentContext(fTraces, new TmfContext[fTraces.length]); + final TmfExperimentContext context = new TmfExperimentContext(fTraces, new TmfContext[fTraces.length]); // Tracer.trace("Ctx: SeekLocation - start"); long rank = 0; for (int i = 0; i < fTraces.length; i++) { // Get the relevant trace attributes - ITmfLocation traceLocation = expLocation.getLocation().locations[i]; - long traceRank = expLocation.getRanks()[i]; + final ITmfLocation traceLocation = expLocation.getLocation().locations[i]; + final long traceRank = expLocation.getRanks()[i]; // Set the corresponding sub-context context.getContexts()[i] = fTraces[i].seekLocation(traceLocation); @@ -357,8 +353,10 @@ public class TmfExperiment extends TmfEventProvider impl rank += traceRank; // Set the trace location and read the corresponding event - /* The (TmfContext) cast should be safe since we created 'context' - * ourselves higher up. */ + /* + * The (TmfContext) cast should be safe since we created 'context' + * ourselves higher up. + */ expLocation.getLocation().locations[i] = ((TmfContext) context.getContexts()[i]).getLocation().clone(); context.getEvents()[i] = fTraces[i].getNextEvent(context.getContexts()[i]); } @@ -378,16 +376,17 @@ public class TmfExperiment extends TmfEventProvider impl /* * (non-Javadoc) * - * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools .tmf.event.TmfTimestamp) + * @see + * org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools + * .tmf.event.TmfTimestamp) */ @Override public synchronized TmfExperimentContext seekEvent(ITmfTimestamp timestamp) { // Tracer.trace("Ctx: seekEvent(TS) - start"); - if (timestamp == null) { + if (timestamp == null) timestamp = TmfTimestamp.BIG_BANG; - } // First, find the right checkpoint int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null)); @@ -395,24 +394,21 @@ public class TmfExperiment extends TmfEventProvider impl // In the very likely case that the checkpoint was not found, bsearch // returns its negated would-be location (not an offset...). From that // index, we can then position the stream and get the event. - if (index < 0) { + if (index < 0) index = Math.max(0, -(index + 2)); - } // Position the experiment at the checkpoint ITmfLocation location; synchronized (fCheckpoints) { if (fCheckpoints.size() > 0) { - if (index >= fCheckpoints.size()) { + if (index >= fCheckpoints.size()) index = fCheckpoints.size() - 1; - } location = fCheckpoints.elementAt(index).getLocation(); - } else { + } else location = null; - } } - TmfExperimentContext context = seekLocation(location); + final TmfExperimentContext context = seekLocation(location); context.setRank((long) index * fIndexPageSize); // And locate the event @@ -436,7 +432,7 @@ public class TmfExperiment extends TmfEventProvider impl * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long) */ @Override - public synchronized TmfExperimentContext seekEvent(long rank) { + public synchronized TmfExperimentContext seekEvent(final long rank) { // Tracer.trace("Ctx: seekEvent(rank) - start"); @@ -444,17 +440,16 @@ public class TmfExperiment extends TmfEventProvider impl int index = (int) rank / fIndexPageSize; ITmfLocation location; synchronized (fCheckpoints) { - if (fCheckpoints.size() == 0) { + if (fCheckpoints.size() == 0) location = null; - } else { - if (index >= fCheckpoints.size()) { + else { + if (index >= fCheckpoints.size()) index = fCheckpoints.size() - 1; - } location = fCheckpoints.elementAt(index).getLocation(); } } - TmfExperimentContext context = seekLocation(location); + final TmfExperimentContext context = seekLocation(location); context.setRank((long) index * fIndexPageSize); // And locate the event @@ -474,24 +469,22 @@ public class TmfExperiment extends TmfEventProvider impl } @Override - public TmfContext seekLocation(double ratio) { - TmfContext context = seekEvent((long) (ratio * getNbEvents())); + public TmfContext seekLocation(final double ratio) { + final TmfContext context = seekEvent((long) (ratio * getNbEvents())); return context; } @Override - public double getLocationRatio(ITmfLocation location) { - if (location instanceof TmfExperimentLocation) { + public double getLocationRatio(final ITmfLocation location) { + if (location instanceof TmfExperimentLocation) return (double) seekLocation(location).getRank() / getNbEvents(); - } return 0; } @Override public ITmfLocation getCurrentLocation() { - if (fExperimentContext != null) { + if (fExperimentContext != null) return fExperimentContext.getLocation(); - } return null; } @@ -513,42 +506,39 @@ public class TmfExperiment extends TmfEventProvider impl // } /** - * Scan the next events from all traces and return the next one in chronological order. + * Scan the next events from all traces and return the next one in + * chronological order. * * @param context the trace context * @return the next event */ - @SuppressWarnings("unchecked") @Override - public synchronized ITmfEvent getNextEvent(ITmfContext context) { + public synchronized ITmfEvent getNextEvent(final ITmfContext context) { // Validate the context - if (!(context instanceof TmfExperimentContext)) { + if (!(context instanceof TmfExperimentContext)) return null; // Throw an exception? - } - if (!context.equals(fExperimentContext)) { -// Tracer.trace("Ctx: Restoring context"); + if (!context.equals(fExperimentContext)) + // Tracer.trace("Ctx: Restoring context"); fExperimentContext = seekLocation(context.getLocation()); - } - TmfExperimentContext expContext = (TmfExperimentContext) context; + final TmfExperimentContext expContext = (TmfExperimentContext) context; // dumpContext(expContext, true); // If an event was consumed previously, get the next one from that trace - int lastTrace = expContext.getLastTrace(); + final int lastTrace = expContext.getLastTrace(); if (lastTrace != TmfExperimentContext.NO_TRACE) { - ITmfContext traceContext = expContext.getContexts()[lastTrace]; + final ITmfContext traceContext = expContext.getContexts()[lastTrace]; expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].getNextEvent(traceContext); expContext.setLastTrace(TmfExperimentContext.NO_TRACE); } // Scan the candidate events and identify the "next" trace to read from - ITmfEvent eventArray[] = expContext.getEvents(); - if (eventArray == null) { + final ITmfEvent eventArray[] = expContext.getEvents(); + if (eventArray == null) return null; - } int trace = TmfExperimentContext.NO_TRACE; ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH; if (eventArray.length == 1) { @@ -556,33 +546,32 @@ public class TmfExperiment extends TmfEventProvider impl timestamp = eventArray[0].getTimestamp(); trace = 0; } - } else { + } else for (int i = 0; i < eventArray.length; i++) { - ITmfEvent event = eventArray[i]; + final ITmfEvent event = eventArray[i]; if (event != null && event.getTimestamp() != null) { - ITmfTimestamp otherTS = event.getTimestamp(); + final ITmfTimestamp otherTS = event.getTimestamp(); if (otherTS.compareTo(timestamp, true) < 0) { trace = i; timestamp = otherTS; } } } - } // Update the experiment context and set the "next" event ITmfEvent event = null; if (trace != TmfExperimentContext.NO_TRACE) { updateIndex(expContext, timestamp); - ITmfContext traceContext = expContext.getContexts()[trace]; - TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation(); + final ITmfContext traceContext = expContext.getContexts()[trace]; + final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation(); // expLocation.getLocation()[trace] = traceContext.getLocation().clone(); - expLocation.getLocation().locations[trace] = (ITmfLocation>) traceContext.getLocation().clone(); + expLocation.getLocation().locations[trace] = traceContext.getLocation().clone(); // updateIndex(expContext, timestamp); expLocation.getRanks()[trace] = traceContext.getRank(); expContext.setLastTrace(trace); - expContext.updateRank(1); + expContext.increaseRank(); event = expContext.getEvents()[trace]; fExperimentContext = expContext; } @@ -596,15 +585,15 @@ public class TmfExperiment extends TmfEventProvider impl return event; } - public synchronized void updateIndex(ITmfContext context, ITmfTimestamp timestamp) { + public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) { // Build the index as we go along - long rank = context.getRank(); - if (context.isValidRank() && (rank % fIndexPageSize) == 0) { + final long rank = context.getRank(); + if (context.hasValidRank() && (rank % fIndexPageSize) == 0) { // Determine the table position - long position = rank / fIndexPageSize; + final long position = rank / fIndexPageSize; // Add new entry at proper location (if empty) if (fCheckpoints.size() == position) { - ITmfLocation location = context.getLocation().clone(); + final ITmfLocation location = context.getLocation().clone(); fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location)); // System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " // + location.toString()); @@ -615,27 +604,27 @@ public class TmfExperiment extends TmfEventProvider impl /* * (non-Javadoc) * - * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools .tmf.trace.TmfContext) + * @see + * org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools + * .tmf.trace.TmfContext) */ @Override - public ITmfEvent parseEvent(ITmfContext context) { + public ITmfEvent parseEvent(final ITmfContext context) { // Validate the context - if (!(context instanceof TmfExperimentContext)) { + if (!(context instanceof TmfExperimentContext)) return null; // Throw an exception? - } - if (!context.equals(fExperimentContext)) { -// Tracer.trace("Ctx: Restoring context"); + if (!context.equals(fExperimentContext)) + // Tracer.trace("Ctx: Restoring context"); seekLocation(context.getLocation()); - } - TmfExperimentContext expContext = (TmfExperimentContext) context; + final TmfExperimentContext expContext = (TmfExperimentContext) context; // If an event was consumed previously, get the next one from that trace - int lastTrace = expContext.getLastTrace(); + final int lastTrace = expContext.getLastTrace(); if (lastTrace != TmfExperimentContext.NO_TRACE) { - ITmfContext traceContext = expContext.getContexts()[lastTrace]; + final ITmfContext traceContext = expContext.getContexts()[lastTrace]; expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].getNextEvent(traceContext); expContext.setLastTrace(TmfExperimentContext.NO_TRACE); fExperimentContext = (TmfExperimentContext) context; @@ -645,9 +634,9 @@ public class TmfExperiment extends TmfEventProvider impl int trace = TmfExperimentContext.NO_TRACE; ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH; for (int i = 0; i < expContext.getTraces().length; i++) { - ITmfEvent event = expContext.getEvents()[i]; + final ITmfEvent event = expContext.getEvents()[i]; if (event != null && event.getTimestamp() != null) { - ITmfTimestamp otherTS = event.getTimestamp(); + final ITmfTimestamp otherTS = event.getTimestamp(); if (otherTS.compareTo(timestamp, true) < 0) { trace = i; timestamp = otherTS; @@ -656,9 +645,8 @@ public class TmfExperiment extends TmfEventProvider impl } ITmfEvent event = null; - if (trace != TmfExperimentContext.NO_TRACE) { + if (trace != TmfExperimentContext.NO_TRACE) event = expContext.getEvents()[trace]; - } return event; } @@ -679,22 +667,21 @@ public class TmfExperiment extends TmfEventProvider impl // ------------------------------------------------------------------------ private synchronized void initializeStreamingMonitor() { - if (fInitialized) { + if (fInitialized) return; - } fInitialized = true; if (getStreamingInterval() == 0) { - TmfContext context = seekLocation(null); - ITmfEvent event = getNext(context); - if (event == null) { + final TmfContext context = seekLocation(null); + final ITmfEvent event = getNext(context); + if (event == null) return; - } - TmfTimeRange timeRange = new TmfTimeRange(event.getTimestamp().clone(), TmfTimestamp.BIG_CRUNCH); + final TmfTimeRange timeRange = new TmfTimeRange(event.getTimestamp().clone(), TmfTimestamp.BIG_CRUNCH); final TmfExperimentRangeUpdatedSignal signal = new TmfExperimentRangeUpdatedSignal(this, this, timeRange); // Broadcast in separate thread to prevent deadlock new Thread() { + @Override public void run() { broadcast(signal); @@ -704,6 +691,7 @@ public class TmfExperiment extends TmfEventProvider impl } final Thread thread = new Thread("Streaming Monitor for experiment " + getName()) { //$NON-NLS-1$ + ITmfTimestamp safeTimestamp = null; TmfTimeRange timeRange = null; @@ -713,29 +701,27 @@ public class TmfExperiment extends TmfEventProvider impl if (!isIndexingBusy()) { ITmfTimestamp startTimestamp = TmfTimestamp.BIG_CRUNCH; ITmfTimestamp endTimestamp = TmfTimestamp.BIG_BANG; - for (ITmfTrace trace : fTraces) { - if (trace.getStartTime().compareTo(startTimestamp) < 0) { + for (final ITmfTrace trace : fTraces) { + if (trace.getStartTime().compareTo(startTimestamp) < 0) startTimestamp = trace.getStartTime(); - } - if (trace.getStreamingInterval() != 0 && trace.getEndTime().compareTo(endTimestamp) > 0) { + if (trace.getStreamingInterval() != 0 && trace.getEndTime().compareTo(endTimestamp) > 0) endTimestamp = trace.getEndTime(); - } } - if (safeTimestamp != null && safeTimestamp.compareTo(getTimeRange().getEndTime(), false) > 0) { + if (safeTimestamp != null && safeTimestamp.compareTo(getTimeRange().getEndTime(), false) > 0) timeRange = new TmfTimeRange(startTimestamp, safeTimestamp); - } else { + else timeRange = null; - } safeTimestamp = endTimestamp; if (timeRange != null) { - TmfExperimentRangeUpdatedSignal signal = - new TmfExperimentRangeUpdatedSignal(TmfExperiment.this, TmfExperiment.this, timeRange); + final TmfExperimentRangeUpdatedSignal signal = + new TmfExperimentRangeUpdatedSignal(TmfExperiment.this, TmfExperiment.this, + timeRange); broadcast(signal); } } try { Thread.sleep(getStreamingInterval()); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { e.printStackTrace(); } } @@ -744,24 +730,27 @@ public class TmfExperiment extends TmfEventProvider impl thread.start(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getStreamingInterval() */ @Override public long getStreamingInterval() { long interval = 0; - for (ITmfTrace trace : fTraces) { + for (final ITmfTrace trace : fTraces) interval = Math.max(interval, trace.getStreamingInterval()); - } return interval; } /* - * The experiment holds the globally ordered events of its set of traces. It is expected to provide access to each - * individual event by index i.e. it must be possible to request the Nth event of the experiment. + * The experiment holds the globally ordered events of its set of traces. It + * is expected to provide access to each individual event by index i.e. it + * must be possible to request the Nth event of the experiment. * - * The purpose of the index is to keep the information needed to rapidly restore the traces contexts at regular - * intervals (every INDEX_PAGE_SIZE event). + * The purpose of the index is to keep the information needed to rapidly + * restore the traces contexts at regular intervals (every INDEX_PAGE_SIZE + * event). */ // The index page size @@ -790,32 +779,30 @@ public class TmfExperiment extends TmfEventProvider impl } @Override - public void indexTrace(boolean waitForCompletion) { - if (waitForCompletion) { + public void indexTrace(final boolean waitForCompletion) { + if (waitForCompletion) initializeStreamingMonitor(); - } } @SuppressWarnings("unchecked") - private void indexExperiment(boolean waitForCompletion, final int index, final TmfTimeRange timeRange) { + private void indexExperiment(final boolean waitForCompletion, final int index, final TmfTimeRange timeRange) { synchronized (fCheckpoints) { - if (fIndexing) { + if (fIndexing) return; - } fIndexing = true; } final Job job = new Job("Indexing " + getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$ + @Override - protected IStatus run(IProgressMonitor monitor) { - while (!monitor.isCanceled()) { + protected IStatus run(final IProgressMonitor monitor) { + while (!monitor.isCanceled()) try { Thread.sleep(100); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { return Status.OK_STATUS; } - } monitor.done(); return Status.OK_STATUS; } @@ -825,8 +812,10 @@ public class TmfExperiment extends TmfEventProvider impl // fEventLog = openLogFile("TraceEvent.log"); // System.out.println(System.currentTimeMillis() + ": Experiment indexing started"); - ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, timeRange, index, TmfDataRequest.ALL_DATA, - fIndexPageSize, ITmfDataRequest.ExecutionType.BACKGROUND) { // PATA FOREGROUND + final ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, timeRange, index, + TmfDataRequest.ALL_DATA, + fIndexPageSize, ITmfDataRequest.ExecutionType.BACKGROUND) { // PATA + // FOREGROUND // long indexingStart = System.nanoTime(); @@ -840,16 +829,15 @@ public class TmfExperiment extends TmfEventProvider impl } @Override - public void handleData(ITmfEvent event) { + public void handleData(final ITmfEvent event) { super.handleData(event); if (event != null) { - ITmfTimestamp ts = event.getTimestamp(); + final ITmfTimestamp ts = event.getTimestamp(); if (startTime == null) startTime = ts.clone(); lastTime = ts.clone(); - if ((getNbRead() % fIndexPageSize) == 1 && getNbRead() != 1) { + if ((getNbRead() % fIndexPageSize) == 1 && getNbRead() != 1) updateExperiment(); - } } } @@ -857,11 +845,12 @@ public class TmfExperiment extends TmfEventProvider impl public void handleSuccess() { // long indexingEnd = System.nanoTime(); - // if the end time is a real value then it is the streaming safe time stamp - // set the last time to the safe time stamp to prevent unnecessary indexing requests - if (getRange().getEndTime() != TmfTimestamp.BIG_CRUNCH) { + // if the end time is a real value then it is the streaming safe + // time stamp + // set the last time to the safe time stamp to prevent + // unnecessary indexing requests + if (getRange().getEndTime() != TmfTimestamp.BIG_CRUNCH) lastTime = getRange().getEndTime(); - } updateExperiment(); // System.out.println(System.currentTimeMillis() + ": Experiment indexing completed"); @@ -887,10 +876,9 @@ public class TmfExperiment extends TmfEventProvider impl } private void updateExperiment() { - int nbRead = getNbRead(); - if (startTime != null) { + final int nbRead = getNbRead(); + if (startTime != null) fTimeRange = new TmfTimeRange(startTime, lastTime.clone()); - } if (nbRead != 0) { // updateTimeRange(); // updateNbEvents(); @@ -904,14 +892,15 @@ public class TmfExperiment extends TmfEventProvider impl if (waitForCompletion) try { request.waitForCompletion(); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { e.printStackTrace(); } } protected void notifyListeners() { broadcast(new TmfExperimentUpdatedSignal(this, this)); // , null)); - //broadcast(new TmfExperimentRangeUpdatedSignal(this, this, fTimeRange)); // , null)); + // broadcast(new TmfExperimentRangeUpdatedSignal(this, this, + // fTimeRange)); // , null)); } // ------------------------------------------------------------------------ @@ -919,8 +908,8 @@ public class TmfExperiment extends TmfEventProvider impl // ------------------------------------------------------------------------ @TmfSignalHandler - public void experimentSelected(TmfExperimentSelectedSignal signal) { - TmfExperiment experiment = signal.getExperiment(); + public void experimentSelected(final TmfExperimentSelectedSignal signal) { + final TmfExperiment experiment = signal.getExperiment(); if (experiment == this) { setCurrentExperiment(experiment); fEndSynchReference = Integer.valueOf(signal.getReference()); @@ -928,42 +917,39 @@ public class TmfExperiment extends TmfEventProvider impl } @TmfSignalHandler - public void endSync(TmfEndSynchSignal signal) { + public void endSync(final TmfEndSynchSignal signal) { if (fEndSynchReference != null && fEndSynchReference.intValue() == signal.getReference()) { fEndSynchReference = null; initializeStreamingMonitor(); } - + } @TmfSignalHandler - public void experimentUpdated(TmfExperimentUpdatedSignal signal) { + public void experimentUpdated(final TmfExperimentUpdatedSignal signal) { } @TmfSignalHandler - public void experimentRangeUpdated(TmfExperimentRangeUpdatedSignal signal) { - if (signal.getExperiment() == this) { + public void experimentRangeUpdated(final TmfExperimentRangeUpdatedSignal signal) { + if (signal.getExperiment() == this) indexExperiment(false, (int) fNbEvents, signal.getRange()); - } } @TmfSignalHandler - public void traceUpdated(TmfTraceUpdatedSignal signal) { - for (ITmfTrace trace : fTraces) { + public void traceUpdated(final TmfTraceUpdatedSignal signal) { + for (final ITmfTrace trace : fTraces) if (trace == signal.getTrace()) { synchronized (fCheckpoints) { if (fIndexing) { - if (fIndexingPendingRange == TmfTimeRange.NULL_RANGE) { + if (fIndexingPendingRange == TmfTimeRange.NULL_RANGE) fIndexingPendingRange = signal.getRange(); - } else { + else { ITmfTimestamp startTime = fIndexingPendingRange.getStartTime(); ITmfTimestamp endTime = fIndexingPendingRange.getEndTime(); - if (signal.getRange().getStartTime().compareTo(startTime) < 0) { + if (signal.getRange().getStartTime().compareTo(startTime) < 0) startTime = signal.getRange().getStartTime(); - } - if (signal.getRange().getEndTime().compareTo(endTime) > 0) { + if (signal.getRange().getEndTime().compareTo(endTime) > 0) endTime = signal.getRange().getEndTime(); - } fIndexingPendingRange = new TmfTimeRange(startTime, endTime); } return; @@ -972,7 +958,6 @@ public class TmfExperiment extends TmfEventProvider impl indexExperiment(false, (int) fNbEvents, signal.getRange()); return; } - } } @Override @@ -983,29 +968,37 @@ public class TmfExperiment extends TmfEventProvider impl /** * Set the file to be used for bookmarks on this experiment + * * @param file the bookmarks file */ - public void setBookmarksFile(IFile file) { + public void setBookmarksFile(final IFile file) { fBookmarksFile = file; } /** * Get the file used for bookmarks on this experiment + * * @return the bookmarks file or null if none is set */ public IFile getBookmarksFile() { return fBookmarksFile; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#setResource(org.eclipse.core.resources.IResource) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#setResource(org.eclipse + * .core.resources.IResource) */ @Override - public void setResource(IResource resource) { + public void setResource(final IResource resource) { fResource = resource; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource() */ @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java index 4e8e65fdb9..20809ec3e8 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java @@ -21,136 +21,133 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfContext; /** * TmfExperimentContext *

- * The experiment keeps track of the next event from each of its traces so - * it can pick the next one in chronological order. + * The experiment keeps track of the next event from each of its traces so it + * can pick the next one in chronological order. *

- * This implies that the "next" event from each trace has already been - * read and that we at least know its timestamp. This doesn't imply that a - * full parse of the event content was performed (read: LTTng works like - * this). + * This implies that the "next" event from each trace has already been read and + * that we at least know its timestamp. This doesn't imply that a full parse of + * the event content was performed (read: LTTng works like this). *

- * The last trace refers to the trace from which the last event was - * "consumed" at the experiment level. + * The last trace refers to the trace from which the last event was "consumed" + * at the experiment level. */ public class TmfExperimentContext extends TmfContext { - // ------------------------------------------------------------------------ - // Constants - // ------------------------------------------------------------------------ - - public static final int NO_TRACE = -1; - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private ITmfTrace[] fTraces = new ITmfTrace[0]; - private ITmfContext[] fContexts; - private ITmfEvent[] fEvents; - private int lastTraceRead; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - public TmfExperimentContext(ITmfTrace[] traces, ITmfContext[] contexts) { - super(); - fTraces = traces; - fContexts = contexts; - fEvents = new ITmfEvent[fTraces.length]; - - ITmfLocation[] locations = new ITmfLocation[fTraces.length]; - long[] ranks = new long[fTraces.length]; - long rank = 0; - for (int i = 0; i < fTraces.length; i++) { - if (contexts[i] != null) { - locations[i] = contexts[i].getLocation(); - ranks[i] = contexts[i].getRank(); - rank += contexts[i].getRank(); - } - } - - setLocation(new TmfExperimentLocation(new TmfLocationArray(locations), ranks)); - setRank(rank); - lastTraceRead = NO_TRACE; - } - - public TmfExperimentContext(ITmfTrace[] traces) { - this(traces, new TmfContext[traces.length]); - } - - public TmfExperimentContext(TmfExperimentContext other) { - this(other.fTraces, other.cloneContexts()); - fEvents = other.fEvents; - if (other.getLocation() != null) - setLocation(other.getLocation().clone()); - setRank(other.getRank()); - setLastTrace(other.lastTraceRead); - } - - private ITmfContext[] cloneContexts() { - ITmfContext[] contexts = new TmfContext[fContexts.length]; - for (int i = 0; i < fContexts.length; i++) - contexts[i] = fContexts[i].clone(); - return contexts; - } - - // ------------------------------------------------------------------------ - // Accessors - // ------------------------------------------------------------------------ - - public ITmfTrace[] getTraces() { - return fTraces; - } - - public ITmfContext[] getContexts() { - return fContexts; - } - - public ITmfEvent[] getEvents() { - return fEvents; - } - - public int getLastTrace() { - return lastTraceRead; - } - - public void setLastTrace(int newIndex) { - lastTraceRead = newIndex; - } - - // ------------------------------------------------------------------------ - // Object - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + public static final int NO_TRACE = -1; + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private ITmfTrace[] fTraces = new ITmfTrace[0]; + private final ITmfContext[] fContexts; + private final ITmfEvent[] fEvents; + private int lastTraceRead; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public TmfExperimentContext(final ITmfTrace[] traces, final ITmfContext[] contexts) { + super(); + fTraces = traces; + fContexts = contexts; + fEvents = new ITmfEvent[fTraces.length]; + + final ITmfLocation[] locations = new ITmfLocation[fTraces.length]; + final long[] ranks = new long[fTraces.length]; + long rank = 0; + for (int i = 0; i < fTraces.length; i++) + if (contexts[i] != null) { + locations[i] = contexts[i].getLocation(); + ranks[i] = contexts[i].getRank(); + rank += contexts[i].getRank(); + } + + setLocation(new TmfExperimentLocation(new TmfLocationArray(locations), ranks)); + setRank(rank); + lastTraceRead = NO_TRACE; + } + + public TmfExperimentContext(final ITmfTrace[] traces) { + this(traces, new TmfContext[traces.length]); + } + +// public TmfExperimentContext(TmfExperimentContext other) { +// this(other.fTraces, other.cloneContexts()); +// fEvents = other.fEvents; +// if (other.getLocation() != null) +// setLocation(other.getLocation().clone()); +// setRank(other.getRank()); +// setLastTrace(other.lastTraceRead); +// } + +// private ITmfContext[] cloneContexts() { +// ITmfContext[] contexts = new TmfContext[fContexts.length]; +// for (int i = 0; i < fContexts.length; i++) +// contexts[i] = fContexts[i].clone(); +// return contexts; +// } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + + public ITmfTrace[] getTraces() { + return fTraces; + } + + public ITmfContext[] getContexts() { + return fContexts; + } + + public ITmfEvent[] getEvents() { + return fEvents; + } + + public int getLastTrace() { + return lastTraceRead; + } + + public void setLastTrace(final int newIndex) { + lastTraceRead = newIndex; + } + + // ------------------------------------------------------------------------ + // Object + // ------------------------------------------------------------------------ @Override public int hashCode() { - int result = 17; - for (int i = 0; i < fTraces.length; i++) { - result = 37 * result + fTraces[i].hashCode(); - result = 37 * result + fContexts[i].hashCode(); - } - return result; + int result = 17; + for (int i = 0; i < fTraces.length; i++) { + result = 37 * result + fTraces[i].hashCode(); + result = 37 * result + fContexts[i].hashCode(); + } + return result; } - + @Override - public boolean equals(Object other) { + public boolean equals(final Object other) { if (this == other) return true; if (!super.equals(other)) return false; - if (!(other instanceof TmfExperimentContext)) { - return false; - } - TmfExperimentContext o = (TmfExperimentContext) other; - boolean isEqual = true; - int i = 0; - while (isEqual && i < fTraces.length) { - isEqual &= fTraces[i].equals(o.fTraces[i]); - isEqual &= fContexts[i].equals(o.fContexts[i]); - i++; - } - return isEqual; + if (!(other instanceof TmfExperimentContext)) + return false; + final TmfExperimentContext o = (TmfExperimentContext) other; + boolean isEqual = true; + int i = 0; + while (isEqual && i < fTraces.length) { + isEqual &= fTraces[i].equals(o.fTraces[i]); + isEqual &= fContexts[i].equals(o.fContexts[i]); + i++; + } + return isEqual; } - + } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfContext.java index 4606ef1eeb..2d7aed5366 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfContext.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 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 @@ -8,6 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Updated as per TMF Trace Model 1.0 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.trace; @@ -15,28 +16,78 @@ package org.eclipse.linuxtools.tmf.core.trace; /** * ITmfContext *

- * This is a place-holder for the context objects. + * The basic trace context structure in TMF. The purpose of the context is to + * associate a trace location to an event of a specific rank (order). + *

+ * The context should be sufficient to allow the trace to position itself so + * that performing a trace read operation will yield the corresponding event. */ public interface ITmfContext extends Cloneable { - public long UNKNOWN_RANK = -2L; + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + /** + * The initial context event rank, before anything is read from the trace + */ public long INITIAL_RANK = -1L; - public void dispose(); + /** + * The unknown event rank + */ + public long UNKNOWN_RANK = -2L; + + // ------------------------------------------------------------------------ + // Getters + // ------------------------------------------------------------------------ - public void setLocation(ITmfLocation location); + /** + * @return the rank of the event referred to by the context + */ + public long getRank(); + + /** + * @return the location of the event referred to by the context + */ + public ITmfLocation> getLocation(); + + /** + * @return indicates if the context rank is valid (!= UNKNOWN_RANK) + */ + public boolean hasValidRank(); - @SuppressWarnings("rawtypes") - public ITmfLocation getLocation(); + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /** + * @param location the new location + */ + public void setLocation(ITmfLocation> location); + + /** + * @param rank the new rank + */ public void setRank(long rank); - public long getRank(); + /** + * Increment the context rank + */ + public void increaseRank(); - public void updateRank(int rank); + /** + * Cleanup hook + */ + public void dispose(); - public boolean isValidRank(); + // ------------------------------------------------------------------------ + // Cloneable + // ------------------------------------------------------------------------ + /** + * @return a clone of the context + */ public ITmfContext clone(); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java index c9dcbe2f20..fb214d13ab 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java @@ -25,38 +25,37 @@ public class TmfCheckpoint implements Comparable, Cloneable { // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ - + private ITmfTimestamp fTimestamp; - private ITmfLocation fLocation; + private ITmfLocation fLocation; // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ @SuppressWarnings("unused") - private TmfCheckpoint() { - fTimestamp = null; - fLocation = null; + private TmfCheckpoint() { } /** * @param ts the checkpoint timestamp * @param location the corresponding trace location */ - public TmfCheckpoint(ITmfTimestamp ts, ITmfLocation location) { + public TmfCheckpoint(final ITmfTimestamp ts, final ITmfLocation location) { fTimestamp = ts; fLocation = location; } /** * Deep copy constructor + * * @param other the other checkpoint */ - public TmfCheckpoint(TmfCheckpoint other) { - if (other == null) - throw new IllegalArgumentException(); + public TmfCheckpoint(final TmfCheckpoint other) { + if (other == null) + throw new IllegalArgumentException(); fTimestamp = other.fTimestamp.clone(); - fLocation = other.fLocation.clone(); + fLocation = other.fLocation.clone(); } // ------------------------------------------------------------------------ @@ -83,48 +82,46 @@ public class TmfCheckpoint implements Comparable, Cloneable { @Override public TmfCheckpoint clone() { - TmfCheckpoint result = null; - try { - result = (TmfCheckpoint) super.clone(); - result.fTimestamp = fTimestamp.clone(); - result.fLocation = fLocation.clone(); - return result; - } catch (CloneNotSupportedException e) { - e.printStackTrace(); - } - return result; + TmfCheckpoint result = null; + try { + result = (TmfCheckpoint) super.clone(); + result.fTimestamp = fTimestamp.clone(); + result.fLocation = fLocation.clone(); + return result; + } catch (final CloneNotSupportedException e) { + e.printStackTrace(); + } + return result; } - + @Override public int hashCode() { - return fTimestamp.hashCode(); + return fTimestamp.hashCode(); } - + @Override - public boolean equals(Object other) { - if (!(other instanceof TmfCheckpoint)) { - return false; - } - TmfCheckpoint o = (TmfCheckpoint) other; - return fTimestamp.equals(o.fTimestamp); + public boolean equals(final Object other) { + if (!(other instanceof TmfCheckpoint)) + return false; + final TmfCheckpoint o = (TmfCheckpoint) other; + return fTimestamp.equals(o.fTimestamp); } - + @Override @SuppressWarnings("nls") public String toString() { - return "[TmfCheckpoint(" + fTimestamp + "," + fLocation + ")]"; + return "[TmfCheckpoint(" + fTimestamp + "," + fLocation + ")]"; } - + // ------------------------------------------------------------------------ // Comparable // ------------------------------------------------------------------------ - @SuppressWarnings("unchecked") - @Override - public int compareTo(TmfCheckpoint other) { - if (fTimestamp == null || other.fTimestamp == null) { - return fLocation.getLocation().compareTo(other.fLocation.getLocation()); - } + @SuppressWarnings("unchecked") + @Override + public int compareTo(final TmfCheckpoint other) { + if (fTimestamp == null || other.fTimestamp == null) + return fLocation.getLocation().compareTo(other.fLocation.getLocation()); return fTimestamp.compareTo(other.fTimestamp, false); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfContext.java index bd5b10eb05..173a9b69da 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfContext.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 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 @@ -8,6 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Updated as per TMF Trace Model 1.0 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.trace; @@ -21,110 +22,180 @@ package org.eclipse.linuxtools.tmf.core.trace; */ public class TmfContext implements ITmfContext, Cloneable { + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + // The trace location private ITmfLocation> fLocation; + + // The event rank private long fRank; // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ - public TmfContext(ITmfLocation> loc, long rank) { - fLocation = loc; - fRank = rank; + /** + * Default constructor + */ + public TmfContext() { + this(null, UNKNOWN_RANK); } + /** + * Simple constructor (unknown rank) + * + * @param location the event location + */ public TmfContext(ITmfLocation> location) { this(location, UNKNOWN_RANK); } - public TmfContext(TmfContext other) { - this(other.fLocation, other.fRank); + /** + * Full constructor + * + * @param location the event location + * @param rank the event rank + */ + public TmfContext(ITmfLocation> location, long rank) { + fLocation = location; + fRank = rank; } - public TmfContext() { - this(null, UNKNOWN_RANK); + /** + * Copy constructor + * + * @param context the other context + */ + public TmfContext(TmfContext context) { + this(context.fLocation, context.fRank); + } + + // ------------------------------------------------------------------------ + // Cloneable + // ------------------------------------------------------------------------ + + /* (non-Javadoc) + * @see java.lang.Object#clone() + */ + @Override + public TmfContext clone() { + TmfContext clone = null; + try { + clone = (TmfContext) super.clone(); + clone.fLocation = fLocation.clone(); + clone.fRank = fRank; + } catch (CloneNotSupportedException e) { + } + return clone; } // ------------------------------------------------------------------------ // ITmfContext // ------------------------------------------------------------------------ + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation() + */ @Override - public void dispose() { - // override if necessary + public ITmfLocation> getLocation() { + return fLocation; } + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setLocation(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation) + */ @Override public void setLocation(ITmfLocation> location) { fLocation = location; } + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank() + */ @Override - public ITmfLocation> getLocation() { - return fLocation; + public long getRank() { + return fRank; } + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long) + */ @Override public void setRank(long rank) { fRank = rank; } + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank() + */ @Override - public long getRank() { - return fRank; + public void increaseRank() { + if (hasValidRank()) + fRank++; } + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank() + */ @Override - public void updateRank(int delta) { - if (isValidRank()) - fRank += delta; + public boolean hasValidRank() { + return fRank != UNKNOWN_RANK; } + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose() + */ @Override - public boolean isValidRank() { - return fRank != UNKNOWN_RANK; + public void dispose() { } // ------------------------------------------------------------------------ // Object // ------------------------------------------------------------------------ + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ @Override public int hashCode() { - int result = 17; - result = 37 * result + fLocation.hashCode(); - result = 37 * result + (int) (fRank ^ (fRank >>> 32)); + final int prime = 31; + int result = 1; + result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode()); + result = prime * result + (int) (fRank ^ (fRank >>> 32)); return result; } + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ @Override - public boolean equals(Object other) { - if (other == this) { + public boolean equals(Object obj) { + if (this == obj) return true; - } - if (!(other instanceof TmfContext)) { + if (obj == null) return false; - } - TmfContext o = (TmfContext) other; - return fLocation.equals(o.fLocation) && (fRank == o.fRank); + if (getClass() != obj.getClass()) + return false; + TmfContext other = (TmfContext) obj; + if (fLocation == null) { + if (other.fLocation != null) + return false; + } else if (!fLocation.equals(other.fLocation)) + return false; + if (fRank != other.fRank) + return false; + return true; } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ @Override @SuppressWarnings("nls") public String toString() { - return "[TmfContext(" + fLocation.toString() + "," + fRank + ")]"; - } - - @Override - public TmfContext clone() { - TmfContext clone = null; - try { - clone = (TmfContext) super.clone(); - clone.fLocation = fLocation.clone(); - clone.fRank = fRank; - } catch (CloneNotSupportedException e) { - } - return clone; + return "TmfContext [fLocation=" + fLocation + ", fRank=" + fRank + "]"; } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java index a9e2947d5a..7b56b9c0de 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java @@ -91,7 +91,7 @@ public class TmfLocation> implements ITmfLocation { clone = (TmfLocation) super.clone(); if (fLocation != null) { Class clazz = fLocation.getClass(); - Method method = clazz.getMethod("clone", new Class[0]); + Method method = clazz.getMethod("clone", new Class[0]); //$NON-NLS-1$ Object copy = method.invoke(this.fLocation, new Object[0]); clone.fLocation = (L) copy; } else { @@ -142,6 +142,7 @@ public class TmfLocation> implements ITmfLocation { } @Override + @SuppressWarnings("nls") public String toString() { return "TmfLocation [fLocation=" + fLocation + "]"; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java index 7c338a7c9b..da41d1d59d 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java @@ -420,7 +420,7 @@ public abstract class TmfTrace extends TmfEventProvider ITmfEvent event = getNextEvent(nextEventContext); while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) { context.setLocation(nextEventContext.getLocation().clone()); - context.updateRank(1); + context.increaseRank(); event = getNextEvent(nextEventContext); } @@ -554,7 +554,7 @@ public abstract class TmfTrace extends TmfEventProvider if (event != null) { updateIndex(context, context.getRank(), event.getTimestamp()); context.setLocation(getCurrentLocation()); - context.updateRank(1); + context.increaseRank(); processEvent(event); } return event; @@ -565,7 +565,7 @@ public abstract class TmfTrace extends TmfEventProvider fStartTime = timestamp; if (fEndTime.compareTo(timestamp, false) < 0) fEndTime = timestamp; - if (context.isValidRank()) { + if (context.hasValidRank()) { if (fNbEvents <= rank) fNbEvents = rank + 1; // Build the index as we go along diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomTxtTrace.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomTxtTrace.java index 57f72582b9..e3a342bf21 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomTxtTrace.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomTxtTrace.java @@ -168,7 +168,7 @@ public class CustomTxtTrace extends TmfTrace { TmfEvent event = parseEvent(context); if (event != null) { updateIndex(savedContext, savedContext.getRank(), event.getTimestamp()); - context.updateRank(1); + context.increaseRank(); } return event; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomXmlTrace.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomXmlTrace.java index efc619947f..968b01908d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomXmlTrace.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomXmlTrace.java @@ -170,7 +170,7 @@ public class CustomXmlTrace extends TmfTrace { TmfEvent event = parseEvent(context); if (event != null) { updateIndex(savedContext, savedContext.getRank(), event.getTimestamp()); - context.updateRank(1); + context.increaseRank(); } return event; } -- 2.34.1