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