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