TMF: Introduce a framework to hook trace analysis modules/plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / ITmfTrace.java
index 15666917f8a66a8b5c3c4bf91fb734efdb478631..8d858d193f506aaa3156fd49743f6a17c6835dca 100644 (file)
@@ -1,42 +1,52 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2011, 2012 Ericsson
- * 
+ * Copyright (c) 2009, 2013 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
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * 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
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.trace;
 
-import java.io.FileNotFoundException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
 import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+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;
 
 /**
- * <b><u>ITmfTrace</u></b>
- * <p>
  * The event stream structure in TMF. In its basic form, a trace has:
  * <ul>
- * <li> the associated Eclipse resource
- * <li> the path to its location on the file system
+ * <li> an associated Eclipse resource
+ * <li> a path to its location on the file system
  * <li> the type of the events it contains
  * <li> the number of events it contains
  * <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 (initTace())if they are to be opened from the
- * Project View. Also, a validation (validate()) method 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
@@ -46,24 +56,24 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
  * trace. Seek operations can be performed for a particular event (by rank or
  * timestamp) or for a plain trace location.
  * <p>
- * <b>Example 1</b>: Read a whole trace
+ * <b>Example 1</b>: Process a whole trace
  * <pre>
- * ITmfContext context = trace.seekLocationt(null);
- * ITmfEvent event = trace.getEvent(context);
+ * ITmfContext context = trace.seekEvent(0);
+ * ITmfEvent event = trace.getNext(context);
  * while (event != null) {
- *     // Do something ...
- *     event = trace.getEvent(context);
+ *     processEvent(event);
+ *     event = trace.getNext(context);
  * }
  * </pre>
  * <b>Example 2</b>: Process 50 events starting from the 1000th event
  * <pre>
  * int nbEventsRead = 0;
  * ITmfContext context = trace.seekEvent(1000);
- * ITmfEvent event = trace.getEvent(context);
+ * ITmfEvent event = trace.getNext(context);
  * while (event != null && nbEventsRead < 50) {
  *     nbEventsRead++;
- *     // Do something ...
- *     event = trace.getEvent(context);
+ *     processEvent(event);
+ *     event = trace.getNext(context);
  * }
  * </pre>
  * <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
@@ -71,14 +81,58 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
  * ITmfTimestamp startTime = ...;
  * ITmfTimestamp endTime = ...;
  * ITmfContext context = trace.seekEvent(startTime);
- * ITmfEvent event = trace.getEvent(context);
+ * ITmfEvent event = trace.getNext(context);
  * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
- *     // Do something ...
- *     event = trace.getEvent(context);
+ *     processEvent(event);
+ *     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>
+ *
+ * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for
+ * variants)
+ * <pre>
+ * ITmfRequest request = new TmfEventRequest&lt;MyEventType&gt;(MyEventType.class) {
+ *     &#064;Override
+ *     public void handleData(MyEventType event) {
+ *         super.handleData(event);
+ *         processEvent(event);
+ *     }
+ *
+ *     &#064;Override
+ *     public void handleCompleted() {
+ *         finish();
+ *         super.handleCompleted();
+ *     }
+ * };
+ *
+ * fTrace.handleRequest(request);
+ * if (youWant) {
+ *     request.waitForCompletion();
  * }
  * </pre>
+ *
+ * @version 1.0
+ * @author Francois Chouinard
+ *
+ * @see ITmfContext
+ * @see ITmfEvent
+ * @see ITmfTraceIndexer
+ * @see ITmfEventParser
  */
