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