ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / ITmfTrace.java
index 7badaff5531f74d9698e9a688555fcd071902b6c..4c2cf3f0a4b812afb49d65d07106b3cc4b3ebd94 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2013 Ericsson
+ * Copyright (c) 2009, 2014 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
@@ -9,22 +9,27 @@
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
  *   Francois Chouinard - Updated as per TMF Trace Model 1.0
+ *   Geneviève Bastien  - Added timestamp transforms and timestamp
+ *                        creation functions
+ *   Patrick Tasse - Add support for folder elements
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.trace;
 
-import java.util.Collections;
-import java.util.Map;
-
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
-import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
+import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 /**
  * The event stream structure in TMF. In its basic form, a trace has:
@@ -36,9 +41,9 @@ import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
  * <li> the time range (span) of the events it contains
  * </ul>
  * Concrete ITmfTrace classes have to provide a parameter-less constructor and
- * an initialization method (<i>initTrace</i>) if they are to be opened from
- * the Project View. Also, a validation method (<i>validate</i>) has to be
- * provided to ensure that the trace is of the correct type.
+ * an initialization method (<i>initTrace</i>) if they are to be opened from the
+ * Project View. Also, a validation method (<i>validate</i>) has to be provided
+ * to ensure that the trace is of the correct type.
  * <p>
  * A trace can be accessed simultaneously from multiple threads by various
  * application components. To avoid obvious multi-threading issues, the trace
@@ -79,19 +84,22 @@ import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
  *     event = trace.getNext(context);
  * }
  * </pre>
+ *
  * A trace is also an event provider so it can process event requests
  * asynchronously (and coalesce compatible, concurrent requests).
  * <p>
- * </pre>
- * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for variants)
+ *
+ * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for
+ * variants)
  * <pre>
  * ITmfRequest request = new TmfEventRequest&lt;MyEventType&gt;(MyEventType.class) {
- *     &#64;Override
+ *     &#064;Override
  *     public void handleData(MyEventType event) {
  *         super.handleData(event);
  *         processEvent(event);
  *     }
- *     &#64;Override
+ *
+ *     &#064;Override
  *     public void handleCompleted() {
  *         finish();
  *         super.handleCompleted();
@@ -112,7 +120,7 @@ import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
  * @see ITmfTraceIndexer
  * @see ITmfEventParser
  */