-public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> {
+public interface ITmfTrace extends ITmfDataProvider {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    /**
+     * The default trace cache size
+     */
+    public static final int DEFAULT_TRACE_CACHE_SIZE = 1000;
 
     // ------------------------------------------------------------------------
     // Initializers
@@ -88,26 +142,33 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> {
      * Initialize a newly instantiated "empty" trace object. This is used to
      * properly parameterize an ITmfTrace instantiated with its parameterless
      * constructor.
-     * 
-     * 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 FileNotFoundException
+     * <p>
+     * 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
      */
-    public void initTrace(IResource resource, String path, Class<T> type) throws FileNotFoundException;
+    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
-     * 
-     * @return true if trace is valid
+     *
+     * @param project
+     *            the eclipse project
+     * @param path
+     *            the trace path
+     * @return an IStatus object with validation result. Use severity OK to
+     *         indicate success.
+     * @since 2.0
      */
-    public boolean validate(IProject project, String path);
+    IStatus validate(IProject project, String path);
 
     // ------------------------------------------------------------------------
     // Basic getters
@@ -116,22 +177,94 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> {
     /**
      * @return the trace event type
      */
-    public Class<T> getType();
+    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
+     * @since 2.0
+     */
+    ITmfStatistics getStatistics();
+
+    /**
+     * Return the map of state systems associated with this trace.
+     *
+     * This view should be read-only (implementations should use
+     * {@link Collections#unmodifiableMap}).
+     *
+     * @return The map of state systems
+     * @since 2.0
+     */
+    Map<String, ITmfStateSystem> getStateSystems();
+
+    /**
+     * 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.
+     *
+     * @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
+     */
+    void registerStateSystem(String id, ITmfStateSystem ss);
+
+    /**
+     * 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
+     */
+    void indexTrace(boolean waitForCompletion);
+
+    /**
+     * Returns an analysis module with the given id
+     *
+     * @param analysisId
+     *            The analysis module id
+     * @return The {@link IAnalysisModule} object
+     */
+    IAnalysisModule getAnalysisModule(String analysisId);
+
+    /**
+     * Return a list of analysis modules that are of a given class
+     *
+     * @param moduleclass
+     *            Class returned module must extend
+     * @return List of {@link IAnalysisModule} of class moduleclass
+     */
+    List<IAnalysisModule> getAnalysisModules(Class<? extends IAnalysisModule> moduleclass);
+
+    /**
+     * Returns a map of analysis modules applicable to this trace. The key is
+     * the analysis id.
+     *
+     * This view should be read-only (implementations should use
+     * {@link Collections#unmodifiableMap}).
+     *
+     * @return The map of analysis modules
+     */
+    Map<String, IAnalysisModule> getAnalysisModules();
 
     // ------------------------------------------------------------------------
     // Trace characteristics getters
@@ -140,22 +273,30 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> {
     /**
      * @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)
+     */
+    long getStreamingInterval();
 
     // ------------------------------------------------------------------------
     // Trace positioning getters
@@ -163,103 +304,137 @@ public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> {
 
     /**
      * @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);
 
     // ------------------------------------------------------------------------
-    // Seek operations (returning a reading context)
+    // SeekEvent operations (returning a trace context)
     // ------------------------------------------------------------------------
 
     /**
-     * Position the trace at the specified location. The null location
-     * is used to indicate that the first trace event is requested.
+     * Position the trace at the specified (trace specific) location.
      * <p>
-     * <ul>
-     * <li> a <b>null</b> location returns the context of the first event
-     * <li> an invalid location, including beyond the last event, returns a null context
-     * </ul>
+     * A null location is interpreted as seeking for the first event of the
+     * trace.
      * <p>
-     * @param location the trace specific location (null for 1st event)
+     * 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
      * @return a context which can later be used to read the corresponding event
+     * @since 3.0
      */
-    public ITmfContext seekLocation(ITmfLocation<?> location);
+    ITmfContext seekEvent(ITmfLocation location);
 
     /**
-     * Position the trace at the event located at the specified ratio in the
-     * trace file.
+     * Position the trace at the 'rank'th event in the trace.
      * <p>
-     * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left
-     * 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
+     * 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
      * @return a context which can later be used to read the corresponding event
      */
-    public ITmfContext seekLocation(double ratio);
+    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.
      * <p>
      * 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 'rank'th event in the trace.
+     * Position the trace at the event located at the specified ratio in the
+     * trace file.
      * <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
+     * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left
+     * 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
      * @return a context which can later be used to read the corresponding event
      */
-    public ITmfContext seekEvent(long rank);
-
-    // ------------------------------------------------------------------------
-    // Read operations (returning an actual event)
-    // ------------------------------------------------------------------------
+    ITmfContext seekEvent(double ratio);
 
     /**
-     * Return the event pointed by the supplied context (or null if no event
-     * left) and updates the context to point the next event.
-     * 
-     * @param context the read context (will be updated)
-     * @return the event pointed to by the context
+     * Returns the initial range offset
+     *
+     * @return the initial range offset
+     * @since 2.0
      */
-    public ITmfEvent getNextEvent(ITmfContext context);
+    ITmfTimestamp getInitialRangeOffset();
 
     /**
-     * Return the event pointed by the supplied context (or null if no event
-     * left) and *does not* update the context.
-     * 
-     * @param context the read context
-     * @return the next event in the stream
+     * 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 host id of this trace
+     * @since 3.0
      */
-    public ITmfEvent parseEvent(ITmfContext context);
+    String getHostId();
 
     // ------------------------------------------------------------------------
+    // Timestamp transformation functions
     // ------------------------------------------------------------------------
 
     /**
-     * @return the streaming interval in ms (0 if not a streaming trace)
+     * Returns the timestamp transformation for this trace
+     *
+     * @return the timestamp transform
+     * @since 3.0
+     */
+    ITmfTimestampTransform getTimestampTransform();
+
+    /**
+     * Sets the trace's timestamp transform
+     *
+     * @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 long with which to create the timestamp
+     * @return The new timestamp
+     * @since 3.0
      */
-    public long getStreamingInterval();
+    ITmfTimestamp createTimestamp(long ts);
 
 }
This page took 0.030829 seconds and 5 git commands to generate.