tmf: Bump plugins version to 2.0 for Kepler branch
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / ITmfTrace.java
CommitLineData
8c8bf09f 1/*******************************************************************************
8636b448 2 * Copyright (c) 2009, 2011, 2012 Ericsson
0283f7ff 3 *
8c8bf09f
ASL
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
0283f7ff 8 *
8c8bf09f
ASL
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
8636b448 11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
8c8bf09f
ASL
12 *******************************************************************************/
13
6c13869b 14package org.eclipse.linuxtools.tmf.core.trace;
8c8bf09f 15
12c155f5 16import org.eclipse.core.resources.IProject;
a1091415 17import org.eclipse.core.resources.IResource;
f17b2f70 18import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
72f1e62a 19import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
4df4581d 20import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
6c13869b 21import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
b4f71e4a 22import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
8c8bf09f
ASL
23
24/**
f17b2f70
FC
25 * The event stream structure in TMF. In its basic form, a trace has:
26 * <ul>
7e6347b0
FC
27 * <li> an associated Eclipse resource
28 * <li> a path to its location on the file system
f17b2f70
FC
29 * <li> the type of the events it contains
30 * <li> the number of events it contains
31 * <li> the time range (span) of the events it contains
32 * </ul>
33 * Concrete ITmfTrace classes have to provide a parameter-less constructor and
7e6347b0 34 * an initialization method (<i>initTrace</i>) if they are to be opened from
0283f7ff 35 * the Project View. Also, a validation method (<i>validate</i>) has to be
7e6347b0 36 * provided to ensure that the trace is of the correct type.
f17b2f70
FC
37 * <p>
38 * A trace can be accessed simultaneously from multiple threads by various
39 * application components. To avoid obvious multi-threading issues, the trace
40 * uses an ITmfContext as a synchronization aid for its read operations.
41 * <p>
42 * A proper ITmfContext can be obtained by performing a seek operation on the
43 * trace. Seek operations can be performed for a particular event (by rank or
44 * timestamp) or for a plain trace location.
45 * <p>
d337369a 46 * <b>Example 1</b>: Process a whole trace
f17b2f70 47 * <pre>
7e6347b0 48 * ITmfContext context = trace.seekEvent(0);
c32744d6 49 * ITmfEvent event = trace.getNext(context);
f17b2f70 50 * while (event != null) {
d337369a 51 * processEvent(event);
c32744d6 52 * event = trace.getNext(context);
f17b2f70
FC
53 * }
54 * </pre>
55 * <b>Example 2</b>: Process 50 events starting from the 1000th event
56 * <pre>
57 * int nbEventsRead = 0;
58 * ITmfContext context = trace.seekEvent(1000);
c32744d6 59 * ITmfEvent event = trace.getNext(context);
f17b2f70
FC
60 * while (event != null && nbEventsRead < 50) {
61 * nbEventsRead++;
d337369a 62 * processEvent(event);
c32744d6 63 * event = trace.getNext(context);
f17b2f70
FC
64 * }
65 * </pre>
66 * <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
67 * <pre>
68 * ITmfTimestamp startTime = ...;
69 * ITmfTimestamp endTime = ...;
70 * ITmfContext context = trace.seekEvent(startTime);
c32744d6 71 * ITmfEvent event = trace.getNext(context);
f17b2f70 72 * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
d337369a 73 * processEvent(event);
c32744d6 74 * event = trace.getNext(context);
f17b2f70
FC
75 * }
76 * </pre>
d337369a 77 * A trace is also an event provider so it can process event requests
7e6347b0 78 * asynchronously (and coalesce compatible, concurrent requests).
d337369a
FC
79 * <p>
80 * </pre>
7e6347b0 81 * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for variants)
d337369a
FC
82 * <pre>
83 * ITmfRequest request = new TmfEventRequest&lt;MyEventType&gt;(MyEventType.class) {
84 * &#64;Override
85 * public void handleData(MyEventType event) {
86 * super.handleData(event);
87 * processEvent(event);
88 * }
89 * &#64;Override
90 * public void handleCompleted() {
91 * finish();
92 * super.handleCompleted();
93 * }
94 * };
0283f7ff 95 *
d337369a
FC
96 * fTrace.handleRequest(request);
97 * if (youWant) {
98 * request.waitForCompletion();
0283f7ff 99 * }
d337369a 100 * </pre>
0283f7ff
FC
101 *
102 * @param <T> The trace event type
103 *
f7703ed6
FC
104 * @version 1.0
105 * @author Francois Chouinard
0283f7ff 106 *
0316808c 107 * @see ITmfContext
d337369a 108 * @see ITmfEvent
0316808c
FC
109 * @see ITmfTraceIndexer
110 * @see ITmfEventParser
8c8bf09f 111 */
f17b2f70 112public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> {
12c155f5 113
0316808c
FC
114 // ------------------------------------------------------------------------
115 // Constants
116 // ------------------------------------------------------------------------
117
118 /**
119 * The default trace cache size
120 */
121 public static final int DEFAULT_TRACE_CACHE_SIZE = 1000;
122
8636b448
FC
123 // ------------------------------------------------------------------------
124 // Initializers
125 // ------------------------------------------------------------------------
085d898f 126
3118edf1
FC
127 /**
128 * Initialize a newly instantiated "empty" trace object. This is used to
25e48683
FC
129 * properly parameterize an ITmfTrace instantiated with its parameterless
130 * constructor.
d337369a 131 * <p>
25e48683
FC
132 * Typically, the parameterless constructor will provide the block size
133 * and its associated parser and indexer.
0283f7ff 134 *
25e48683 135 * @param resource the trace resource
3118edf1 136 * @param path the trace path
3791b5df 137 * @param type the trace event type
063f0d27 138 * @throws TmfTraceException If we couldn't open the trace
3118edf1 139 */
b4f71e4a 140 public void initTrace(IResource resource, String path, Class<T> type) throws TmfTraceException;
12c155f5 141
3118edf1
FC
142 /**
143 * Validate that the trace is of the correct type.
0283f7ff 144 *
3118edf1
FC
145 * @param project the eclipse project
146 * @param path the trace path
0283f7ff 147 *
3118edf1
FC
148 * @return true if trace is valid
149 */
150 public boolean validate(IProject project, String path);
12c155f5 151
8636b448 152 // ------------------------------------------------------------------------
3118edf1 153 // Basic getters
8636b448 154 // ------------------------------------------------------------------------
b0a282fb 155
abfad0aa 156 /**
25e48683 157 * @return the trace event type
12c155f5 158 */
13cb5f43 159 public Class<T> getEventType();
12c155f5
FC
160
161 /**
25e48683 162 * @return the associated trace resource
12c155f5 163 */
3791b5df 164 public IResource getResource();
12c155f5 165
25e48683
FC
166 /**
167 * @return the trace path
168 */
169 public String getPath();
170
20658947
FC
171 /**
172 * @return the trace cache size
173 */
174 public int getCacheSize();
175
25e48683
FC
176 // ------------------------------------------------------------------------
177 // Trace characteristics getters
178 // ------------------------------------------------------------------------
179
12c155f5
FC
180 /**
181 * @return the number of events in the trace
182 */
183 public long getNbEvents();
184
185 /**
3118edf1 186 * @return the trace time range
12c155f5
FC
187 */
188 public TmfTimeRange getTimeRange();
189
3118edf1
FC
190 /**
191 * @return the timestamp of the first trace event
192 */
4df4581d 193 public ITmfTimestamp getStartTime();
12c155f5 194
3118edf1
FC
195 /**
196 * @return the timestamp of the last trace event
197 */
4df4581d 198 public ITmfTimestamp getEndTime();
62d1696a 199
13cb5f43
FC
200 /**
201 * @return the streaming interval in ms (0 if not a streaming trace)
202 */
203 public long getStreamingInterval();
204
25e48683
FC
205 // ------------------------------------------------------------------------
206 // Trace positioning getters
207 // ------------------------------------------------------------------------
1b70b6dc 208
3118edf1 209 /**
25e48683 210 * @return the current trace location
3118edf1 211 */
25e48683 212 public ITmfLocation<?> getCurrentLocation();
3791b5df
FC
213
214 /**
25e48683 215 * Returns the ratio (proportion) corresponding to the specified location.
0283f7ff 216 *
25e48683
FC
217 * @param location a trace specific location
218 * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
3791b5df 219 */
25e48683 220 public double getLocationRatio(ITmfLocation<?> location);
3791b5df 221
8636b448 222 // ------------------------------------------------------------------------
7e6347b0 223 // SeekEvent operations (returning a trace context)
8636b448
FC
224 // ------------------------------------------------------------------------
225
12c155f5 226 /**
7e6347b0
FC
227 * Position the trace at the specified (trace specific) location.
228 * <p>
229 * A null location is interpreted as seeking for the first event of the
230 * trace.
25e48683 231 * <p>
7e6347b0
FC
232 * If not null, the location requested must be valid otherwise the returned
233 * context is undefined (up to the implementation to recover if possible).
25e48683 234 * <p>
7e6347b0 235 * @param location the trace specific location
3118edf1 236 * @return a context which can later be used to read the corresponding event
8c8bf09f 237 */
7e6347b0 238 public ITmfContext seekEvent(ITmfLocation<?> location);
12c155f5 239
c76c54bb 240 /**
7e6347b0 241 * Position the trace at the 'rank'th event in the trace.
09e86496 242 * <p>
7e6347b0
FC
243 * A rank <= 0 is interpreted as seeking for the first event of the
244 * trace.
245 * <p>
246 * If the requested rank is beyond the last trace event, the context
247 * returned will yield a null event if used in a subsequent read.
0283f7ff 248 *
7e6347b0 249 * @param rank the event rank
3118edf1 250 * @return a context which can later be used to read the corresponding event
c76c54bb 251 */
7e6347b0 252 public ITmfContext seekEvent(long rank);
12c155f5 253
3118edf1
FC
254 /**
255 * Position the trace at the first event with the specified timestamp. If
256 * there is no event with the requested timestamp, a context pointing to
09e86496
FC
257 * the next chronological event is returned.
258 * <p>
259 * A null timestamp is interpreted as seeking for the first event of the
260 * trace.
261 * <p>
262 * If the requested timestamp is beyond the last trace event, the context
263 * returned will yield a null event if used in a subsequent read.
0283f7ff 264 *
3118edf1
FC
265 * @param timestamp the timestamp of desired event
266 * @return a context which can later be used to read the corresponding event
267 */
268 public ITmfContext seekEvent(ITmfTimestamp timestamp);
269
270 /**
7e6347b0
FC
271 * Position the trace at the event located at the specified ratio in the
272 * trace file.
09e86496 273 * <p>
7e6347b0
FC
274 * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left
275 * voluntarily vague. Typically, it would refer to the event proportional
276 * rank (arguably more intuitive) or timestamp in the trace file.
0283f7ff 277 *
7e6347b0 278 * @param ratio the proportional 'rank' in the trace
3118edf1
FC
279 * @return a context which can later be used to read the corresponding event
280 */
7e6347b0 281 public ITmfContext seekEvent(double ratio);
3118edf1 282
8c8bf09f 283}
This page took 0.087569 seconds and 5 git commands to generate.