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