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