Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
0316808c | 2 | * Copyright (c) 2009, 2010, 2012 Ericsson |
ce2388e0 | 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 | |
ce2388e0 | 8 | * |
8c8bf09f ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
0316808c | 11 | * Francois Chouinard - Updated as per TMF Trace Model 1.0 |
8c8bf09f ASL |
12 | *******************************************************************************/ |
13 | ||
9e0640dc | 14 | package org.eclipse.linuxtools.tmf.core.trace; |
8c8bf09f | 15 | |
a1091415 | 16 | import org.eclipse.core.resources.IFile; |
12c155f5 | 17 | import org.eclipse.core.resources.IProject; |
828e5592 | 18 | import org.eclipse.core.resources.IResource; |
9e0640dc FC |
19 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; |
20 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation; | |
21 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfLocationArray; | |
72f1e62a | 22 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
4df4581d | 23 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b FC |
24 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; |
25 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
0316808c | 26 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
49e2f79a FC |
27 | import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest; |
28 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; | |
1b70b6dc | 29 | import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal; |
6c13869b FC |
30 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal; |
31 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal; | |
32 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; | |
33 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentUpdatedSignal; | |
34 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; | |
c32744d6 | 35 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; |
8c8bf09f ASL |
36 | |
37 | /** | |
9e0640dc | 38 | * TmfExperiment presents a time-ordered, unified view of a set of ITmfTrace:s |
cbdacf03 | 39 | * that are part of a tracing experiment. |
4b7b3670 FC |
40 | * |
41 | * @version 1.0 | |
42 | * @author Francois Chouinard | |
8c8bf09f | 43 | */ |
0316808c | 44 | public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements ITmfEventParser<T> { |
8c8bf09f | 45 | |
c32744d6 FC |
46 | // ------------------------------------------------------------------------ |
47 | // Constants | |
48 | // ------------------------------------------------------------------------ | |
49 | ||
9e0640dc FC |
50 | /** |
51 | * The default index page size | |
52 | */ | |
53 | public static final int DEFAULT_INDEX_PAGE_SIZE = 5000; | |
c32744d6 | 54 | |
8c8bf09f ASL |
55 | // ------------------------------------------------------------------------ |
56 | // Attributes | |
57 | // ------------------------------------------------------------------------ | |
58 | ||
9e0640dc FC |
59 | /** |
60 | * The currently selected experiment (null if none) | |
61 | */ | |
c32744d6 | 62 | protected static TmfExperiment<?> fCurrentExperiment = null; |
e31e01e8 | 63 | |
9e0640dc FC |
64 | /** |
65 | * The set of traces that constitute the experiment | |
66 | */ | |
c32744d6 | 67 | protected ITmfTrace<T>[] fTraces; |
8c8bf09f | 68 | |
9e0640dc FC |
69 | /** |
70 | * The set of traces that constitute the experiment | |
71 | */ | |
72 | private boolean fInitialized = false; | |
a1091415 | 73 | |
9e0640dc FC |
74 | /** |
75 | * The experiment bookmarks file | |
76 | */ | |
77 | private IFile fBookmarksFile; | |
828e5592 | 78 | |
49e2f79a FC |
79 | |
80 | // Saved experiment context (optimization) | |
81 | private TmfExperimentContext fExperimentContext; | |
82 | ||
8c8bf09f | 83 | // ------------------------------------------------------------------------ |
9e0640dc | 84 | // Construction |
8c8bf09f ASL |
85 | // ------------------------------------------------------------------------ |
86 | ||
9e0640dc FC |
87 | /** |
88 | * @param type | |
89 | * @param id | |
90 | * @param traces | |
91 | * @throws TmfTraceException | |
92 | */ | |
93 | public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces) { | |
94 | this(type, id, traces, DEFAULT_INDEX_PAGE_SIZE); | |
96c6806f PT |
95 | } |
96 | ||
8c8bf09f ASL |
97 | /** |
98 | * @param type | |
99 | * @param id | |
100 | * @param traces | |
8c8bf09f | 101 | * @param indexPageSize |
0316808c | 102 | * @throws TmfTraceException |
8c8bf09f | 103 | */ |
0316808c | 104 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
9e0640dc | 105 | public TmfExperiment(final Class<T> type, final String path, final ITmfTrace<T>[] traces, final int indexPageSize) { |
0316808c FC |
106 | setCacheSize(indexPageSize); |
107 | setStreamingInterval(0); | |
07671572 | 108 | setIndexer(new TmfCheckpointIndexer(this, indexPageSize)); |
0316808c FC |
109 | setParser(this); |
110 | try { | |
111 | super.initialize(null, path, type); | |
112 | } catch (TmfTraceException e) { | |
113 | e.printStackTrace(); | |
114 | } | |
8c8bf09f | 115 | |
a79913eb | 116 | fTraces = traces; |
a87cc4ef | 117 | setTimeRange(TmfTimeRange.NULL_RANGE); |
8c8bf09f | 118 | } |
a79913eb | 119 | |
8c8bf09f | 120 | /** |
ff4ed569 | 121 | * Clears the experiment |
8c8bf09f ASL |
122 | */ |
123 | @Override | |
12c155f5 | 124 | @SuppressWarnings("rawtypes") |
a79913eb FC |
125 | public synchronized void dispose() { |
126 | ||
cbdacf03 | 127 | final TmfExperimentDisposedSignal<T> signal = new TmfExperimentDisposedSignal<T>(this, this); |
a79913eb | 128 | broadcast(signal); |
9e0640dc FC |
129 | |
130 | if (fCurrentExperiment == this) { | |
09d11238 | 131 | fCurrentExperiment = null; |
9e0640dc | 132 | } |
a79913eb | 133 | |
77551cc2 FC |
134 | // Clean up the index if applicable |
135 | if (getIndexer() != null) { | |
136 | getIndexer().dispose(); | |
137 | } | |
b5ee6881 | 138 | |
a79913eb | 139 | if (fTraces != null) { |
cbdacf03 | 140 | for (final ITmfTrace trace : fTraces) |
a79913eb | 141 | trace.dispose(); |
a79913eb FC |
142 | fTraces = null; |
143 | } | |
2fb2eb37 | 144 | super.dispose(); |
8c8bf09f ASL |
145 | } |
146 | ||
9e0640dc FC |
147 | // ------------------------------------------------------------------------ |
148 | // ITmfTrace - Initializers | |
149 | // ------------------------------------------------------------------------ | |
150 | ||
151 | /* (non-Javadoc) | |
152 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String) | |
153 | */ | |
154 | @Override | |
155 | public boolean validate(final IProject project, final String path) { | |
156 | return true; | |
157 | } | |
158 | ||
159 | /* (non-Javadoc) | |
160 | * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#initTrace(org.eclipse.core.resources.IResource, java.lang.String, java.lang.Class) | |
161 | */ | |
162 | @Override | |
163 | public void initTrace(final IResource resource, final String path, final Class<T> type) { | |
164 | } | |
165 | ||
8c8bf09f | 166 | // ------------------------------------------------------------------------ |
e31e01e8 | 167 | // Accessors |
8c8bf09f ASL |
168 | // ------------------------------------------------------------------------ |
169 | ||
9e0640dc FC |
170 | /** |
171 | * Selects the current, framework-wide, experiment | |
172 | * | |
173 | * @param experiment das experiment | |
174 | */ | |
cbdacf03 | 175 | public static void setCurrentExperiment(final TmfExperiment<?> experiment) { |
9e0640dc | 176 | if (fCurrentExperiment != null && fCurrentExperiment != experiment) { |
09d11238 | 177 | fCurrentExperiment.dispose(); |
9e0640dc | 178 | } |
a79913eb | 179 | fCurrentExperiment = experiment; |
f6b14ce2 FC |
180 | } |
181 | ||
9e0640dc FC |
182 | /** |
183 | * @return das experiment | |
184 | */ | |
e31e01e8 | 185 | public static TmfExperiment<?> getCurrentExperiment() { |
a79913eb | 186 | return fCurrentExperiment; |
8c8bf09f ASL |
187 | } |
188 | ||
9e0640dc FC |
189 | /** |
190 | * Get the list of traces. Handle with care... | |
191 | * | |
192 | * @return the experiment traces | |
193 | */ | |
12c155f5 | 194 | public ITmfTrace<T>[] getTraces() { |
a79913eb | 195 | return fTraces; |
8c8bf09f ASL |
196 | } |
197 | ||
8c8bf09f | 198 | /** |
cbdacf03 FC |
199 | * Returns the timestamp of the event at the requested index. If none, |
200 | * returns null. | |
a79913eb | 201 | * |
0d9a6d76 FC |
202 | * @param index the event index (rank) |
203 | * @return the corresponding event timestamp | |
8c8bf09f | 204 | */ |
cbdacf03 | 205 | public ITmfTimestamp getTimestamp(final int index) { |
0316808c | 206 | final ITmfContext context = seekEvent(index); |
c32744d6 | 207 | final ITmfEvent event = getNext(context); |
a79913eb | 208 | return (event != null) ? event.getTimestamp() : null; |
8c8bf09f ASL |
209 | } |
210 | ||
9e0640dc FC |
211 | /** |
212 | * Set the file to be used for bookmarks on this experiment | |
213 | * | |
214 | * @param file the bookmarks file | |
215 | */ | |
216 | public void setBookmarksFile(final IFile file) { | |
217 | fBookmarksFile = file; | |
218 | } | |
07671572 | 219 | |
9e0640dc FC |
220 | /** |
221 | * Get the file used for bookmarks on this experiment | |
222 | * | |
223 | * @return the bookmarks file or null if none is set | |
224 | */ | |
225 | public IFile getBookmarksFile() { | |
226 | return fBookmarksFile; | |
a79913eb FC |
227 | } |
228 | ||
49e2f79a FC |
229 | // ------------------------------------------------------------------------ |
230 | // Request management | |
231 | // ------------------------------------------------------------------------ | |
232 | ||
3bd44ac8 FC |
233 | /* (non-Javadoc) |
234 | * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#armRequest(org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest) | |
235 | */ | |
49e2f79a | 236 | @Override |
408e65d2 | 237 | protected synchronized ITmfContext armRequest(final ITmfDataRequest<T> request) { |
49e2f79a FC |
238 | if (request instanceof ITmfEventRequest<?> |
239 | && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest<T>) request).getRange().getStartTime()) | |
240 | && request.getIndex() == 0) | |
241 | { | |
242 | final ITmfContext context = seekEvent(((ITmfEventRequest<T>) request).getRange().getStartTime()); | |
243 | ((ITmfEventRequest<T>) request).setStartIndex((int) context.getRank()); | |
244 | return context; | |
245 | ||
246 | } | |
247 | ||
248 | // Check if we are already at the right index | |
249 | if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex()) { | |
250 | return fExperimentContext; | |
251 | } | |
252 | ||
253 | return seekEvent(request.getIndex()); | |
254 | } | |
255 | ||
a79913eb | 256 | // ------------------------------------------------------------------------ |
9f584e4c FC |
257 | // ITmfTrace trace positioning |
258 | // ------------------------------------------------------------------------ | |
259 | ||
3bd44ac8 FC |
260 | /* (non-Javadoc) |
261 | * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#seekEvent(long) | |
262 | * | |
263 | * TmfTrace.seekEvent(rank) will return a context that will position the | |
264 | * trace to read the event at rank 'rank' in the trace. In the case of an | |
265 | * experiment context, that event has to be actually read in the fEvents | |
266 | * buffer and the corresponding trace context has to point to the next | |
267 | * event (rank + 1) in the trace (the sum of the traces contexts ranks | |
268 | * should equal [exp context rank + #traces] (corner cases not considered). | |
269 | * | |
270 | * In the likely case that TmfTrace.seekEvent() computed the context | |
271 | * by using a read loop (reading from the experiment), the 'lastTraceRead' | |
272 | * field will be set to the actual trace that needs to be read to obtain | |
273 | * event at rank 'rank'. | |
274 | * | |
275 | * Therefore, if 'lastTraceRead' is set, we need to read that particular | |
276 | * trace *and* then decrease the context rank (which has to correspond to | |
277 | * the rank of the event to be returned next by TmfExperiemnt.getNext(). | |
278 | */ | |
279 | @Override | |
280 | public synchronized ITmfContext seekEvent(final long rank) { | |
281 | TmfExperimentContext context = (TmfExperimentContext) super.seekEvent(rank); | |
282 | int lastTrace = context.getLastTrace(); | |
283 | if (lastTrace != TmfExperimentContext.NO_TRACE) { | |
284 | getNext(context); | |
285 | context.setRank(rank); | |
286 | context.setLastTrace(TmfExperimentContext.NO_TRACE); | |
287 | } | |
288 | return context; | |
289 | } | |
290 | ||
9e0640dc FC |
291 | /* (non-Javadoc) |
292 | * | |
293 | * Returns a brand new context based on the location provided and | |
294 | * initializes the event queues | |
295 | * | |
296 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation) | |
297 | */ | |
a79913eb | 298 | @Override |
9e0640dc | 299 | public synchronized ITmfContext seekEvent(final ITmfLocation<?> location) { |
a79913eb | 300 | // Validate the location |
9e0640dc | 301 | if (location != null && !(location instanceof TmfExperimentLocation)) { |
a79913eb | 302 | return null; // Throw an exception? |
9e0640dc FC |
303 | } |
304 | // Make sure we have something to read from | |
305 | if (fTraces == null) { | |
a79913eb | 306 | return null; |
9e0640dc | 307 | } |
8f50c396 | 308 | |
a79913eb | 309 | // Instantiate the location |
9e0640dc FC |
310 | final TmfExperimentLocation expLocation = (location == null) |
311 | ? new TmfExperimentLocation(new TmfLocationArray(new ITmfLocation<?>[fTraces.length])) | |
312 | : (TmfExperimentLocation) location.clone(); | |
8f50c396 | 313 | |
a79913eb | 314 | // Create and populate the context's traces contexts |
0316808c | 315 | final TmfExperimentContext context = new TmfExperimentContext(new ITmfContext[fTraces.length]); |
9b635e61 | 316 | |
a79913eb FC |
317 | for (int i = 0; i < fTraces.length; i++) { |
318 | // Get the relevant trace attributes | |
3bd44ac8 FC |
319 | final ITmfLocation<?> trcLocation = expLocation.getLocation().getLocations()[i]; |
320 | context.getContexts()[i] = fTraces[i].seekEvent(trcLocation); | |
0316808c | 321 | expLocation.getLocation().getLocations()[i] = context.getContexts()[i].getLocation().clone(); |
c32744d6 | 322 | context.getEvents()[i] = fTraces[i].getNext(context.getContexts()[i]); |
a79913eb | 323 | } |
8f50c396 | 324 | |
a79913eb FC |
325 | // Finalize context |
326 | context.setLocation(expLocation); | |
327 | context.setLastTrace(TmfExperimentContext.NO_TRACE); | |
0316808c | 328 | context.setRank(ITmfContext.UNKNOWN_RANK); |
49e2f79a FC |
329 | |
330 | fExperimentContext = context; | |
9e0640dc | 331 | return (ITmfContext) context; |
a79913eb | 332 | } |
9f584e4c | 333 | |
3bd44ac8 FC |
334 | // ------------------------------------------------------------------------ |
335 | // ITmfTrace - SeekEvent operations (returning a trace context) | |
336 | // ------------------------------------------------------------------------ | |
337 | ||
9e0640dc FC |
338 | /* (non-Javadoc) |
339 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(double) | |
340 | */ | |
c76c54bb | 341 | @Override |
0316808c FC |
342 | public ITmfContext seekEvent(final double ratio) { |
343 | final ITmfContext context = seekEvent((long) (ratio * getNbEvents())); | |
c76c54bb FC |
344 | return context; |
345 | } | |
346 | ||
9e0640dc FC |
347 | /* (non-Javadoc) |
348 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getLocationRatio(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation) | |
349 | */ | |
a79913eb | 350 | @Override |
cbdacf03 | 351 | public double getLocationRatio(final ITmfLocation<?> location) { |
9e0640dc | 352 | if (location instanceof TmfExperimentLocation) { |
7e6347b0 | 353 | return (double) seekEvent(location).getRank() / getNbEvents(); |
9e0640dc FC |
354 | } |
355 | return 0.0; | |
c76c54bb FC |
356 | } |
357 | ||
9e0640dc FC |
358 | /* (non-Javadoc) |
359 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentLocation() | |
360 | */ | |
a79913eb FC |
361 | @Override |
362 | public ITmfLocation<?> getCurrentLocation() { | |
a87cc4ef FC |
363 | ITmfLocation<?>[] locations = new ITmfLocation<?>[fTraces.length]; |
364 | for (int i = 0; i < fTraces.length; i++) { | |
365 | locations[i] = fTraces[i].getCurrentLocation(); | |
366 | } | |
367 | return new TmfExperimentLocation(new TmfLocationArray(locations)); | |
a79913eb | 368 | } |
c76c54bb | 369 | |
9e0640dc FC |
370 | // ------------------------------------------------------------------------ |
371 | // ITmfTrace trace positioning | |
372 | // ------------------------------------------------------------------------ | |
373 | ||
07671572 | 374 | /* (non-Javadoc) |
408e65d2 | 375 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser#parseEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext) |
07671572 FC |
376 | */ |
377 | @Override | |
408e65d2 FC |
378 | public synchronized T parseEvent(final ITmfContext context) { |
379 | final ITmfContext savedContext = context.clone(); | |
380 | final T event = getNext(savedContext); | |
07671572 FC |
381 | return event; |
382 | } | |
a79913eb | 383 | |
ce2388e0 | 384 | /* (non-Javadoc) |
408e65d2 | 385 | * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#getNext(org.eclipse.linuxtools.tmf.core.trace.ITmfContext) |
a79913eb | 386 | */ |
0316808c | 387 | @Override |
3bd44ac8 | 388 | @SuppressWarnings("unchecked") |
408e65d2 | 389 | public synchronized T getNext(ITmfContext context) { |
a79913eb FC |
390 | |
391 | // Validate the context | |
9e0640dc | 392 | if (!(context instanceof TmfExperimentContext)) { |
a79913eb | 393 | return null; // Throw an exception? |
9e0640dc | 394 | } |
a87cc4ef | 395 | TmfExperimentContext expContext = (TmfExperimentContext) context; |
a79913eb | 396 | |
a87cc4ef | 397 | // If an event was consumed previously, first get the next one from that trace |
cbdacf03 | 398 | final int lastTrace = expContext.getLastTrace(); |
a79913eb | 399 | if (lastTrace != TmfExperimentContext.NO_TRACE) { |
cbdacf03 | 400 | final ITmfContext traceContext = expContext.getContexts()[lastTrace]; |
3bd44ac8 FC |
401 | |
402 | TmfExperimentLocation location = (TmfExperimentLocation) expContext.getLocation(); | |
403 | if (location != null) { | |
404 | location.getLocation().getLocations()[lastTrace] = traceContext.getLocation().clone(); | |
405 | } | |
406 | ||
c32744d6 | 407 | expContext.getEvents()[lastTrace] = fTraces[lastTrace].getNext(traceContext); |
a79913eb | 408 | expContext.setLastTrace(TmfExperimentContext.NO_TRACE); |
a79913eb FC |
409 | } |
410 | ||
411 | // Scan the candidate events and identify the "next" trace to read from | |
412 | int trace = TmfExperimentContext.NO_TRACE; | |
a4115405 | 413 | ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH; |
0316808c | 414 | for (int i = 0; i < fTraces.length; i++) { |
cbdacf03 | 415 | final ITmfEvent event = expContext.getEvents()[i]; |
a79913eb | 416 | if (event != null && event.getTimestamp() != null) { |
cbdacf03 | 417 | final ITmfTimestamp otherTS = event.getTimestamp(); |
a79913eb FC |
418 | if (otherTS.compareTo(timestamp, true) < 0) { |
419 | trace = i; | |
420 | timestamp = otherTS; | |
421 | } | |
422 | } | |
423 | } | |
a87cc4ef FC |
424 | |
425 | T event = null; | |
07671572 | 426 | if (trace != TmfExperimentContext.NO_TRACE) { |
a87cc4ef | 427 | event = (T) expContext.getEvents()[trace]; |
408e65d2 FC |
428 | if (event != null) { |
429 | updateAttributes(expContext, event.getTimestamp()); | |
408e65d2 FC |
430 | expContext.increaseRank(); |
431 | expContext.setLastTrace(trace); | |
432 | fExperimentContext = expContext; | |
433 | processEvent(event); | |
434 | } | |
07671572 | 435 | } |
a87cc4ef | 436 | |
a87cc4ef | 437 | return event; |
a79913eb FC |
438 | } |
439 | ||
bcbea6a6 | 440 | /* (non-Javadoc) |
a79913eb FC |
441 | * @see java.lang.Object#toString() |
442 | */ | |
443 | @Override | |
3b38ea61 | 444 | @SuppressWarnings("nls") |
a79913eb FC |
445 | public String toString() { |
446 | return "[TmfExperiment (" + getName() + ")]"; | |
447 | } | |
8c8bf09f ASL |
448 | |
449 | // ------------------------------------------------------------------------ | |
9e0640dc | 450 | // Streaming support |
8c8bf09f ASL |
451 | // ------------------------------------------------------------------------ |
452 | ||
1b70b6dc | 453 | private synchronized void initializeStreamingMonitor() { |
9e0640dc FC |
454 | |
455 | if (fInitialized) { | |
828e5592 | 456 | return; |
9e0640dc | 457 | } |
828e5592 PT |
458 | fInitialized = true; |
459 | ||
1b70b6dc | 460 | if (getStreamingInterval() == 0) { |
0316808c | 461 | final ITmfContext context = seekEvent(0); |
cbdacf03 FC |
462 | final ITmfEvent event = getNext(context); |
463 | if (event == null) | |
1b70b6dc | 464 | return; |
cbdacf03 | 465 | final TmfTimeRange timeRange = new TmfTimeRange(event.getTimestamp().clone(), TmfTimestamp.BIG_CRUNCH); |
828e5592 PT |
466 | final TmfExperimentRangeUpdatedSignal signal = new TmfExperimentRangeUpdatedSignal(this, this, timeRange); |
467 | ||
468 | // Broadcast in separate thread to prevent deadlock | |
469 | new Thread() { | |
470 | @Override | |
471 | public void run() { | |
472 | broadcast(signal); | |
473 | } | |
474 | }.start(); | |
1b70b6dc PT |
475 | return; |
476 | } | |
477 | ||
9e0640dc | 478 | final Thread thread = new Thread("Streaming Monitor for experiment " + getName()) { //$NON-NLS-1$ |
bcbea6a6 FC |
479 | private ITmfTimestamp safeTimestamp = null; |
480 | private TmfTimeRange timeRange = null; | |
1b70b6dc PT |
481 | |
482 | @Override | |
483 | public void run() { | |
484 | while (!fExecutor.isShutdown()) { | |
9e0640dc | 485 | if (!getIndexer().isIndexing()) { |
a4115405 FC |
486 | ITmfTimestamp startTimestamp = TmfTimestamp.BIG_CRUNCH; |
487 | ITmfTimestamp endTimestamp = TmfTimestamp.BIG_BANG; | |
cbdacf03 FC |
488 | for (final ITmfTrace<T> trace : fTraces) { |
489 | if (trace.getStartTime().compareTo(startTimestamp) < 0) | |
1b70b6dc | 490 | startTimestamp = trace.getStartTime(); |
cbdacf03 | 491 | if (trace.getStreamingInterval() != 0 && trace.getEndTime().compareTo(endTimestamp) > 0) |
1b70b6dc | 492 | endTimestamp = trace.getEndTime(); |
1b70b6dc | 493 | } |
cbdacf03 | 494 | if (safeTimestamp != null && safeTimestamp.compareTo(getTimeRange().getEndTime(), false) > 0) |
1b70b6dc | 495 | timeRange = new TmfTimeRange(startTimestamp, safeTimestamp); |
cbdacf03 | 496 | else |
1b70b6dc | 497 | timeRange = null; |
1b70b6dc PT |
498 | safeTimestamp = endTimestamp; |
499 | if (timeRange != null) { | |
cbdacf03 | 500 | final TmfExperimentRangeUpdatedSignal signal = |
1b70b6dc PT |
501 | new TmfExperimentRangeUpdatedSignal(TmfExperiment.this, TmfExperiment.this, timeRange); |
502 | broadcast(signal); | |
503 | } | |
504 | } | |
505 | try { | |
506 | Thread.sleep(getStreamingInterval()); | |
cbdacf03 | 507 | } catch (final InterruptedException e) { |
1b70b6dc PT |
508 | e.printStackTrace(); |
509 | } | |
510 | } | |
511 | } | |
512 | }; | |
513 | thread.start(); | |
514 | } | |
515 | ||
9e0640dc | 516 | /* (non-Javadoc) |
1b70b6dc PT |
517 | * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getStreamingInterval() |
518 | */ | |
519 | @Override | |
520 | public long getStreamingInterval() { | |
521 | long interval = 0; | |
cbdacf03 | 522 | for (final ITmfTrace<T> trace : fTraces) |
1b70b6dc | 523 | interval = Math.max(interval, trace.getStreamingInterval()); |
1b70b6dc PT |
524 | return interval; |
525 | } | |
526 | ||
8c8bf09f ASL |
527 | // ------------------------------------------------------------------------ |
528 | // Signal handlers | |
529 | // ------------------------------------------------------------------------ | |
530 | ||
9e0640dc | 531 | private Integer fEndSynchReference; |
c32744d6 | 532 | |
9e0640dc FC |
533 | /** |
534 | * Signal handler for the TmfExperimentSelectedSignal signal | |
535 | * | |
536 | * @param signal | |
537 | */ | |
8c8bf09f | 538 | @TmfSignalHandler |
cbdacf03 FC |
539 | public void experimentSelected(final TmfExperimentSelectedSignal<T> signal) { |
540 | final TmfExperiment<?> experiment = signal.getExperiment(); | |
a79913eb FC |
541 | if (experiment == this) { |
542 | setCurrentExperiment(experiment); | |
6e85c58d | 543 | fEndSynchReference = Integer.valueOf(signal.getReference()); |
a79913eb | 544 | } |
8c8bf09f ASL |
545 | } |
546 | ||
9e0640dc FC |
547 | /** |
548 | * Signal handler for the TmfEndSynchSignal signal | |
549 | * | |
550 | * @param signal | |
551 | */ | |
1b70b6dc | 552 | @TmfSignalHandler |
cbdacf03 | 553 | public void endSync(final TmfEndSynchSignal signal) { |
1b70b6dc PT |
554 | if (fEndSynchReference != null && fEndSynchReference.intValue() == signal.getReference()) { |
555 | fEndSynchReference = null; | |
556 | initializeStreamingMonitor(); | |
557 | } | |
1b70b6dc PT |
558 | } |
559 | ||
828e5592 | 560 | /** |
9e0640dc | 561 | * Signal handler for the TmfTraceUpdatedSignal signal |
cbdacf03 | 562 | * |
9e0640dc | 563 | * @param signal |
828e5592 | 564 | */ |
9e0640dc FC |
565 | @TmfSignalHandler |
566 | public void traceUpdated(final TmfTraceUpdatedSignal signal) { | |
567 | if (signal.getTrace() == this) { | |
568 | broadcast(new TmfExperimentUpdatedSignal(this, this)); | |
569 | } | |
a1091415 PT |
570 | } |
571 | ||
572 | /** | |
9e0640dc | 573 | * Signal handler for the TmfExperimentRangeUpdatedSignal signal |
cbdacf03 | 574 | * |
9e0640dc | 575 | * @param signal |
a1091415 | 576 | */ |
9e0640dc FC |
577 | @TmfSignalHandler |
578 | public void experimentRangeUpdated(final TmfExperimentRangeUpdatedSignal signal) { | |
579 | if (signal.getExperiment() == this) { | |
580 | getIndexer().buildIndex(getNbEvents(), signal.getRange(), false); | |
581 | } | |
a1091415 PT |
582 | } |
583 | ||
4dc47e28 | 584 | } |