TmfExperimentLocation expLocation = (TmfExperimentLocation) checkpoint.getLocation();
TmfLocationArray locations = expLocation.getLocation();
ITmfContext[] trcContexts = new ITmfContext[2];
- trcContexts[0] = new TmfContext(locations.getLocations()[0], (i * pageSize) / 2);
- trcContexts[1] = new TmfContext(locations.getLocations()[1], (i * pageSize) / 2);
+ trcContexts[0] = new TmfContext(locations.getLocations()[0].getLocation(), (i * pageSize) / 2);
+ trcContexts[1] = new TmfContext(locations.getLocations()[1].getLocation(), (i * pageSize) / 2);
TmfExperimentContext expContext = new TmfExperimentContext(trcContexts);
expContext.getEvents()[0] = fTestTraces[0].getNext(fTestTraces[0].seekEvent((i * pageSize) / 2));
expContext.getEvents()[1] = fTestTraces[1].getNext(fTestTraces[1].seekEvent((i * pageSize) / 2));
TmfExperimentLocation expLocation = (TmfExperimentLocation) checkpoint.getLocation();
TmfLocationArray locations = expLocation.getLocation();
ITmfContext[] trcContexts = new ITmfContext[2];
- trcContexts[0] = new TmfContext(locations.getLocations()[0], (i * pageSize) / 2);
- trcContexts[1] = new TmfContext(locations.getLocations()[1], (i * pageSize) / 2);
+ trcContexts[0] = new TmfContext(locations.getLocations()[0].getLocation(), (i * pageSize) / 2);
+ trcContexts[1] = new TmfContext(locations.getLocations()[1].getLocation(), (i * pageSize) / 2);
TmfExperimentContext expContext = new TmfExperimentContext(trcContexts);
expContext.getEvents()[0] = testTraces[0].getNext(testTraces[0].seekEvent((i * pageSize) / 2));
expContext.getEvents()[1] = testTraces[1].getNext(testTraces[1].seekEvent((i * pageSize) / 2));
// First event
ITmfContext context = fExperiment.seekEvent((ITmfLocation) null);
double ratio = fExperiment.getLocationRatio(context.getLocation());
- context = fExperiment.seekEvent(ratio);
- double ratio2 = fExperiment.getLocationRatio(context.getLocation());
- assertEquals("getLocationRatio", ratio, ratio2);
+ assertEquals("getLocationRatio", 0.0, ratio);
// Middle event
context = fExperiment.seekEvent(NB_EVENTS / 2);
ratio = fExperiment.getLocationRatio(context.getLocation());
- context = fExperiment.seekEvent(ratio);
- ratio2 = fExperiment.getLocationRatio(context.getLocation());
- assertEquals("getLocationRatio", ratio, ratio2);
+ assertEquals("getLocationRatio", (double) (NB_EVENTS / 2) / NB_EVENTS, ratio);
// Last event
context = fExperiment.seekEvent(NB_EVENTS - 1);
ratio = fExperiment.getLocationRatio(context.getLocation());
- context = fExperiment.seekEvent(ratio);
- ratio2 = fExperiment.getLocationRatio(context.getLocation());
- assertEquals("getLocationRatio", ratio, ratio2);
+ assertEquals("getLocationRatio", (double) (NB_EVENTS - 1) / NB_EVENTS, ratio);
}
// @SuppressWarnings({ "unchecked", "rawtypes" })
assertTrue("isCancelled", request.isCancelled());
}
-}
\ No newline at end of file
+}
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
/**
super();
fContexts = contexts;
fEvents = new ITmfEvent[fContexts.length];
- final ITmfLocation<?>[] locations = new ITmfLocation[fContexts.length];
+ final TmfRankedLocation[] locations = new TmfRankedLocation[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++)
+ for (int i = 0; i < fContexts.length; i++) {
if (contexts[i] != null) {
- locations[i] = contexts[i].getLocation();
- ranks[i] = contexts[i].getRank();
+ locations[i] = new TmfRankedLocation(contexts[i]);
rank += contexts[i].getRank();
}
+ }
-// setLocation(new TmfExperimentLocation(new TmfLocationArray(locations)));
+ setLocation(new TmfExperimentLocation(new TmfLocationArray(locations)));
setRank(rank);
fLastTraceRead = NO_TRACE;
}
package org.eclipse.linuxtools.internal.tmf.core.trace;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
/**
*/
@Override
public TmfExperimentLocation clone() {
-// super.clone(); // To keep FindBugs happy
TmfLocationArray array = (TmfLocationArray) getLocation();
TmfLocationArray clones = array.clone();
return new TmfExperimentLocation(clones);
@SuppressWarnings("nls")
public String toString() {
StringBuilder result = new StringBuilder("[TmfExperimentLocation");
- ITmfLocation<? extends Comparable<?>>[] locations = ((TmfLocationArray) getLocation()).getLocations();
- for (ITmfLocation<?> location : locations) {
+ TmfRankedLocation[] locations = ((TmfLocationArray) getLocation()).getLocations();
+ for (TmfRankedLocation location : locations) {
result.append("[" + location + "]");
}
result.append("]");
import java.util.Arrays;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
-
/**
* A convenience class to store trace location arrays. The main purpose is to
* provide a Comparable implementation for TmfExperimentLocation.
// Attributes
// ------------------------------------------------------------------------
- private ITmfLocation<? extends Comparable<?>>[] fLocations;
+ private TmfRankedLocation[] fLocations;
// ------------------------------------------------------------------------
// Constructors
*
* @param locations the locations
*/
- public TmfLocationArray(ITmfLocation<? extends Comparable<?>>[] locations) {
+ public TmfLocationArray(TmfRankedLocation[] locations) {
fLocations = locations;
}
*
* @param locations the locations
*/
- public ITmfLocation<? extends Comparable<?>>[] getLocations() {
+ public TmfRankedLocation[] getLocations() {
return fLocations;
}
*/
@Override
public TmfLocationArray clone() {
- ITmfLocation<? extends Comparable<?>>[] clones = (ITmfLocation<? extends Comparable<?>>[]) new ITmfLocation<?>[fLocations.length];
+ TmfRankedLocation[] clones = new TmfRankedLocation[fLocations.length];
for (int i = 0; i < fLocations.length; i++) {
- ITmfLocation<?> location = fLocations[i];
+ TmfRankedLocation location = fLocations[i];
clones[i] = (location != null) ? location.clone() : null;
}
return new TmfLocationArray(clones);
// ------------------------------------------------------------------------
@Override
- @SuppressWarnings({ "unchecked", "rawtypes" })
public int compareTo(TmfLocationArray o) {
for (int i = 0; i < fLocations.length; i++) {
- ITmfLocation<? extends Comparable> l1 = (ITmfLocation<? extends Comparable>) fLocations[i].getLocation();
- ITmfLocation<? extends Comparable> l2 = (ITmfLocation<? extends Comparable>) o.fLocations[i].getLocation();
- int result = l1.getLocation().compareTo(l2.getLocation());
+ TmfRankedLocation l1 = fLocations[i];
+ TmfRankedLocation l2 = o.fLocations[i];
+ int result = l1.compareTo(l2);
if (result != 0) {
return result;
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.core.trace;
+
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+
+/**
+ * A pair of trace location and trace rank.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfRankedLocation implements Comparable<TmfRankedLocation>, Cloneable {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private ITmfLocation<? extends Comparable<?>> fLocation;
+ private long fRank;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * The standard constructor
+ *
+ * @param context a trace context
+ */
+ public TmfRankedLocation(ITmfContext context) {
+ fLocation = context.getLocation().clone();
+ fRank = context.getRank();
+ }
+
+ /**
+ * Private constructor
+ *
+ * @param location the trace location
+ * @param rank the trace rank
+ */
+ private TmfRankedLocation(ITmfLocation<? extends Comparable<?>> location, long rank) {
+ fLocation = location;
+ fRank = rank;
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get the trace location
+ *
+ * @return the trace location
+ */
+ public ITmfLocation<? extends Comparable<?>> getLocation() {
+ return fLocation;
+ }
+
+ /**
+ * Get the trace rank
+ *
+ * @return the trace rank
+ */
+ public long getRank() {
+ return fRank;
+ }
+
+ // ------------------------------------------------------------------------
+ // Cloneable
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public TmfRankedLocation clone() {
+ return new TmfRankedLocation(fLocation.clone(), fRank);
+ }
+
+ // ------------------------------------------------------------------------
+ // Comparable
+ // ------------------------------------------------------------------------
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(TmfRankedLocation o) {
+ return Long.valueOf(fRank).compareTo(Long.valueOf(o.fRank));
+ }
+
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ 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 obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ TmfRankedLocation other = (TmfRankedLocation) 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 fLocation + "," + fRank;
+ }
+
+}
import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext;
import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation;
import org.eclipse.linuxtools.internal.tmf.core.trace.TmfLocationArray;
+import org.eclipse.linuxtools.internal.tmf.core.trace.TmfRankedLocation;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
// Instantiate the location
final TmfExperimentLocation expLocation = (location == null)
- ? new TmfExperimentLocation(new TmfLocationArray(new ITmfLocation<?>[fTraces.length]))
+ ? new TmfExperimentLocation(new TmfLocationArray(new TmfRankedLocation[fTraces.length]))
: (TmfExperimentLocation) location.clone();
// Create and populate the context's traces contexts
final TmfExperimentContext context = new TmfExperimentContext(new ITmfContext[fTraces.length]);
+ long rank = 0;
for (int i = 0; i < fTraces.length; i++) {
// Get the relevant trace attributes
- final ITmfLocation<?> trcLocation = expLocation.getLocation().getLocations()[i];
- context.getContexts()[i] = fTraces[i].seekEvent(trcLocation);
- expLocation.getLocation().getLocations()[i] = context.getContexts()[i].getLocation().clone();
+ final TmfRankedLocation rankedLocation = expLocation.getLocation().getLocations()[i];
+ final ITmfLocation<?> traceLocation = (rankedLocation == null) ? null : rankedLocation.getLocation();
+ final long traceRank = (rankedLocation == null) ? 0 : rankedLocation.getRank();
+ context.getContexts()[i] = fTraces[i].seekEvent(traceLocation);
+ context.getContexts()[i].setRank(traceRank);
+ expLocation.getLocation().getLocations()[i] = new TmfRankedLocation(context.getContexts()[i]);
context.getEvents()[i] = fTraces[i].getNext(context.getContexts()[i]);
+ rank += traceRank;
}
// Finalize context
context.setLocation(expLocation);
context.setLastTrace(TmfExperimentContext.NO_TRACE);
- context.setRank(ITmfContext.UNKNOWN_RANK);
+ context.setRank(rank);
fExperimentContext = context;
return (ITmfContext) context;
@Override
public double getLocationRatio(final ITmfLocation<?> location) {
if (location instanceof TmfExperimentLocation) {
- return (double) seekEvent(location).getRank() / getNbEvents();
+ long rank = 0;
+ for (TmfRankedLocation rankedLocation : ((TmfExperimentLocation) location).getLocation().getLocations()) {
+ rank += rankedLocation.getRank();
+ }
+ return (double) rank / getNbEvents();
}
return 0.0;
}
*/
@Override
public ITmfLocation<?> getCurrentLocation() {
- ITmfLocation<?>[] locations = new ITmfLocation<?>[fTraces.length];
+ TmfRankedLocation[] locations = new TmfRankedLocation[fTraces.length];
for (int i = 0; i < fTraces.length; i++) {
- locations[i] = fTraces[i].getCurrentLocation();
+ locations[i] = new TmfRankedLocation(new TmfContext(fTraces[i].getCurrentLocation(), ITmfContext.UNKNOWN_RANK));
}
return new TmfExperimentLocation(new TmfLocationArray(locations));
}
updateAttributes(expContext, event.getTimestamp());
expContext.increaseRank();
expContext.setLastTrace(trace);
- final TmfExperimentLocation location = (TmfExperimentLocation) expContext.getLocation();
+ final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation();
final ITmfContext traceContext = expContext.getContexts()[trace];
- location.getLocation().getLocations()[trace] = traceContext.getLocation().clone();
+ expLocation.getLocation().getLocations()[trace] = new TmfRankedLocation(traceContext);
fExperimentContext = expContext;
processEvent(event);
}