Refactor TmfTrace and dependencies - finalize ITmfTraceIndexer
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / ITmfTrace.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2011, 2012 Ericsson
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
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.trace;
15
16 import java.io.FileNotFoundException;
17
18 import org.eclipse.core.resources.IProject;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
21 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
22 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
23 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
24
25 /**
26 * <b><u>ITmfTrace</u></b>
27 * <p>
28 * The event stream structure in TMF. In its basic form, a trace has:
29 * <ul>
30 * <li> the associated Eclipse resource
31 * <li> the path to its location on the file system
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
37 * an initialization method (initTace())if they are to be opened from the
38 * Project View. Also, a validation (validate()) method has to be provided to
39 * ensure that the trace is of the correct type.
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>
49 * <b>Example 1</b>: Process a whole trace
50 * <pre>
51 * ITmfContext context = trace.seekLocationt(null);
52 * ITmfEvent event = trace.getNextEvent(context);
53 * while (event != null) {
54 * processEvent(event);
55 * event = trace.getNextEvent(context);
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);
62 * ITmfEvent event = trace.getNextEvent(context);
63 * while (event != null && nbEventsRead < 50) {
64 * nbEventsRead++;
65 * processEvent(event);
66 * event = trace.getNextEvent(context);
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);
74 * ITmfEvent event = trace.getNextEvent(context);
75 * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
76 * processEvent(event);
77 * event = trace.getNextEvent(context);
78 * }
79 * </pre>
80 * A trace is also an event provider so it can process event requests
81 * asynchronously (and coalesce compatible requests).
82 * <p>
83 * </pre>
84 * <b>Example 4</b>: Process a whole trace
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 * };
98 * fTrace.handleRequest(request);
99 * if (youWant) {
100 * request.waitForCompletion();
101 * }
102 * </pre>
103 * @see ITmfEvent
104 * @see ITmfEventProvider
105 * @see ITmfRequest
106 */
107 public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> {
108
109 // ------------------------------------------------------------------------
110 // Initializers
111 // ------------------------------------------------------------------------
112
113 /**
114 * Initialize a newly instantiated "empty" trace object. This is used to
115 * properly parameterize an ITmfTrace instantiated with its parameterless
116 * constructor.
117 * <p>
118 * Typically, the parameterless constructor will provide the block size
119 * and its associated parser and indexer.
120 *
121 * @param resource the trace resource
122 * @param path the trace path
123 * @param type the trace event type
124 * @throws FileNotFoundException
125 */
126 public void initTrace(IResource resource, String path, Class<T> type) throws FileNotFoundException;
127
128 /**
129 * Validate that the trace is of the correct type.
130 *
131 * @param project the eclipse project
132 * @param path the trace path
133 *
134 * @return true if trace is valid
135 */
136 public boolean validate(IProject project, String path);
137
138 // ------------------------------------------------------------------------
139 // Basic getters
140 // ------------------------------------------------------------------------
141
142 /**
143 * @return the trace event type
144 */
145 public Class<T> getType();
146
147 /**
148 * @return the associated trace resource
149 */
150 public IResource getResource();
151
152 /**
153 * @return the trace path
154 */
155 public String getPath();
156
157 /**
158 * @return the trace cache size
159 */
160 public int getCacheSize();
161
162 // ------------------------------------------------------------------------
163 // Trace characteristics getters
164 // ------------------------------------------------------------------------
165
166 /**
167 * @return the number of events in the trace
168 */
169 public long getNbEvents();
170
171 /**
172 * @return the trace time range
173 */
174 public TmfTimeRange getTimeRange();
175
176 /**
177 * @return the timestamp of the first trace event
178 */
179 public ITmfTimestamp getStartTime();
180
181 /**
182 * @return the timestamp of the last trace event
183 */
184 public ITmfTimestamp getEndTime();
185
186 // ------------------------------------------------------------------------
187 // Trace positioning getters
188 // ------------------------------------------------------------------------
189
190 /**
191 * @return the current trace location
192 */
193 public ITmfLocation<?> getCurrentLocation();
194
195 /**
196 * Returns the ratio (proportion) corresponding to the specified location.
197 *
198 * @param location a trace specific location
199 * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
200 */
201 public double getLocationRatio(ITmfLocation<?> location);
202
203 // ------------------------------------------------------------------------
204 // Seek operations (returning a reading context)
205 // ------------------------------------------------------------------------
206
207 /**
208 * Position the trace at the specified location. The null location
209 * is used to indicate that the first trace event is requested.
210 * <p>
211 * <ul>
212 * <li> a <b>null</b> location returns the context of the first event
213 * <li> an invalid location, including beyond the last event, returns a null context
214 * </ul>
215 * <p>
216 * @param location the trace specific location (null for 1st event)
217 * @return a context which can later be used to read the corresponding event
218 */
219 public ITmfContext seekLocation(ITmfLocation<?> location);
220
221 /**
222 * Position the trace at the event located at the specified ratio in the
223 * trace file.
224 * <p>
225 * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left
226 * voluntarily vague. Typically, it would refer to the event proportional
227 * rank (arguably more intuitive) or timestamp in the trace file.
228 *
229 * @param ratio the proportional 'rank' in the trace
230 * @return a context which can later be used to read the corresponding event
231 */
232 public ITmfContext seekLocation(double ratio);
233
234 /**
235 * Position the trace at the first event with the specified timestamp. If
236 * there is no event with the requested timestamp, a context pointing to
237 * the next chronological event is returned.
238 * <p>
239 * A null timestamp is interpreted as seeking for the first event of the
240 * trace.
241 * <p>
242 * If the requested timestamp is beyond the last trace event, the context
243 * returned will yield a null event if used in a subsequent read.
244 *
245 * @param timestamp the timestamp of desired event
246 * @return a context which can later be used to read the corresponding event
247 */
248 public ITmfContext seekEvent(ITmfTimestamp timestamp);
249
250 /**
251 * Position the trace at the 'rank'th event in the trace.
252 * <p>
253 * If the requested rank is beyond the last trace event, the context
254 * returned will yield a null event if used in a subsequent read.
255 *
256 * @param rank the event rank
257 * @return a context which can later be used to read the corresponding event
258 */
259 public ITmfContext seekEvent(long rank);
260
261 // ------------------------------------------------------------------------
262 // Read operations (returning an actual event)
263 // ------------------------------------------------------------------------
264
265 /**
266 * Return the event pointed by the supplied context (or null if no event
267 * left) and updates the context to point the next event.
268 *
269 * @param context the read context (will be updated)
270 * @return the event pointed to by the context
271 */
272 public ITmfEvent getNextEvent(ITmfContext context);
273
274 /**
275 * Return the event pointed by the supplied context (or null if no event
276 * left) and *does not* update the context.
277 *
278 * @param context the read context
279 * @return the next event in the stream
280 */
281 public ITmfEvent parseEvent(ITmfContext context);
282
283 // ------------------------------------------------------------------------
284 // ------------------------------------------------------------------------
285
286 /**
287 * @return the streaming interval in ms (0 if not a streaming trace)
288 */
289 public long getStreamingInterval();
290
291 }
This page took 0.03748 seconds and 5 git commands to generate.