-public interface ITmfTrace extends ITmfDataProvider {
+public interface ITmfTrace extends ITmfEventProvider {
 
     // ------------------------------------------------------------------------
     // Constants
@@ -132,95 +140,148 @@ public interface ITmfTrace extends ITmfDataProvider {
      * properly parameterize an ITmfTrace instantiated with its parameterless
      * constructor.
      * <p>
-     * Typically, the parameterless constructor will provide the block size
-     * and its associated parser and indexer.
+     * Typically, the parameterless constructor will provide the block size and
+     * its associated parser and indexer.
      *
-     * @param resource the trace resource
-     * @param path the trace path
-     * @param type the trace event type
-     * @throws TmfTraceException If we couldn't open the trace
+     * @param resource
+     *            the trace resource
+     * @param path
+     *            the trace path. The path should suitable for passing to
+     *            <code>java.io.File(String)</code> and should use the
+     *            platform-dependent path separator.
+     * @param type
+     *            the trace event type
+     * @throws TmfTraceException
+     *             If we couldn't open the trace
      */
-    public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException;
+    void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException;
 
     /**
-     * Validate that the trace is of the correct type.
-     *
-     * @param project the eclipse project
-     * @param path the trace path
+     * Initialize a newly instantiated "empty" trace object. This is used to
+     * properly parameterize an ITmfTrace instantiated with its parameterless
+     * constructor.
+     * <p>
+     * Typically, the parameterless constructor will provide the block size and
+     * its associated parser and indexer.
      *
-     * @return true if trace is valid
+     * @param resource
+     *            the trace resource
+     * @param path
+     *            the trace path
+     * @param type
+     *            the trace event type
+     * @param name
+     *            the trace name
+     * @throws TmfTraceException
+     *             If we couldn't open the trace
      */
-    public boolean validate(IProject project, String path);
-
-    // ------------------------------------------------------------------------
-    // Basic getters
-    // ------------------------------------------------------------------------
+    void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type, String name) throws TmfTraceException;
 
     /**
-     * If this trace is used as a container for sub-traces, this can be used to
-     * get the sub-traces themselves. If the trace is stand-alone, this should
-     * return an array with only "this" inside. For this reason, be careful if
-     * calling this recursively.
+     * Validate that the trace is of the correct type. The implementation should
+     * return a TraceValidationStatus to indicate success with a certain level
+     * of confidence.
      *
-     * This offers a standard way of iterating through compound traces (like
-     * experiments).
+     * @param project
+     *            the eclipse project
+     * @param path
+     *            the trace path. The path should suitable for passing to
+     *            <code>java.io.File(String)</code> and should use the
+     *            platform-dependent path separator.
      *
-     * @return The array of sub-traces.
+     * @return an IStatus object with validation result. Use severity OK to
+     *         indicate success.
+     * @see TraceValidationStatus
      * @since 2.0
      */
-    public ITmfTrace[] getTraces();
+    IStatus validate(IProject project, String path);
+
+    // ------------------------------------------------------------------------
+    // Basic getters
+    // ------------------------------------------------------------------------
 
     /**
      * @return the trace event type
      */
-    public Class<? extends ITmfEvent> getEventType();
+    Class<? extends ITmfEvent> getEventType();
 
     /**
      * @return the associated trace resource
      */
-    public IResource getResource();
+    IResource getResource();
 
     /**
      * @return the trace path
      */
-    public String getPath();
+    String getPath();
 
     /**
      * @return the trace cache size
      */
-    public int getCacheSize();
+    int getCacheSize();
 
     /**
-     * @return The statistics provider for this trace
+     * Index the trace. Depending on the trace type, this could be done at the
+     * constructor or initTrace phase too, so this could be implemented as a
+     * no-op.
+     *
+     * @param waitForCompletion
+     *            Should we block the caller until indexing is finished, or not.
      * @since 2.0
      */
-    public ITmfStatistics getStatistics();
+    void indexTrace(boolean waitForCompletion);
+
+    // ------------------------------------------------------------------------
+    // Analysis getters
+    // ------------------------------------------------------------------------
 
     /**
-     * Return the map of state systems associated with this trace.
+     * Returns an analysis module with the given ID.
      *
-     * This view should be read-only (implementations should use
-     * {@link Collections#unmodifiableMap}).
+     * @param id
+     *            The analysis module ID
+     * @return The {@link IAnalysisModule} object, or null if an analysis with
+     *         the given ID does no exist.
+     * @since 3.0
+     */
+    @Nullable
+    IAnalysisModule getAnalysisModule(String id);
+
+    /**
+     * Get a list of all analysis modules currently available for this trace.
      *
-     * @return The map of state systems
-     * @since 2.0
+     * @return An iterable view of the analysis modules
+     * @since 3.0
      */
-    public Map<String, ITmfStateSystem> getStateSystems();
+    @NonNull
+    Iterable<IAnalysisModule> getAnalysisModules();
 
     /**
-     * If a state system is not build by the trace itself, it's possible to
-     * register it if it comes from another source. It will then be accessible
-     * with {@link #getStateSystems} normally.
+     * Get an analysis module belonging to this trace, with the specified ID and
+     * class.
      *
+     * @param moduleClass
+     *            Returned modules must extend this class
      * @param id
-     *            The unique ID to assign to this state system. In case of
-     *            conflicting ID's, the new one will overwrite the previous one
-     *            (default Map behavior).
-     * @param ss
-     *            The already-built state system
-     * @since 2.0
+     *            The ID of the analysis module
+     * @return The analysis module with specified class and ID, or null if no
+     *         such module exists.
+     * @since 3.0
+     */
+    @Nullable
+    <T extends IAnalysisModule> T getAnalysisModuleOfClass(Class<T> moduleClass, String id);
+
+    /**
+     * Return the analysis modules that are of a given class. Module are already
+     * casted to the requested class.
+     *
+     * @param moduleClass
+     *            Returned modules must extend this class
+     * @return List of modules of class moduleClass
+     * @since 3.0
      */
-    public void registerStateSystem(String id, ITmfStateSystem ss);
+    @NonNull
+    <T> Iterable<T> getAnalysisModulesOfClass(Class<T> moduleClass);
 
     // ------------------------------------------------------------------------
     // Trace characteristics getters
@@ -229,30 +290,30 @@ public interface ITmfTrace extends ITmfDataProvider {
     /**
      * @return the number of events in the trace
      */
-    public long getNbEvents();
+    long getNbEvents();
 
     /**
      * @return the trace time range
      * @since 2.0
      */
-    public TmfTimeRange getTimeRange();
+    TmfTimeRange getTimeRange();
 
     /**
      * @return the timestamp of the first trace event
      * @since 2.0
      */
-    public ITmfTimestamp getStartTime();
+    ITmfTimestamp getStartTime();
 
     /**
      * @return the timestamp of the last trace event
      * @since 2.0
      */
-    public ITmfTimestamp getEndTime();
+    ITmfTimestamp getEndTime();
 
     /**
      * @return the streaming interval in ms (0 if not a streaming trace)
      */
-    public long getStreamingInterval();
+    long getStreamingInterval();
 
     // ------------------------------------------------------------------------
     // Trace positioning getters
@@ -260,16 +321,19 @@ public interface ITmfTrace extends ITmfDataProvider {
 
     /**
      * @return the current trace location
+     * @since 3.0
      */
-    public ITmfLocation getCurrentLocation();
+    ITmfLocation getCurrentLocation();
 
     /**
      * Returns the ratio (proportion) corresponding to the specified location.
      *
-     * @param location a trace specific location
+     * @param location
+     *            a trace specific location
      * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
+     * @since 3.0
      */
-    public double getLocationRatio(ITmfLocation location);
+    double getLocationRatio(ITmfLocation location);
 
     // ------------------------------------------------------------------------
     // SeekEvent operations (returning a trace context)
@@ -284,29 +348,32 @@ public interface ITmfTrace extends ITmfDataProvider {
      * If not null, the location requested must be valid otherwise the returned
      * context is undefined (up to the implementation to recover if possible).
      * <p>
-     * @param location the trace specific location
+     *
+     * @param location
+     *            the trace specific location
      * @return a context which can later be used to read the corresponding event
+     * @since 3.0
      */
-    public ITmfContext seekEvent(ITmfLocation location);
+    ITmfContext seekEvent(ITmfLocation location);
 
     /**
      * Position the trace at the 'rank'th event in the trace.
      * <p>
-     * A rank <= 0 is interpreted as seeking for the first event of the
-     * trace.
+     * A rank <= 0 is interpreted as seeking for the first event of the trace.
      * <p>
      * If the requested rank is beyond the last trace event, the context
      * returned will yield a null event if used in a subsequent read.
      *
-     * @param rank the event rank
+     * @param rank
+     *            the event rank
      * @return a context which can later be used to read the corresponding event
      */
-    public ITmfContext seekEvent(long rank);
+    ITmfContext seekEvent(long rank);
 
     /**
      * Position the trace at the first event with the specified timestamp. If
-     * there is no event with the requested timestamp, a context pointing to
-     * the next chronological event is returned.
+     * there is no event with the requested timestamp, a context pointing to the
+     * next chronological event is returned.
      * <p>
      * A null timestamp is interpreted as seeking for the first event of the
      * trace.
@@ -314,11 +381,12 @@ public interface ITmfTrace extends ITmfDataProvider {
      * If the requested timestamp is beyond the last trace event, the context
      * returned will yield a null event if used in a subsequent read.
      *
-     * @param timestamp the timestamp of desired event
+     * @param timestamp
+     *            the timestamp of desired event
      * @return a context which can later be used to read the corresponding event
      * @since 2.0
      */
-    public ITmfContext seekEvent(ITmfTimestamp timestamp);
+    ITmfContext seekEvent(ITmfTimestamp timestamp);
 
     /**
      * Position the trace at the event located at the specified ratio in the
@@ -328,10 +396,11 @@ public interface ITmfTrace extends ITmfDataProvider {
      * voluntarily vague. Typically, it would refer to the event proportional
      * rank (arguably more intuitive) or timestamp in the trace file.
      *
-     * @param ratio the proportional 'rank' in the trace
+     * @param ratio
+     *            the proportional 'rank' in the trace
      * @return a context which can later be used to read the corresponding event
      */
-    public ITmfContext seekEvent(double ratio);
+    ITmfContext seekEvent(double ratio);
 
     /**
      * Returns the initial range offset
@@ -339,21 +408,50 @@ public interface ITmfTrace extends ITmfDataProvider {
      * @return the initial range offset
      * @since 2.0
      */
-    public ITmfTimestamp getInitialRangeOffset();
+    ITmfTimestamp getInitialRangeOffset();
 
     /**
-     * Return the current selected time.
+     * Returns the ID of the host this trace is from. The host ID is not
+     * necessarily the hostname, but should be a unique identifier for the
+     * machine on which the trace was taken. It can be used to determine if two
+     * traces were taken on the exact same machine (timestamp are already
+     * synchronized, resources with same id are the same if taken at the same
+     * time, etc).
      *
-     * @return the current time stamp
-     * @since 2.0
+     * @return The host id of this trace
+     * @since 3.0
+     */
+    String getHostId();
+
+    // ------------------------------------------------------------------------
+    // Timestamp transformation functions
+    // ------------------------------------------------------------------------
+
+    /**
+     * Returns the timestamp transformation for this trace
+     *
+     * @return the timestamp transform
+     * @since 3.0
      */
-    public ITmfTimestamp getCurrentTime();
+    ITmfTimestampTransform getTimestampTransform();
 
     /**
-     * Return the current selected range.
+     * Sets the trace's timestamp transform
      *
-     * @return the current time range
-     * @since 2.0
+     * @param tt
+     *            The timestamp transform for all timestamps of this trace
+     * @since 3.0
+     */
+    void setTimestampTransform(final ITmfTimestampTransform tt);
+
+    /**
+     * Creates a timestamp for this trace, using the transformation formula
+     *
+     * @param ts
+     *            The time in nanoseconds with which to create the timestamp
+     * @return The new timestamp
+     * @since 3.0
      */
-    public TmfTimeRange getCurrentRange();
+    ITmfTimestamp createTimestamp(long ts);
+
 }
This page took 0.037788 seconds and 5 git commands to generate.