15666917f8a66a8b5c3c4bf91fb734efdb478631
[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>: Read a whole trace
50 * <pre>
51 * ITmfContext context = trace.seekLocationt(null);
52 * ITmfEvent event = trace.getEvent(context);
53 * while (event != null) {
54 * // Do something ...
55 * event = trace.getEvent(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.getEvent(context);
63 * while (event != null && nbEventsRead < 50) {
64 * nbEventsRead++;
65 * // Do something ...
66 * event = trace.getEvent(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.getEvent(context);
75 * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
76 * // Do something ...
77 * event = trace.getEvent(context);
78 * }
79 * </pre>
80 */
81 public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> {
82
83 // ------------------------------------------------------------------------
84 // Initializers
85 // ------------------------------------------------------------------------
86
87 /**
88 * Initialize a newly instantiated "empty" trace object. This is used to
89 * properly parameterize an ITmfTrace instantiated with its parameterless
90 * constructor.
91 *
92 * Typically, the parameterless constructor will provide the block size
93 * and its associated parser and indexer.
94 *
95 * @param resource the trace resource
96 * @param path the trace path
97 * @param type the trace event type
98 * @throws FileNotFoundException
99 */
100 public void initTrace(IResource resource, String path, Class<T> type) throws FileNotFoundException;
101
102 /**
103 * Validate that the trace is of the correct type.
104 *
105 * @param project the eclipse project
106 * @param path the trace path
107 *
108 * @return true if trace is valid
109 */
110 public boolean validate(IProject project, String path);
111
112 // ------------------------------------------------------------------------
113 // Basic getters
114 // ------------------------------------------------------------------------
115
116 /**
117 * @return the trace event type
118 */
119 public Class<T> getType();
120
121 /**
122 * @return the associated trace resource
123 */
124 public IResource getResource();
125
126 /**
127 * @return the trace path
128 */
129 public String getPath();
130
131 /**
132 * @return the trace cache size
133 */
134 public int getCacheSize();
135
136 // ------------------------------------------------------------------------
137 // Trace characteristics getters
138 // ------------------------------------------------------------------------
139
140 /**
141 * @return the number of events in the trace
142 */
143 public long getNbEvents();
144
145 /**
146 * @return the trace time range
147 */
148 public TmfTimeRange getTimeRange();
149
150 /**
151 * @return the timestamp of the first trace event
152 */
153 public ITmfTimestamp getStartTime();
154
155 /**
156 * @return the timestamp of the last trace event
157 */
158 public ITmfTimestamp getEndTime();
159
160 // ------------------------------------------------------------------------
161 // Trace positioning getters
162 // ------------------------------------------------------------------------
163
164 /**
165 * @return the current trace location
166 */
167 public ITmfLocation<?> getCurrentLocation();
168
169 /**
170 * Returns the ratio (proportion) corresponding to the specified location.
171 *
172 * @param location a trace specific location
173 * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
174 */
175 public double getLocationRatio(ITmfLocation<?> location);
176
177 // ------------------------------------------------------------------------
178 // Seek operations (returning a reading context)
179 // ------------------------------------------------------------------------
180
181 /**
182 * Position the trace at the specified location. The null location
183 * is used to indicate that the first trace event is requested.
184 * <p>
185 * <ul>
186 * <li> a <b>null</b> location returns the context of the first event
187 * <li> an invalid location, including beyond the last event, returns a null context
188 * </ul>
189 * <p>
190 * @param location the trace specific location (null for 1st event)
191 * @return a context which can later be used to read the corresponding event
192 */
193 public ITmfContext seekLocation(ITmfLocation<?> location);
194
195 /**
196 * Position the trace at the event located at the specified ratio in the
197 * trace file.
198 * <p>
199 * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left
200 * voluntarily vague. Typically, it would refer to the event proportional
201 * rank (arguably more intuitive) or timestamp in the trace file.
202 *
203 * @param ratio the proportional 'rank' in the trace
204 * @return a context which can later be used to read the corresponding event
205 */
206 public ITmfContext seekLocation(double ratio);
207
208 /**
209 * Position the trace at the first event with the specified timestamp. If
210 * there is no event with the requested timestamp, a context pointing to
211 * the next chronological event is returned.
212 * <p>
213 * A null timestamp is interpreted as seeking for the first event of the
214 * trace.
215 * <p>
216 * If the requested timestamp is beyond the last trace event, the context
217 * returned will yield a null event if used in a subsequent read.
218 *
219 * @param timestamp the timestamp of desired event
220 * @return a context which can later be used to read the corresponding event
221 */
222 public ITmfContext seekEvent(ITmfTimestamp timestamp);
223
224 /**
225 * Position the trace at the 'rank'th event in the trace.
226 * <p>
227 * If the requested rank is beyond the last trace event, the context
228 * returned will yield a null event if used in a subsequent read.
229 *
230 * @param rank the event rank
231 * @return a context which can later be used to read the corresponding event
232 */
233 public ITmfContext seekEvent(long rank);
234
235 // ------------------------------------------------------------------------
236 // Read operations (returning an actual event)
237 // ------------------------------------------------------------------------
238
239 /**
240 * Return the event pointed by the supplied context (or null if no event
241 * left) and updates the context to point the next event.
242 *
243 * @param context the read context (will be updated)
244 * @return the event pointed to by the context
245 */
246 public ITmfEvent getNextEvent(ITmfContext context);
247
248 /**
249 * Return the event pointed by the supplied context (or null if no event
250 * left) and *does not* update the context.
251 *
252 * @param context the read context
253 * @return the next event in the stream
254 */
255 public ITmfEvent parseEvent(ITmfContext context);
256
257 // ------------------------------------------------------------------------
258 // ------------------------------------------------------------------------
259
260 /**
261 * @return the streaming interval in ms (0 if not a streaming trace)
262 */
263 public long getStreamingInterval();
264
265 }
This page took 0.037805 seconds and 5 git commands to generate.