Change LTTng help plugin generation
[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;
7898bb21 23import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
200789b3 24import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
8c8bf09f
ASL
25
26/**
f17b2f70
FC
27 * The event stream structure in TMF. In its basic form, a trace has:
28 * <ul>
7e6347b0
FC
29 * <li> an associated Eclipse resource
30 * <li> a path to its location on the file system
f17b2f70
FC
31 * <li> the type of the events it contains
32 * <li> the number of events it contains
33 * <li> the time range (span) of the events it contains
34 * </ul>
35 * Concrete ITmfTrace classes have to provide a parameter-less constructor and
7e6347b0 36 * an initialization method (<i>initTrace</i>) if they are to be opened from
0283f7ff 37 * the Project View. Also, a validation method (<i>validate</i>) has to be
7e6347b0 38 * provided to ensure that the trace is of the correct type.
f17b2f70
FC
39 * <p>
40 * A trace can be accessed simultaneously from multiple threads by various
41 * application components. To avoid obvious multi-threading issues, the trace
42 * uses an ITmfContext as a synchronization aid for its read operations.
43 * <p>
44 * A proper ITmfContext can be obtained by performing a seek operation on the
45 * trace. Seek operations can be performed for a particular event (by rank or
46 * timestamp) or for a plain trace location.
47 * <p>
d337369a 48 * <b>Example 1</b>: Process a whole trace
f17b2f70 49 * <pre>
7e6347b0 50 * ITmfContext context = trace.seekEvent(0);
c32744d6 51 * ITmfEvent event = trace.getNext(context);
f17b2f70 52 * while (event != null) {
d337369a 53 * processEvent(event);
c32744d6 54 * event = trace.getNext(context);
f17b2f70
FC
55 * }
56 * </pre>
57 * <b>Example 2</b>: Process 50 events starting from the 1000th event
58 * <pre>
59 * int nbEventsRead = 0;
60 * ITmfContext context = trace.seekEvent(1000);
c32744d6 61 * ITmfEvent event = trace.getNext(context);
f17b2f70
FC
62 * while (event != null && nbEventsRead < 50) {
63 * nbEventsRead++;
d337369a 64 * processEvent(event);
c32744d6 65 * event = trace.getNext(context);
f17b2f70
FC
66 * }
67 * </pre>
68 * <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
69 * <pre>
70 * ITmfTimestamp startTime = ...;
71 * ITmfTimestamp endTime = ...;
72 * ITmfContext context = trace.seekEvent(startTime);
c32744d6 73 * ITmfEvent event = trace.getNext(context);
f17b2f70 74 * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
d337369a 75 * processEvent(event);
c32744d6 76 * event = trace.getNext(context);
f17b2f70
FC
77 * }
78 * </pre>
d337369a 79 * A trace is also an event provider so it can process event requests
7e6347b0 80 * asynchronously (and coalesce compatible, concurrent requests).
d337369a
FC
81 * <p>
82 * </pre>
7e6347b0 83 * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for variants)
d337369a
FC
84 * <pre>
85 * ITmfRequest request = new TmfEventRequest&lt;MyEventType&gt;(MyEventType.class) {
86 * &#64;Override
87 * public void handleData(MyEventType event) {
88 * super.handleData(event);
89 * processEvent(event);
90 * }
91 * &#64;Override
92 * public void handleCompleted() {
93 * finish();
94 * super.handleCompleted();
95 * }
96 * };
0283f7ff 97 *
d337369a
FC
98 * fTrace.handleRequest(request);
99 * if (youWant) {
100 * request.waitForCompletion();
0283f7ff 101 * }
d337369a 102 * </pre>
0283f7ff 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 */
6256d8ad 112public interface ITmfTrace extends ITmfDataProvider {
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 */
6256d8ad 140 public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> 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 */
6256d8ad 159 public Class<? extends ITmfEvent> 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
200789b3
AM
176 /**
177 * @return The statistics provider for this trace
178 * @since 2.0
179 */
180 public ITmfStatistics getStatistics();
181
7898bb21
AM
182 /**
183 * @return The state system that is associated with this trace
184 * @since 2.0
185 */
186 public ITmfStateSystem getStateSystem();
187
25e48683
FC
188 // ------------------------------------------------------------------------
189 // Trace characteristics getters
190 // ------------------------------------------------------------------------
191
12c155f5
FC
192 /**
193 * @return the number of events in the trace
194 */
195 public long getNbEvents();
196
197 /**
3118edf1 198 * @return the trace time range
12c155f5
FC
199 */
200 public TmfTimeRange getTimeRange();
201
3118edf1
FC
202 /**
203 * @return the timestamp of the first trace event
204 */
4df4581d 205 public ITmfTimestamp getStartTime();
12c155f5 206
3118edf1
FC
207 /**
208 * @return the timestamp of the last trace event
209 */
4df4581d 210 public ITmfTimestamp getEndTime();
62d1696a 211
13cb5f43
FC
212 /**
213 * @return the streaming interval in ms (0 if not a streaming trace)
214 */
215 public long getStreamingInterval();
216
25e48683
FC
217 // ------------------------------------------------------------------------
218 // Trace positioning getters
219 // ------------------------------------------------------------------------
1b70b6dc 220
3118edf1 221 /**
25e48683 222 * @return the current trace location
3118edf1 223 */
1e1bef82 224 public ITmfLocation getCurrentLocation();
3791b5df
FC
225
226 /**
25e48683 227 * Returns the ratio (proportion) corresponding to the specified location.
0283f7ff 228 *
25e48683
FC
229 * @param location a trace specific location
230 * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
3791b5df 231 */
1e1bef82 232 public double getLocationRatio(ITmfLocation location);
3791b5df 233
8636b448 234 // ------------------------------------------------------------------------
7e6347b0 235 // SeekEvent operations (returning a trace context)
8636b448
FC
236 // ------------------------------------------------------------------------
237
12c155f5 238 /**
7e6347b0
FC
239 * Position the trace at the specified (trace specific) location.
240 * <p>
241 * A null location is interpreted as seeking for the first event of the
242 * trace.
25e48683 243 * <p>
7e6347b0
FC
244 * If not null, the location requested must be valid otherwise the returned
245 * context is undefined (up to the implementation to recover if possible).
25e48683 246 * <p>
7e6347b0 247 * @param location the trace specific location
3118edf1 248 * @return a context which can later be used to read the corresponding event
8c8bf09f 249 */
1e1bef82 250 public ITmfContext seekEvent(ITmfLocation location);
12c155f5 251
c76c54bb 252 /**
7e6347b0 253 * Position the trace at the 'rank'th event in the trace.
09e86496 254 * <p>
7e6347b0
FC
255 * A rank <= 0 is interpreted as seeking for the first event of the
256 * trace.
257 * <p>
258 * If the requested rank is beyond the last trace event, the context
259 * returned will yield a null event if used in a subsequent read.
0283f7ff 260 *
7e6347b0 261 * @param rank the event rank
3118edf1 262 * @return a context which can later be used to read the corresponding event
c76c54bb 263 */
7e6347b0 264 public ITmfContext seekEvent(long rank);
12c155f5 265
3118edf1
FC
266 /**
267 * Position the trace at the first event with the specified timestamp. If
268 * there is no event with the requested timestamp, a context pointing to
09e86496
FC
269 * the next chronological event is returned.
270 * <p>
271 * A null timestamp is interpreted as seeking for the first event of the
272 * trace.
273 * <p>
274 * If the requested timestamp is beyond the last trace event, the context
275 * returned will yield a null event if used in a subsequent read.
0283f7ff 276 *
3118edf1
FC
277 * @param timestamp the timestamp of desired event
278 * @return a context which can later be used to read the corresponding event
279 */
280 public ITmfContext seekEvent(ITmfTimestamp timestamp);
281
282 /**
7e6347b0
FC
283 * Position the trace at the event located at the specified ratio in the
284 * trace file.
09e86496 285 * <p>
7e6347b0
FC
286 * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left
287 * voluntarily vague. Typically, it would refer to the event proportional
288 * rank (arguably more intuitive) or timestamp in the trace file.
0283f7ff 289 *
7e6347b0 290 * @param ratio the proportional 'rank' in the trace
3118edf1
FC
291 * @return a context which can later be used to read the corresponding event
292 */
7e6347b0 293 public ITmfContext seekEvent(double ratio);
3118edf1 294
d7ee91bb
PT
295 /**
296 * Return the current selected time.
297 *
298 * @return the current time stamp
299 * @since 2.0
300 */
301 public ITmfTimestamp getCurrentTime();
302
303 /**
304 * Return the current selected range.
305 *
306 * @return the current time range
307 * @since 2.0
308 */
309 public TmfTimeRange getCurrentRange();
8c8bf09f 310}
This page took 0.058651 seconds and 5 git commands to generate.