X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=org.eclipse.linuxtools.tmf.core%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Ftmf%2Fcore%2Fexperiment%2FTmfExperiment.java;h=ed9758506814cb13c0e189eac25d42957f71cecb;hb=2065894741f9e2ad30265d0ffe7ccf00fe40e67d;hp=f87ab5f241a4757c755b61d42cb083e18468f5e5;hpb=0d9a6d765b693ee77f0ccf19a0289de466aa6a63;p=deliverable%2Ftracecompass.git 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 f87ab5f241..ed97585068 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 @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2009, 2010 Ericsson - * + * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Francois Chouinard - Initial API and implementation *******************************************************************************/ @@ -37,7 +37,6 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentUpdatedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; -import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; @@ -48,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 { @@ -69,7 +69,7 @@ public class TmfExperiment extends TmfEventProvider impl // The experiment time range protected TmfTimeRange fTimeRange; - // The experiment reference timestamp (default: Zero) + // The experiment reference timestamp (default: ZERO) protected ITmfTimestamp fEpoch; // The experiment index @@ -92,30 +92,18 @@ public class TmfExperiment extends TmfEventProvider impl // ------------------------------------------------------------------------ @Override - public boolean validate(IProject project, String path) { - return true; - } - - @Override - public void initTrace(String name, String path, Class eventType) { + public TmfExperiment clone() throws CloneNotSupportedException { + throw new CloneNotSupportedException(); } @Override - public void initTrace(String name, String path, Class eventType, boolean indexTrace) { - if (indexTrace) { - initializeStreamingMonitor(); - } - } - - @Override - public void initTrace(String name, String path, Class eventType, int cacheSize) { + public boolean validate(final IProject project, final String path) { + return true; } @Override - public void initTrace(String name, String path, Class eventType, int cacheSize, boolean indexTrace) { - if (indexTrace) { - initializeStreamingMonitor(); - } + public void initTrace(final IResource resource, final String path, final Class eventType) { + fResource = resource; } /** @@ -125,11 +113,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; @@ -138,13 +128,12 @@ public class TmfExperiment extends TmfEventProvider impl fTimeRange = TmfTimeRange.NULL_RANGE; if (preIndexExperiment) { - indexExperiment(true); + indexExperiment(true, 0, TmfTimeRange.ETERNITY); updateTimeRange(); } - } - protected TmfExperiment(String id, Class type) { + protected TmfExperiment(final String id, final Class type) { super(id, type); } @@ -153,7 +142,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); } @@ -163,38 +152,10 @@ 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); } - /** - * Copy constructor - * - * @param other - */ - @SuppressWarnings("unchecked") - public TmfExperiment(TmfExperiment other) { - super(other.getName() + "(clone)", other.fType); //$NON-NLS-1$ - - fEpoch = other.fEpoch; - fIndexPageSize = other.fIndexPageSize; - - fTraces = new ITmfTrace[other.fTraces.length]; - for (int trace = 0; trace < other.fTraces.length; trace++) { - fTraces[trace] = other.fTraces[trace].copy(); - } - - fNbEvents = other.fNbEvents; - fTimeRange = other.fTimeRange; - } - - @Override - public TmfExperiment copy() { - TmfExperiment experiment = new TmfExperiment(this); - TmfSignalManager.deregister(experiment); - return experiment; - } - /** * Clears the experiment */ @@ -202,21 +163,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(); } @@ -224,6 +182,11 @@ public class TmfExperiment extends TmfEventProvider impl // ITmfTrace // ------------------------------------------------------------------------ + @Override + public Class getType() { + return fType; + } + @Override public long getNbEvents() { return fNbEvents; @@ -257,10 +220,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; } @@ -277,27 +239,15 @@ 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). - * - * @param timestamp the event timestamp - * @return the corresponding event rank - */ - @Override - public long getRank(ITmfTimestamp timestamp) { - 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; } @@ -312,11 +262,11 @@ public class TmfExperiment extends TmfEventProvider impl 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; } @@ -326,40 +276,33 @@ public class TmfExperiment extends TmfEventProvider impl // ------------------------------------------------------------------------ // TmfProvider // ------------------------------------------------------------------------ - @Override - public ITmfContext armRequest(ITmfDataRequest request) { -// Tracer.trace("Ctx: Arming request - start"); - ITmfTimestamp timestamp = (request instanceof ITmfEventRequest) ? ((ITmfEventRequest) request).getRange().getStartTime() - : null; - if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0) { + @Override + public ITmfContext armRequest(final ITmfDataRequest request) { + // Tracer.trace("Ctx: Arming request - start"); + ITmfTimestamp timestamp = (request instanceof ITmfEventRequest) ? ((ITmfEventRequest) request).getRange().getStartTime() : null; + 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()) { + } 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 { + else context = seekEvent(request.getIndex()); - } - } -// Tracer.trace("Ctx: Arming request - done"); + // 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); - } + @SuppressWarnings("unchecked") + public T getNext(final ITmfContext context) { + if (context instanceof TmfExperimentContext) + return (T) getNextEvent(context); return null; } @@ -370,29 +313,27 @@ 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( + 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]); -// Tracer.trace("Ctx: SeekLocation - start"); + final TmfExperimentContext context = new TmfExperimentContext(fTraces, new ITmfContext[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); @@ -400,13 +341,15 @@ 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. */ - expLocation.getLocation().locations[i] = ((TmfContext) context.getContexts()[i]).getLocation().clone(); + /* + * The (TmfContext) cast should be safe since we created 'context' + * ourselves higher up. + */ + expLocation.getLocation().locations[i] = context.getContexts()[i].getLocation().clone(); context.getEvents()[i] = fTraces[i].getNextEvent(context.getContexts()[i]); } -// Tracer.trace("Ctx: SeekLocation - done"); + // Tracer.trace("Ctx: SeekLocation - done"); // Finalize context context.setLocation(expLocation); @@ -418,19 +361,16 @@ public class TmfExperiment extends TmfEventProvider impl return context; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @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"); + // 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)); @@ -438,29 +378,26 @@ 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 ITmfEvent event = parseEvent(context); - while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) { + while ((event != null) && (event.getTimestamp().compareTo(timestamp, false) < 0)) { getNextEvent(context); event = parseEvent(context); } @@ -473,37 +410,34 @@ public class TmfExperiment extends TmfEventProvider impl return context; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @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"); + // Tracer.trace("Ctx: seekEvent(rank) - start"); // Position the stream at the previous checkpoint 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 ITmfEvent event = parseEvent(context); long pos = context.getRank(); - while (event != null && pos++ < rank) { + while ((event != null) && (pos++ < rank)) { getNextEvent(context); event = parseEvent(context); } @@ -517,81 +451,75 @@ 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; } -// private void dumpContext(TmfExperimentContext context, boolean isBefore) { - -// TmfContext context0 = context.getContexts()[0]; -// TmfEvent event0 = context.getEvents()[0]; -// TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation(); -// long rank0 = context.getRank(); -// int trace = context.getLastTrace(); -// -// StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A ")); -// -// result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] "); -// result.append("[Evt: " + event0.getTimestamp().toString() + "] "); -// result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] "); -// result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]"); -// Tracer.trace(result.toString()); -// } + // private void dumpContext(TmfExperimentContext context, boolean isBefore) { + // TmfContext context0 = context.getContexts()[0]; + // TmfEvent event0 = context.getEvents()[0]; + // TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation(); + // long rank0 = context.getRank(); + // int trace = context.getLastTrace(); + // + // StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A ")); + // + // result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] "); + // result.append("[Evt: " + event0.getTimestamp().toString() + "] "); + // result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] "); + // result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]"); + // Tracer.trace(result.toString()); + // } /** - * 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); + // 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) { @@ -599,86 +527,81 @@ 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(); -// expLocation.getLocation()[trace] = traceContext.getLocation().clone(); - expLocation.getLocation().locations[trace] = (ITmfLocation>) traceContext.getLocation().clone(); + final ITmfContext traceContext = expContext.getContexts()[trace]; + final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation(); + // expLocation.getLocation()[trace] = traceContext.getLocation().clone(); + expLocation.getLocation().locations[trace] = traceContext.getLocation().clone(); -// updateIndex(expContext, timestamp); + // updateIndex(expContext, timestamp); expLocation.getRanks()[trace] = traceContext.getRank(); expContext.setLastTrace(trace); - expContext.updateRank(1); + expContext.increaseRank(); event = expContext.getEvents()[trace]; fExperimentContext = expContext; } -// if (event != null) { -// Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString()); -// dumpContext(expContext, false); -// Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString()); -// } + // if (event != null) { + // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString()); + // dumpContext(expContext, false); + // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString()); + // } 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()); + // System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " + // + location.toString()); } } } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @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; @@ -688,9 +611,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; @@ -699,16 +622,13 @@ 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; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override @@ -722,18 +642,16 @@ 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 @@ -746,9 +664,9 @@ public class TmfExperiment extends TmfEventProvider impl return; } - final Thread thread = new Thread("Streaming Monitor for experiment " + getName()) { //$NON-NLS-1$ - ITmfTimestamp safeTimestamp = null; - TmfTimeRange timeRange = null; + final Thread thread = new Thread("Streaming Monitor for experiment " + getName()) { ////$NON-NLS-1$ + private ITmfTimestamp safeTimestamp = null; + private TmfTimeRange timeRange = null; @Override public void run() { @@ -756,29 +674,26 @@ 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 = + 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(); } } @@ -787,24 +702,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 @@ -815,16 +733,16 @@ public class TmfExperiment extends TmfEventProvider impl private Integer fEndSynchReference; -// private static BufferedWriter fEventLog = null; -// private static BufferedWriter openLogFile(String filename) { -// BufferedWriter outfile = null; -// try { -// outfile = new BufferedWriter(new FileWriter(filename)); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// return outfile; -// } + // private static BufferedWriter fEventLog = null; + // private static BufferedWriter openLogFile(String filename) { + // BufferedWriter outfile = null; + // try { + // outfile = new BufferedWriter(new FileWriter(filename)); + // } catch (IOException e) { + // e.printStackTrace(); + // } + // return outfile; + // } protected boolean isIndexingBusy() { synchronized (fCheckpoints) { @@ -832,43 +750,40 @@ public class TmfExperiment extends TmfEventProvider impl } } - protected void indexExperiment(boolean waitForCompletion) { - indexExperiment(waitForCompletion, 0, TmfTimeRange.ETERNITY); - } - @SuppressWarnings("unchecked") - protected 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; } }; job.schedule(); -// fEventLog = openLogFile("TraceEvent.log"); -// System.out.println(System.currentTimeMillis() + ": Experiment indexing started"); + // 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(); + // long indexingStart = System.nanoTime(); ITmfTimestamp startTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getStartTime(); ITmfTimestamp lastTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getEndTime(); @@ -880,36 +795,36 @@ 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) { - updateExperiment(); - } } + if ((getNbRead() % fIndexPageSize) == 1 && getNbRead() != 1) + updateExperiment(); } @Override public void handleSuccess() { -// long indexingEnd = System.nanoTime(); + // 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"); + // System.out.println(System.currentTimeMillis() + ": Experiment indexing completed"); -// long average = (indexingEnd - indexingStart) / fNbEvents; -// System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed=" -// + (indexingEnd * 1.0 - indexingStart) / 1000000000); -// System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "." -// + (average % 1000) + " us/evt)"); + // long average = (indexingEnd - indexingStart) / fNbEvents; + // System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed=" + // + (indexingEnd * 1.0 - indexingStart) / 1000000000); + // System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "." + // + (average % 1000) + " us/evt)"); super.handleSuccess(); } @@ -927,13 +842,12 @@ 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(); + // updateTimeRange(); + // updateNbEvents(); fNbEvents = initialNbEvents + nbRead; notifyListeners(); } @@ -944,14 +858,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)); } // ------------------------------------------------------------------------ @@ -959,8 +874,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()); @@ -968,42 +883,38 @@ 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; @@ -1012,7 +923,6 @@ public class TmfExperiment extends TmfEventProvider impl indexExperiment(false, (int) fNbEvents, signal.getRange()); return; } - } } @Override @@ -1023,29 +933,25 @@ 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) - */ - @Override - public void setResource(IResource resource) { - fResource = resource; - } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource() */ @Override