Commit | Line | Data |
---|---|---|
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 | 14 | package org.eclipse.linuxtools.tmf.core.trace; |
8c8bf09f | 15 | |
12c155f5 FC |
16 | import java.io.FileNotFoundException; |
17 | ||
18 | import org.eclipse.core.resources.IProject; | |
a1091415 | 19 | import org.eclipse.core.resources.IResource; |
f17b2f70 | 20 | import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider; |
72f1e62a | 21 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
4df4581d | 22 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b | 23 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; |
8c8bf09f ASL |
24 | |
25 | /** | |
146a887c | 26 | * <b><u>ITmfTrace</u></b> |
8c8bf09f | 27 | * <p> |
f17b2f70 FC |
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> | |
8c8bf09f | 80 | */ |
f17b2f70 | 81 | public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> { |
12c155f5 | 82 | |
8636b448 FC |
83 | // ------------------------------------------------------------------------ |
84 | // Initializers | |
85 | // ------------------------------------------------------------------------ | |
085d898f | 86 | |
3118edf1 FC |
87 | /** |
88 | * Initialize a newly instantiated "empty" trace object. This is used to | |
25e48683 FC |
89 | * properly parameterize an ITmfTrace instantiated with its parameterless |
90 | * constructor. | |
3118edf1 | 91 | * |
25e48683 FC |
92 | * Typically, the parameterless constructor will provide the block size |
93 | * and its associated parser and indexer. | |
94 | * | |
95 | * @param resource the trace resource | |
3118edf1 | 96 | * @param path the trace path |
3791b5df | 97 | * @param type the trace event type |
3118edf1 FC |
98 | * @throws FileNotFoundException |
99 | */ | |
25e48683 | 100 | public void initTrace(IResource resource, String path, Class<T> type) throws FileNotFoundException; |
12c155f5 | 101 | |
3118edf1 FC |
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); | |
12c155f5 | 111 | |
8636b448 | 112 | // ------------------------------------------------------------------------ |
3118edf1 | 113 | // Basic getters |
8636b448 | 114 | // ------------------------------------------------------------------------ |
b0a282fb | 115 | |
abfad0aa | 116 | /** |
25e48683 | 117 | * @return the trace event type |
12c155f5 | 118 | */ |
25e48683 | 119 | public Class<T> getType(); |
12c155f5 FC |
120 | |
121 | /** | |
25e48683 | 122 | * @return the associated trace resource |
12c155f5 | 123 | */ |
3791b5df | 124 | public IResource getResource(); |
12c155f5 | 125 | |
25e48683 FC |
126 | /** |
127 | * @return the trace path | |
128 | */ | |
129 | public String getPath(); | |
130 | ||
131 | // ------------------------------------------------------------------------ | |
132 | // Trace characteristics getters | |
133 | // ------------------------------------------------------------------------ | |
134 | ||
12c155f5 FC |
135 | /** |
136 | * @return the number of events in the trace | |
137 | */ | |
138 | public long getNbEvents(); | |
139 | ||
140 | /** | |
3118edf1 | 141 | * @return the trace time range |
12c155f5 FC |
142 | */ |
143 | public TmfTimeRange getTimeRange(); | |
144 | ||
3118edf1 FC |
145 | /** |
146 | * @return the timestamp of the first trace event | |
147 | */ | |
4df4581d | 148 | public ITmfTimestamp getStartTime(); |
12c155f5 | 149 | |
3118edf1 FC |
150 | /** |
151 | * @return the timestamp of the last trace event | |
152 | */ | |
4df4581d | 153 | public ITmfTimestamp getEndTime(); |
62d1696a | 154 | |
25e48683 FC |
155 | // ------------------------------------------------------------------------ |
156 | // Trace positioning getters | |
157 | // ------------------------------------------------------------------------ | |
1b70b6dc | 158 | |
3118edf1 | 159 | /** |
25e48683 | 160 | * @return the current trace location |
3118edf1 | 161 | */ |
25e48683 | 162 | public ITmfLocation<?> getCurrentLocation(); |
3791b5df FC |
163 | |
164 | /** | |
25e48683 | 165 | * Returns the ratio (proportion) corresponding to the specified location. |
3791b5df | 166 | * |
25e48683 FC |
167 | * @param location a trace specific location |
168 | * @return a floating-point number between 0.0 (beginning) and 1.0 (end) | |
3791b5df | 169 | */ |
25e48683 | 170 | public double getLocationRatio(ITmfLocation<?> location); |
3791b5df | 171 | |
8636b448 | 172 | // ------------------------------------------------------------------------ |
25e48683 | 173 | // Seek operations (returning a reading context) |
8636b448 FC |
174 | // ------------------------------------------------------------------------ |
175 | ||
12c155f5 | 176 | /** |
3118edf1 | 177 | * Position the trace at the specified location. The null location |
25e48683 FC |
178 | * is used to indicate that the first trace event is requested. |
179 | * <p> | |
180 | * <ul> | |
181 | * <li> a <b>null</b> location returns the context of the first event | |
182 | * <li> an invalid location, including beyond the last event, returns a null context | |
183 | * </ul> | |
184 | * <p> | |
3118edf1 FC |
185 | * @param location the trace specific location (null for 1st event) |
186 | * @return a context which can later be used to read the corresponding event | |
8c8bf09f | 187 | */ |
34ccf9a9 | 188 | public ITmfContext seekLocation(ITmfLocation<?> location); |
12c155f5 | 189 | |
c76c54bb | 190 | /** |
3118edf1 FC |
191 | * Position the trace at the event located at the specified ratio in the |
192 | * trace file. | |
09e86496 | 193 | * <p> |
3118edf1 FC |
194 | * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left |
195 | * voluntarily vague. Typically, it would refer to the event proportional | |
25e48683 | 196 | * rank (arguably more intuitive) or timestamp in the trace file. |
c76c54bb | 197 | * |
3118edf1 FC |
198 | * @param ratio the proportional 'rank' in the trace |
199 | * @return a context which can later be used to read the corresponding event | |
c76c54bb | 200 | */ |
34ccf9a9 | 201 | public ITmfContext seekLocation(double ratio); |
12c155f5 | 202 | |
3118edf1 FC |
203 | /** |
204 | * Position the trace at the first event with the specified timestamp. If | |
205 | * there is no event with the requested timestamp, a context pointing to | |
09e86496 FC |
206 | * the next chronological event is returned. |
207 | * <p> | |
208 | * A null timestamp is interpreted as seeking for the first event of the | |
209 | * trace. | |
210 | * <p> | |
211 | * If the requested timestamp is beyond the last trace event, the context | |
212 | * returned will yield a null event if used in a subsequent read. | |
3118edf1 FC |
213 | * |
214 | * @param timestamp the timestamp of desired event | |
215 | * @return a context which can later be used to read the corresponding event | |
216 | */ | |
217 | public ITmfContext seekEvent(ITmfTimestamp timestamp); | |
218 | ||
219 | /** | |
25e48683 | 220 | * Position the trace at the 'rank'th event in the trace. |
09e86496 FC |
221 | * <p> |
222 | * If the requested rank is beyond the last trace event, the context | |
223 | * returned will yield a null event if used in a subsequent read. | |
3118edf1 FC |
224 | * |
225 | * @param rank the event rank | |
226 | * @return a context which can later be used to read the corresponding event | |
227 | */ | |
228 | public ITmfContext seekEvent(long rank); | |
229 | ||
8636b448 | 230 | // ------------------------------------------------------------------------ |
25e48683 | 231 | // Read operations (returning an actual event) |
8636b448 FC |
232 | // ------------------------------------------------------------------------ |
233 | ||
234 | /** | |
3118edf1 FC |
235 | * Return the event pointed by the supplied context (or null if no event |
236 | * left) and updates the context to point the next event. | |
8636b448 | 237 | * |
25e48683 FC |
238 | * @param context the read context (will be updated) |
239 | * @return the event pointed to by the context | |
8636b448 FC |
240 | */ |
241 | public ITmfEvent getNextEvent(ITmfContext context); | |
242 | ||
243 | /** | |
3118edf1 FC |
244 | * Return the event pointed by the supplied context (or null if no event |
245 | * left) and *does not* update the context. | |
8636b448 | 246 | * |
3118edf1 | 247 | * @param context the read context |
8636b448 FC |
248 | * @return the next event in the stream |
249 | */ | |
250 | public ITmfEvent parseEvent(ITmfContext context); | |
251 | ||
25e48683 FC |
252 | // ------------------------------------------------------------------------ |
253 | // ------------------------------------------------------------------------ | |
3791b5df | 254 | |
c76c54bb | 255 | /** |
25e48683 | 256 | * @return the trace index page size |
c76c54bb | 257 | */ |
25e48683 | 258 | public int getIndexPageSize(); |
12c155f5 | 259 | |
abfad0aa | 260 | /** |
25e48683 | 261 | * @return the streaming interval in ms (0 if not a streaming trace) |
abfad0aa | 262 | */ |
25e48683 | 263 | public long getStreamingInterval(); |
085d898f | 264 | |
8c8bf09f | 265 | } |