import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader;
+import org.eclipse.tracecompass.ctf.core.trace.Metadata;
import org.eclipse.tracecompass.internal.tmf.ctf.core.Activator;
import org.eclipse.tracecompass.internal.tmf.ctf.core.trace.iterator.CtfIterator;
import org.eclipse.tracecompass.internal.tmf.ctf.core.trace.iterator.CtfIteratorManager;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceProperties;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
import org.eclipse.tracecompass.tmf.core.trace.indexer.TmfBTreeTraceIndexer;
*/
private static final String CLOCK_HOST_PROPERTY = "uuid"; //$NON-NLS-1$
private static final int CONFIDENCE = 10;
+ private static final int MIN_CONFIDENCE = 1;
// -------------------------------------------
// Fields
/**
* {@inheritDoc}
* <p>
- * The default implementation sets the confidence to 10 if the trace is a
- * valid CTF trace.
+ * The default implementation of a CTF trace.
+ *
+ * Firstly a weak validation of the metadata is done to determine if the
+ * path is actually for a CTF trace. After that a full validation is done.
+ *
+ * If the weak and full validation are successful the confidence is set
+ * to 10.
+ *
+ * If the weak validation was successful, but the full validation fails
+ * a TraceValidationStatus with severity warning and confidence of 1 is
+ * returned.
+ *
+ * If both weak and full validation fails an error status is returned.
*/
@Override
public IStatus validate(final IProject project, final String path) {
+ boolean isMetadataFile = false;
try {
- final CTFTrace trace = new CTFTrace(path);
- if (!trace.majorIsSet()) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet);
- }
- try (CTFTraceReader ctfTraceReader = new CTFTraceReader(trace)) {
- if (!ctfTraceReader.hasMoreEvents()) {
- // TODO: This will need an additional check when we
- // support live traces
- // because having no event is valid for a live trace
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_NoEvent);
+ isMetadataFile = Metadata.preValidate(path);
+ } catch (final CTFException e) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString(), e); //$NON-NLS-1$
+ }
+
+ if (isMetadataFile) {
+ // Trace is pre-validated, continue will full validation
+ try {
+ final CTFTrace trace = new CTFTrace(path);
+ if (!trace.majorIsSet()) {
+ if (isMetadataFile) {
+ return new TraceValidationStatus(MIN_CONFIDENCE, IStatus.WARNING, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet, null);
+ }
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet);
}
+
+ // Validate using reader initialization
+ try (CTFTraceReader ctfTraceReader = new CTFTraceReader(trace)) {}
+
+ // Trace is validated, return with confidence
+ return new CtfTraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID, trace.getEnvironment());
+
+ } catch (final CTFException | BufferOverflowException e ) {
+ // return warning since it's a CTF trace but with errors in it
+ return new TraceValidationStatus(MIN_CONFIDENCE, IStatus.WARNING, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString(), e); //$NON-NLS-1$
}
- return new CtfTraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID, trace.getEnvironment());
- } catch (final CTFException e) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString()); //$NON-NLS-1$
- } catch (final BufferOverflowException e) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + Messages.CtfTmfTrace_BufferOverflowErrorMessage); //$NON-NLS-1$
}
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError);
}
@Override
@Override
public double getLocationRatio(ITmfLocation location) {
final CtfLocation curLocation = (CtfLocation) location;
- final CtfTmfContext context = new CtfTmfContext(this);
- context.setLocation(curLocation);
- context.seek(curLocation.getLocationInfo());
- final CtfLocationInfo currentTime = ((CtfLocationInfo) context.getLocation().getLocationInfo());
- final long startTime = fIteratorManager.getIterator(context).getStartTime();
- final long endTime = fIteratorManager.getIterator(context).getEndTime();
- return ((double) currentTime.getTimestamp() - startTime)
- / (endTime - startTime);
+ final long startTime = getStartTime().getValue();
+ final double diff = curLocation.getLocationInfo().getTimestamp() - startTime;
+ final double total = getEndTime().getValue() - startTime;
+ return Math.max(0.0, Math.min(1.0, diff / total));
}
/**
if (currentLocation == null) {
currentLocation = new CtfLocation(new CtfLocationInfo(0L, 0L));
context.setRank(0);
- }
- if (currentLocation.getLocationInfo() == CtfLocation.INVALID_LOCATION) {
- currentLocation = new CtfLocation(fTrace.getCurrentEndTime() + 1, 0L);
- }
- context.setLocation(currentLocation);
- if (location == null) {
- long timestamp = fIteratorManager.getIterator(context).getCurrentTimestamp();
- currentLocation = new CtfLocation(timestamp, 0);
- }
- if (context.getRank() != 0) {
+ } else {
context.setRank(ITmfContext.UNKNOWN_RANK);
+ if (currentLocation.getLocationInfo() == CtfLocation.INVALID_LOCATION) {
+ currentLocation = new CtfLocation(fTrace.getCurrentEndTime() + 1, 0L);
+ }
}
+ /* This will seek and update the location after the seek */
+ context.setLocation(currentLocation);
return context;
}
context.setRank(ITmfContext.UNKNOWN_RANK);
return context;
}
- final long end = fTrace.getCurrentEndTime();
- final long start = fTrace.getCurrentStartTime();
+ final long end = getEndTime().getValue();
+ final long start = getStartTime().getValue();
final long diff = end - start;
final long ratioTs = Math.round(diff * ratio) + start;
context.seek(ratioTs);