/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
+ * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.ctf.core.CTFReaderException;
+import org.eclipse.tracecompass.ctf.core.CTFException;
import org.eclipse.tracecompass.ctf.core.event.CTFCallsite;
import org.eclipse.tracecompass.ctf.core.event.CTFClock;
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.event.aspect.ITmfEventAspect;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceProperties;
import org.eclipse.tracecompass.tmf.ctf.core.event.aspect.CtfChannelAspect;
import org.eclipse.tracecompass.tmf.ctf.core.event.aspect.CtfCpuAspect;
import org.eclipse.tracecompass.tmf.ctf.core.event.lookup.CtfTmfCallsite;
-import org.eclipse.tracecompass.tmf.ctf.core.timestamp.CtfTmfTimestamp;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
*/
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
}
}
}
- } catch (final CTFReaderException e) {
+ } catch (final CTFException e) {
/*
* If it failed at the init(), we can assume it's because the file
* was not found or was not recognized as a CTF trace. Throw into
/**
* {@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) {
- IStatus status = new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
+ boolean isMetadataValid = false;
try {
- final CTFTrace temp = new CTFTrace(path);
- if (!temp.majorIsSet()) {
- status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet);
- } else {
- try (CTFTraceReader ctfTraceReader = new CTFTraceReader(temp);) {
- 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
- status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_NoEvent);
+ isMetadataValid = 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 (isMetadataValid) {
+ // Trace is pre-validated, continue will full validation
+ try {
+ final CTFTrace trace = new CTFTrace(path);
+ if (!trace.majorIsSet()) {
+ if (isMetadataValid) {
+ 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 e) {
+ if (isMetadataValid) {
+ return new TraceValidationStatus(MIN_CONFIDENCE, IStatus.WARNING, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString(), e); //$NON-NLS-1$
+ }
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString()); //$NON-NLS-1$
+ } catch (final BufferOverflowException e) {
+ if (isMetadataValid) {
+ return new TraceValidationStatus(MIN_CONFIDENCE, IStatus.WARNING, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString(), e); //$NON-NLS-1$
}
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString()); //$NON-NLS-1$
}
- } catch (final CTFReaderException e) {
- status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString()); //$NON-NLS-1$
- } catch (final BufferOverflowException e) {
- status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + Messages.CtfTmfTrace_BufferOverflowErrorMessage); //$NON-NLS-1$
}
-
- return status;
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError);
}
@Override
public ITmfContext createIterator() {
try {
return new CtfIterator(fTrace, this);
- } catch (CTFReaderException e) {
+ } catch (CTFException e) {
Activator.getDefault().logError(e.getMessage(), e);
}
return null;
public ITmfContext createIterator(CtfLocationInfo ctfLocationData, long rank) {
try {
return new CtfIterator(fTrace, this, ctfLocationData, rank);
- } catch (CTFReaderException e) {
+ } catch (CTFException e) {
Activator.getDefault().logError(e.getMessage(), e);
}
return null;
// Timestamp transformation functions
// ------------------------------------------------------------------------
+ /**
+ * @since 1.0
+ */
@Override
- public CtfTmfTimestamp createTimestamp(long ts) {
- return new CtfTmfTimestamp(getTimestampTransform().transform(ts));
+ public @NonNull TmfNanoTimestamp createTimestamp(long ts) {
+ return new TmfNanoTimestamp(getTimestampTransform().transform(ts));
}
private static int fCheckpointSize = -1;
@Override
public synchronized int getCheckpointSize() {
if (fCheckpointSize == -1) {
- TmfCheckpoint c = new TmfCheckpoint(new CtfTmfTimestamp(0), new CtfLocation(0, 0), 0);
+ TmfCheckpoint c = new TmfCheckpoint(new TmfNanoTimestamp(0), new CtfLocation(0, 0), 0);
ByteBuffer b = ByteBuffer.allocate(ITmfCheckpoint.MAX_SERIALIZE_SIZE);
b.clear();
c.serialize(b);