diff options
author | Francois Chouinard | 2012-06-06 20:43:21 +0000 |
---|---|---|
committer | Francois Chouinard | 2012-06-06 20:44:16 +0000 |
commit | 05b63f06b7b162cc335f0a8ebeefa4becef1c0b7 (patch) | |
tree | 976bfa090ef82e26965d70c5fdb52fab3277b559 /lttng/org.eclipse.linuxtools.tmf.core | |
parent | ac47da1ec693090ec29a8aa4573bfa659ba42b54 (diff) | |
download | org.eclipse.linuxtools-05b63f06b7b162cc335f0a8ebeefa4becef1c0b7.tar.gz org.eclipse.linuxtools-05b63f06b7b162cc335f0a8ebeefa4becef1c0b7.tar.xz org.eclipse.linuxtools-05b63f06b7b162cc335f0a8ebeefa4becef1c0b7.zip |
Fix #2 for bug381411
Diffstat (limited to 'lttng/org.eclipse.linuxtools.tmf.core')
6 files changed, 145 insertions, 17 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java index 716b9a87b4..dfe716fedd 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java @@ -8,7 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation - * Francois Chouinard - Put in shape for 1.0 + * Francois Chouinard - Put in shape for 1.0 *******************************************************************************/ package org.eclipse.linuxtools.internal.tmf.core.trace; @@ -63,6 +63,9 @@ public class TmfExperimentContext extends TmfContext implements Cloneable { fContexts = contexts; fEvents = new ITmfEvent[fContexts.length]; final ITmfLocation<?>[] locations = new ITmfLocation[fContexts.length]; + + setLocation(new TmfExperimentLocation(new TmfLocationArray(locations.clone()))); + final long[] ranks = new long[fContexts.length]; long rank = 0; for (int i = 0; i < fContexts.length; i++) @@ -72,7 +75,7 @@ public class TmfExperimentContext extends TmfContext implements Cloneable { rank += contexts[i].getRank(); } - setLocation(new TmfExperimentLocation(new TmfLocationArray(locations))); +// setLocation(new TmfExperimentLocation(new TmfLocationArray(locations))); setRank(rank); fLastTraceRead = NO_TRACE; } @@ -167,4 +170,23 @@ public class TmfExperimentContext extends TmfContext implements Cloneable { return isEqual; } + @Override + @SuppressWarnings("nls") + public String toString() { + StringBuilder sb = new StringBuilder("TmfExperimentContext [\n"); + sb.append("\tfLocation=" + getLocation() + ", fRank=" + getRank() + "\n"); + sb.append("\tfContexts=["); + for (int i = 0; i < fContexts.length; i++) { + sb.append("(" + fContexts[i].getLocation() + "," + fContexts[i].getRank() + ((i < fContexts.length - 1) ? ")," : ")]\n")); + } + sb.append("\tfEvents=["); + for (int i = 0; i < fEvents.length; i++) { + ITmfEvent event = fEvents[i]; + sb.append(((event != null) ? fEvents[i].getTimestamp() : "(null)") + ((i < fEvents.length - 1) ? "," : "]\n")); + } + sb.append("\tfLastTraceRead=" + fLastTraceRead + "\n"); + sb.append("]"); + return sb.toString(); + } + } diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentLocation.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentLocation.java index 566758c0ad..22e4357a9b 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentLocation.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentLocation.java @@ -83,7 +83,7 @@ public class TmfExperimentLocation extends TmfLocation<TmfLocationArray> impleme StringBuilder result = new StringBuilder("[TmfExperimentLocation"); ITmfLocation<? extends Comparable<?>>[] locations = ((TmfLocationArray) getLocation()).getLocations(); for (ITmfLocation<?> location : locations) { - result.append("[" + location.toString() + "]"); + result.append("[" + location + "]"); } result.append("]"); return result.toString(); diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java index c781fe0974..3b40a68698 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java @@ -69,7 +69,8 @@ public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable public TmfLocationArray clone() { ITmfLocation<? extends Comparable<?>>[] clones = (ITmfLocation<? extends Comparable<?>>[]) new ITmfLocation<?>[fLocations.length]; for (int i = 0; i < fLocations.length; i++) { - clones[i] = fLocations[i].clone(); + ITmfLocation<?> location = fLocations[i]; + clones[i] = (location != null) ? location : null; } return new TmfLocationArray(clones); } diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java index 02ef51d97b..0c4ae3e218 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java @@ -127,7 +127,7 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(IProject, String) */ @Override - public boolean validate(@SuppressWarnings("unused") final IProject project, final String path) { + public boolean validate(final IProject project, final String path) { try { final CTFTrace temp = new CTFTrace(path); return temp.majortIsSet(); // random test @@ -169,6 +169,8 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse public ITmfContext seekEvent(final ITmfLocation<?> location) { CtfLocation currentLocation = (CtfLocation) location; CtfIterator context = new CtfIterator(this); + context.setRank(ITmfContext.UNKNOWN_RANK); + /* * The rank is set to 0 if the iterator seeks the beginning. If not, it * will be set to UNKNOWN_RANK, since CTF traces don't support seeking @@ -184,7 +186,7 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse } context.setLocation(currentLocation); if(context.getRank() != 0) - context.setRank(ITmfContext.UNKNOWN_RANK); + context.setRank(ITmfContext.UNKNOWN_RANK); return context; } @@ -225,7 +227,7 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse * sub-classes. * @throws TmfTraceException */ - @SuppressWarnings({ "static-method", "unused" }) + @SuppressWarnings({ "static-method" }) protected void buildStateSystem() throws TmfTraceException { /* * Nothing is done in the basic implementation, please specify diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java index f2b4688c39..1c5b958d98 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; @@ -55,7 +56,7 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm // ------------------------------------------------------------------------ // The event trace to index - private final ITmfTrace<ITmfEvent> fTrace; + protected final ITmfTrace<ITmfEvent> fTrace; // The interval between checkpoints private final int fCheckpointInterval; @@ -67,7 +68,7 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm * The trace index. It is composed of checkpoints taken at intervals of * fCheckpointInterval events. */ - private final List<ITmfCheckpoint> fTraceIndex; + protected final List<ITmfCheckpoint> fTraceIndex; /** * The indexing request @@ -245,7 +246,7 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm final long position = rank / fCheckpointInterval; // Add new entry at proper location (if empty) if (fTraceIndex.size() == position) { - fTraceIndex.add(new TmfCheckpoint(timestamp.clone(), context.clone())); + fTraceIndex.add(new TmfCheckpoint(timestamp.clone(), shrinkContext(context))); } } } @@ -311,7 +312,7 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm if (index >= fTraceIndex.size()) { index = fTraceIndex.size() - 1; } - return fTraceIndex.get(index).getContext().clone(); + return restoreContext(fTraceIndex.get(index).getContext()); } } final ITmfContext context = fTrace.seekEvent(location); @@ -329,4 +330,65 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm protected List<ITmfCheckpoint> getTraceIndex() { return fTraceIndex; } + + // ------------------------------------------------------------------------ + // Context conversion functions + // ------------------------------------------------------------------------ + + private ITmfContext shrinkContext(ITmfContext context) { + if (context instanceof TmfExperimentContext) { + return shrinkExpContext(context); + } + TmfContext ctx = new TmfContext(context.getLocation().clone(), context.getRank()); + return ctx; + } + + private ITmfContext shrinkExpContext(ITmfContext context) { + TmfExperimentContext expContext = (TmfExperimentContext) context; + int size = expContext.getContexts().length; + ITmfContext[] trcCtxts = new TmfContext[size]; + for (int i = 0; i < size; i++) { + ITmfContext ctx = expContext.getContexts()[i]; + trcCtxts[i] = (ctx != null) ? new TmfContext(ctx.getLocation().clone(), ctx.getRank()) : null; + } + TmfExperimentContext expCtx = new TmfExperimentContext(trcCtxts); + expCtx.setLocation(context.getLocation().clone()); + expCtx.setRank(context.getRank()); + ITmfEvent[] trcEvts = expCtx.getEvents(); + for (int i = 0; i < size; i++) { + ITmfEvent event = expContext.getEvents()[i]; + trcEvts[i] = (event != null) ? event.clone() : null; + } + return expCtx; + } + + private ITmfContext restoreContext(ITmfContext context) { + if (context instanceof TmfExperimentContext) { + return restoreExpContext(context); + } + ITmfContext ctx = fTrace.seekEvent(context.getLocation()); + ctx.setRank(context.getRank()); + return ctx; + } + + private ITmfContext restoreExpContext(ITmfContext context) { + TmfExperimentContext expContext = (TmfExperimentContext) context; + int size = expContext.getContexts().length; + ITmfContext[] trcCtxts = new ITmfContext[size]; + for (int i = 0; i < size; i++) { + ITmfTrace<?> trace = ((TmfExperiment<?>) fTrace).getTraces()[i]; + ITmfContext ctx = expContext.getContexts()[i]; + trcCtxts[i] = trace.seekEvent(ctx.getLocation().clone()); + trcCtxts[i].setRank(ctx.getRank()); + } + TmfExperimentContext ctx = new TmfExperimentContext(trcCtxts); + ctx.setLocation(context.getLocation().clone()); + ctx.setRank(context.getRank()); + ITmfEvent[] trcEvts = expContext.getEvents(); + for (int i = 0; i < size; i++) { + ITmfEvent event = trcEvts[i]; + ctx.getEvents()[i] = (event != null) ? event.clone() : null; + } + return ctx; + } } diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java index 15698f92f1..4cdbbc1889 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java @@ -230,6 +230,9 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I // Request management // ------------------------------------------------------------------------ + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#armRequest(org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest) + */ @Override protected synchronized ITmfContext armRequest(final ITmfDataRequest<T> request) { if (request instanceof ITmfEventRequest<?> @@ -255,6 +258,37 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I // ------------------------------------------------------------------------ /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#seekEvent(long) + * + * TmfTrace.seekEvent(rank) will return a context that will position the + * trace to read the event at rank 'rank' in the trace. In the case of an + * experiment context, that event has to be actually read in the fEvents + * buffer and the corresponding trace context has to point to the next + * event (rank + 1) in the trace (the sum of the traces contexts ranks + * should equal [exp context rank + #traces] (corner cases not considered). + * + * In the likely case that TmfTrace.seekEvent() computed the context + * by using a read loop (reading from the experiment), the 'lastTraceRead' + * field will be set to the actual trace that needs to be read to obtain + * event at rank 'rank'. + * + * Therefore, if 'lastTraceRead' is set, we need to read that particular + * trace *and* then decrease the context rank (which has to correspond to + * the rank of the event to be returned next by TmfExperiemnt.getNext(). + */ + @Override + public synchronized ITmfContext seekEvent(final long rank) { + TmfExperimentContext context = (TmfExperimentContext) super.seekEvent(rank); + int lastTrace = context.getLastTrace(); + if (lastTrace != TmfExperimentContext.NO_TRACE) { + getNext(context); + context.setRank(rank); + context.setLastTrace(TmfExperimentContext.NO_TRACE); + } + return context; + } + + /* (non-Javadoc) * * Returns a brand new context based on the location provided and * initializes the event queues @@ -282,8 +316,8 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I for (int i = 0; i < fTraces.length; i++) { // Get the relevant trace attributes - final ITmfLocation<?> traceLocation = expLocation.getLocation().getLocations()[i]; - context.getContexts()[i] = fTraces[i].seekEvent(traceLocation); + final ITmfLocation<?> trcLocation = expLocation.getLocation().getLocations()[i]; + context.getContexts()[i] = fTraces[i].seekEvent(trcLocation); expLocation.getLocation().getLocations()[i] = context.getContexts()[i].getLocation().clone(); context.getEvents()[i] = fTraces[i].getNext(context.getContexts()[i]); } @@ -294,10 +328,13 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I context.setRank(ITmfContext.UNKNOWN_RANK); fExperimentContext = context; - return (ITmfContext) context; } + // ------------------------------------------------------------------------ + // ITmfTrace - SeekEvent operations (returning a trace context) + // ------------------------------------------------------------------------ + /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(double) */ @@ -347,8 +384,8 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#getNext(org.eclipse.linuxtools.tmf.core.trace.ITmfContext) */ - @SuppressWarnings("unchecked") @Override + @SuppressWarnings("unchecked") public synchronized T getNext(ITmfContext context) { // Validate the context @@ -361,6 +398,12 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I final int lastTrace = expContext.getLastTrace(); if (lastTrace != TmfExperimentContext.NO_TRACE) { final ITmfContext traceContext = expContext.getContexts()[lastTrace]; + + TmfExperimentLocation location = (TmfExperimentLocation) expContext.getLocation(); + if (location != null) { + location.getLocation().getLocations()[lastTrace] = traceContext.getLocation().clone(); + } + expContext.getEvents()[lastTrace] = fTraces[lastTrace].getNext(traceContext); expContext.setLastTrace(TmfExperimentContext.NO_TRACE); } @@ -384,8 +427,6 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I event = (T) expContext.getEvents()[trace]; if (event != null) { updateAttributes(expContext, event.getTimestamp()); - TmfExperimentLocation location = (TmfExperimentLocation) expContext.getLocation(); - location.getLocation().getLocations()[trace] = expContext.getContexts()[trace].getLocation(); expContext.increaseRank(); expContext.setLastTrace(trace); fExperimentContext = expContext; |