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