Commit | Line | Data |
---|---|---|
8a6ff07f | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2015 École Polytechnique de Montréal |
8a6ff07f GB |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
baa96b1d | 11 | * Bernd Hufmann - Integrated history builder functionality |
8a6ff07f GB |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.core.statesystem; |
8a6ff07f | 15 | |
5db5a3a4 AM |
16 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
17 | ||
8a6ff07f | 18 | import java.io.File; |
baa96b1d | 19 | import java.io.IOException; |
5237a931 | 20 | import java.util.Collections; |
ef06db91 GB |
21 | import java.util.HashMap; |
22 | import java.util.Map; | |
09ec275e | 23 | import java.util.concurrent.CountDownLatch; |
8a6ff07f | 24 | |
ef06db91 | 25 | import org.apache.commons.io.FileUtils; |
8a6ff07f | 26 | import org.eclipse.core.runtime.IProgressMonitor; |
e1c415b3 | 27 | import org.eclipse.core.runtime.IStatus; |
baa96b1d | 28 | import org.eclipse.core.runtime.NullProgressMonitor; |
ef06db91 | 29 | import org.eclipse.jdt.annotation.NonNull; |
baa96b1d | 30 | import org.eclipse.jdt.annotation.Nullable; |
ef06db91 | 31 | import org.eclipse.tracecompass.common.core.NonNullUtils; |
2bdf0193 AM |
32 | import org.eclipse.tracecompass.internal.tmf.core.statesystem.backends.partial.PartialHistoryBackend; |
33 | import org.eclipse.tracecompass.internal.tmf.core.statesystem.backends.partial.PartialStateSystem; | |
e894a508 AM |
34 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
35 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; | |
36 | import org.eclipse.tracecompass.statesystem.core.StateSystemFactory; | |
37 | import org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend; | |
0306a843 | 38 | import org.eclipse.tracecompass.statesystem.core.backend.StateHistoryBackendFactory; |
2bdf0193 AM |
39 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule; |
40 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
41 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; | |
ef06db91 | 42 | import org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider; |
2bdf0193 AM |
43 | import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest; |
44 | import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest; | |
de83d1ab MAL |
45 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; |
46 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal; | |
2bdf0193 AM |
47 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; |
48 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
de83d1ab | 49 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceCompleteness; |
2bdf0193 | 50 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; |
b8585c7c | 51 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; |
5c5fa260 | 52 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; |
8a6ff07f GB |
53 | |
54 | /** | |
55 | * Abstract analysis module to generate a state system. It is a base class that | |
56 | * can be used as a shortcut by analysis who just need to build a single state | |
57 | * system with a state provider. | |
58 | * | |
59 | * Analysis implementing this class should only need to provide a state system | |
60 | * and optionally a backend (default to NULL) and, if required, a filename | |
61 | * (defaults to the analysis'ID) | |
62 | * | |
63 | * @author Geneviève Bastien | |
8a6ff07f GB |
64 | */ |
65 | public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisModule | |
ef06db91 | 66 | implements ITmfAnalysisModuleWithStateSystems, ITmfPropertiesProvider { |
8a6ff07f | 67 | |
8a6ff07f GB |
68 | private static final String EXTENSION = ".ht"; //$NON-NLS-1$ |
69 | ||
09ec275e | 70 | private final CountDownLatch fInitialized = new CountDownLatch(1); |
de83d1ab | 71 | private final Object fRequestSyncObj = new Object(); |
09ec275e | 72 | |
baa96b1d BH |
73 | @Nullable private ITmfStateSystemBuilder fStateSystem; |
74 | @Nullable private ITmfStateProvider fStateProvider; | |
75 | @Nullable private IStateHistoryBackend fHtBackend; | |
76 | @Nullable private ITmfEventRequest fRequest; | |
de83d1ab MAL |
77 | @Nullable private TmfTimeRange fTimeRange = null; |
78 | ||
79 | private int fNbRead = 0; | |
c81ffdf2 | 80 | private boolean fInitializationSucceeded; |
5237a931 | 81 | |
8a6ff07f GB |
82 | /** |
83 | * State system backend types | |
84 | * | |
85 | * @author Geneviève Bastien | |
86 | */ | |
87 | protected enum StateSystemBackendType { | |
88 | /** Full history in file */ | |
89 | FULL, | |
90 | /** In memory state system */ | |
91 | INMEM, | |
92 | /** Null history */ | |
93 | NULL, | |
94 | /** State system backed with partial history */ | |
95 | PARTIAL | |
96 | } | |
97 | ||
72221aa4 AM |
98 | /** |
99 | * Retrieve a state system belonging to trace, by passing the ID of the | |
100 | * relevant analysis module. | |
101 | * | |
102 | * This will start the execution of the analysis module, and start the | |
103 | * construction of the state system, if needed. | |
104 | * | |
105 | * @param trace | |
106 | * The trace for which you want the state system | |
107 | * @param moduleId | |
108 | * The ID of the state system analysis module | |
c81ffdf2 JCK |
109 | * @return The state system, or null if there was no match or the module was |
110 | * not initialized correctly | |
72221aa4 AM |
111 | */ |
112 | public static @Nullable ITmfStateSystem getStateSystem(ITmfTrace trace, String moduleId) { | |
113 | TmfStateSystemAnalysisModule module = | |
b8585c7c | 114 | TmfTraceUtils.getAnalysisModuleOfClass(trace, TmfStateSystemAnalysisModule.class, moduleId); |
72221aa4 | 115 | if (module != null) { |
e8e09aa3 GB |
116 | ITmfStateSystem ss = module.getStateSystem(); |
117 | if (ss != null) { | |
118 | return ss; | |
119 | } | |
e1c415b3 BH |
120 | IStatus status = module.schedule(); |
121 | if (status.isOK()) { | |
c81ffdf2 | 122 | return module.waitForInitialization() ? module.getStateSystem() : null; |
e1c415b3 | 123 | } |
72221aa4 AM |
124 | } |
125 | return null; | |
126 | } | |
127 | ||
8a6ff07f GB |
128 | /** |
129 | * Get the state provider for this analysis module | |
130 | * | |
131 | * @return the state provider | |
132 | */ | |
8a6ff07f GB |
133 | protected abstract ITmfStateProvider createStateProvider(); |
134 | ||
135 | /** | |
136 | * Get the state system backend type used by this module | |
137 | * | |
138 | * @return The {@link StateSystemBackendType} | |
139 | */ | |
a3b864c0 AM |
140 | protected StateSystemBackendType getBackendType() { |
141 | /* Using full history by default, sub-classes can override */ | |
142 | return StateSystemBackendType.FULL; | |
143 | } | |
8a6ff07f GB |
144 | |
145 | /** | |
146 | * Get the supplementary file name where to save this state system. The | |
147 | * default is the ID of the analysis followed by the extension. | |
148 | * | |
149 | * @return The supplementary file name | |
150 | */ | |
151 | protected String getSsFileName() { | |
152 | return getId() + EXTENSION; | |
153 | } | |
154 | ||
155 | /** | |
baa96b1d BH |
156 | * Get the state system generated by this analysis, or null if it is not yet |
157 | * created. | |
8a6ff07f GB |
158 | * |
159 | * @return The state system | |
160 | */ | |
baa96b1d | 161 | @Nullable |
8a6ff07f GB |
162 | public ITmfStateSystem getStateSystem() { |
163 | return fStateSystem; | |
164 | } | |
165 | ||
c81ffdf2 JCK |
166 | /** |
167 | * @since 2.0 | |
168 | */ | |
6537ccdd | 169 | @Override |
c81ffdf2 | 170 | public boolean waitForInitialization() { |
09ec275e AM |
171 | try { |
172 | fInitialized.await(); | |
c81ffdf2 JCK |
173 | } catch (InterruptedException e) { |
174 | return false; | |
175 | } | |
176 | return fInitializationSucceeded; | |
09ec275e AM |
177 | } |
178 | ||
baa96b1d BH |
179 | // ------------------------------------------------------------------------ |
180 | // TmfAbstractAnalysisModule | |
181 | // ------------------------------------------------------------------------ | |
8a6ff07f | 182 | |
ef06db91 GB |
183 | private @Nullable File getSsFile() { |
184 | ITmfTrace trace = getTrace(); | |
185 | if (trace == null) { | |
186 | return null; | |
187 | } | |
188 | String directory = TmfTraceManager.getSupplementaryFileDir(trace); | |
189 | File htFile = new File(directory + getSsFileName()); | |
190 | return htFile; | |
191 | } | |
192 | ||
baa96b1d BH |
193 | @Override |
194 | protected boolean executeAnalysis(@Nullable final IProgressMonitor monitor) { | |
195 | IProgressMonitor mon = (monitor == null ? new NullProgressMonitor() : monitor); | |
196 | final ITmfStateProvider provider = createStateProvider(); | |
8a6ff07f | 197 | |
84a9548a | 198 | String id = getId(); |
84a9548a | 199 | |
8a6ff07f GB |
200 | /* FIXME: State systems should make use of the monitor, to be cancelled */ |
201 | try { | |
202 | /* Get the state system according to backend */ | |
203 | StateSystemBackendType backend = getBackendType(); | |
ef06db91 | 204 | |
e1c415b3 BH |
205 | |
206 | ITmfTrace trace = getTrace(); | |
207 | if (trace == null) { | |
208 | // Analysis was cancelled in the meantime | |
fa6e7869 | 209 | analysisReady(false); |
e1c415b3 BH |
210 | return false; |
211 | } | |
8a6ff07f | 212 | switch (backend) { |
ef06db91 GB |
213 | case FULL: { |
214 | File htFile = getSsFile(); | |
215 | if (htFile == null) { | |
216 | return false; | |
217 | } | |
84a9548a | 218 | createFullHistory(id, provider, htFile); |
ef06db91 | 219 | } |
8a6ff07f | 220 | break; |
ef06db91 GB |
221 | case PARTIAL: { |
222 | File htFile = getSsFile(); | |
223 | if (htFile == null) { | |
224 | return false; | |
225 | } | |
84a9548a | 226 | createPartialHistory(id, provider, htFile); |
ef06db91 | 227 | } |
8a6ff07f GB |
228 | break; |
229 | case INMEM: | |
84a9548a | 230 | createInMemoryHistory(id, provider); |
8a6ff07f GB |
231 | break; |
232 | case NULL: | |
84a9548a | 233 | createNullHistory(id, provider); |
8a6ff07f GB |
234 | break; |
235 | default: | |
236 | break; | |
237 | } | |
238 | } catch (TmfTraceException e) { | |
fa6e7869 | 239 | analysisReady(false); |
8a6ff07f GB |
240 | return false; |
241 | } | |
baa96b1d | 242 | return !mon.isCanceled(); |
8a6ff07f GB |
243 | } |
244 | ||
fa6e7869 JCK |
245 | /** |
246 | * Make the module available and set whether the initialization succeeded or | |
247 | * not. If not, no state system is available and | |
248 | * {@link #waitForInitialization()} should return false. | |
249 | * | |
250 | * @param success | |
251 | * True if the initialization succeeded, false otherwise | |
252 | */ | |
253 | private void analysisReady(boolean succeeded) { | |
254 | fInitializationSucceeded = succeeded; | |
255 | fInitialized.countDown(); | |
256 | } | |
257 | ||
8a6ff07f GB |
258 | @Override |
259 | protected void canceling() { | |
baa96b1d BH |
260 | ITmfEventRequest req = fRequest; |
261 | if ((req != null) && (!req.isCompleted())) { | |
262 | req.cancel(); | |
263 | } | |
264 | } | |
265 | ||
a1529f38 AM |
266 | @Override |
267 | public void dispose() { | |
130e6f4e | 268 | super.dispose(); |
a1529f38 AM |
269 | if (fStateSystem != null) { |
270 | fStateSystem.dispose(); | |
271 | } | |
a1529f38 AM |
272 | } |
273 | ||
baa96b1d BH |
274 | // ------------------------------------------------------------------------ |
275 | // History creation methods | |
276 | // ------------------------------------------------------------------------ | |
277 | ||
278 | /* | |
279 | * Load the history file matching the target trace. If the file already | |
280 | * exists, it will be opened directly. If not, it will be created from | |
281 | * scratch. | |
282 | */ | |
84a9548a | 283 | private void createFullHistory(String id, ITmfStateProvider provider, File htFile) throws TmfTraceException { |
baa96b1d BH |
284 | |
285 | /* If the target file already exists, do not rebuild it uselessly */ | |
286 | // TODO for now we assume it's complete. Might be a good idea to check | |
287 | // at least if its range matches the trace's range. | |
288 | ||
289 | if (htFile.exists()) { | |
290 | /* Load an existing history */ | |
291 | final int version = provider.getVersion(); | |
292 | try { | |
0306a843 AM |
293 | IStateHistoryBackend backend = StateHistoryBackendFactory.createHistoryTreeBackendExistingFile( |
294 | id, htFile, version); | |
84a9548a | 295 | fHtBackend = backend; |
b2f62cb5 | 296 | fStateSystem = StateSystemFactory.newStateSystem(backend, false); |
fa6e7869 | 297 | analysisReady(true); |
baa96b1d BH |
298 | return; |
299 | } catch (IOException e) { | |
300 | /* | |
301 | * There was an error opening the existing file. Perhaps it was | |
302 | * corrupted, perhaps it's an old version? We'll just | |
303 | * fall-through and try to build a new one from scratch instead. | |
304 | */ | |
305 | } | |
306 | } | |
307 | ||
308 | /* Size of the blocking queue to use when building a state history */ | |
4cdea8fc | 309 | final int QUEUE_SIZE = 10000; |
baa96b1d BH |
310 | |
311 | try { | |
0306a843 | 312 | IStateHistoryBackend backend = StateHistoryBackendFactory.createHistoryTreeBackendNewFile( |
f6d24a71 | 313 | id, htFile, provider.getVersion(), provider.getStartTime(), QUEUE_SIZE); |
84a9548a | 314 | fHtBackend = backend; |
b2f62cb5 | 315 | fStateSystem = StateSystemFactory.newStateSystem(backend); |
baa96b1d BH |
316 | provider.assignTargetStateSystem(fStateSystem); |
317 | build(provider); | |
318 | } catch (IOException e) { | |
319 | /* | |
320 | * If it fails here however, it means there was a problem writing to | |
321 | * the disk, so throw a real exception this time. | |
322 | */ | |
323 | throw new TmfTraceException(e.toString(), e); | |
324 | } | |
325 | } | |
326 | ||
327 | /* | |
328 | * Create a new state system backed with a partial history. A partial | |
329 | * history is similar to a "full" one (which you get with | |
330 | * {@link #newFullHistory}), except that the file on disk is much smaller, | |
331 | * but queries are a bit slower. | |
332 | * | |
333 | * Also note that single-queries are implemented using a full-query | |
334 | * underneath, (which are much slower), so this might not be a good fit for | |
335 | * a use case where you have to do lots of single queries. | |
336 | */ | |
84a9548a | 337 | private void createPartialHistory(String id, ITmfStateProvider provider, File htPartialFile) |
baa96b1d BH |
338 | throws TmfTraceException { |
339 | /* | |
340 | * The order of initializations is very tricky (but very important!) | |
341 | * here. We need to follow this pattern: | |
342 | * (1 is done before the call to this method) | |
343 | * | |
344 | * 1- Instantiate realStateProvider | |
345 | * 2- Instantiate realBackend | |
346 | * 3- Instantiate partialBackend, with prereqs: | |
347 | * 3a- Instantiate partialProvider, via realProvider.getNew() | |
348 | * 3b- Instantiate nullBackend (partialSS's backend) | |
349 | * 3c- Instantiate partialSS | |
350 | * 3d- partialProvider.assignSS(partialSS) | |
351 | * 4- Instantiate realSS | |
352 | * 5- partialSS.assignUpstream(realSS) | |
353 | * 6- realProvider.assignSS(realSS) | |
354 | * 7- Call HistoryBuilder(realProvider, realSS, partialBackend) to build the thing. | |
355 | */ | |
356 | ||
357 | /* Size of the blocking queue to use when building a state history */ | |
358 | final int QUEUE_SIZE = 10000; | |
359 | ||
360 | final long granularity = 50000; | |
361 | ||
362 | /* 2 */ | |
363 | IStateHistoryBackend realBackend = null; | |
364 | try { | |
0306a843 | 365 | realBackend = StateHistoryBackendFactory.createHistoryTreeBackendNewFile( |
f6d24a71 | 366 | id, htPartialFile, provider.getVersion(), provider.getStartTime(), QUEUE_SIZE); |
baa96b1d BH |
367 | } catch (IOException e) { |
368 | throw new TmfTraceException(e.toString(), e); | |
369 | } | |
370 | ||
371 | /* 3a */ | |
372 | ITmfStateProvider partialProvider = provider.getNewInstance(); | |
373 | ||
374 | /* 3b-3c, constructor automatically uses a NullBackend */ | |
375 | PartialStateSystem pss = new PartialStateSystem(); | |
376 | ||
377 | /* 3d */ | |
378 | partialProvider.assignTargetStateSystem(pss); | |
379 | ||
380 | /* 3 */ | |
651cbda0 | 381 | IStateHistoryBackend partialBackend = new PartialHistoryBackend(id + ".partial", partialProvider, pss, realBackend, granularity); //$NON-NLS-1$ |
baa96b1d BH |
382 | |
383 | /* 4 */ | |
bcec0116 | 384 | @SuppressWarnings("restriction") |
e894a508 | 385 | org.eclipse.tracecompass.internal.statesystem.core.StateSystem realSS = |
b2f62cb5 | 386 | (org.eclipse.tracecompass.internal.statesystem.core.StateSystem) StateSystemFactory.newStateSystem(partialBackend); |
baa96b1d BH |
387 | |
388 | /* 5 */ | |
389 | pss.assignUpstream(realSS); | |
390 | ||
391 | /* 6 */ | |
392 | provider.assignTargetStateSystem(realSS); | |
393 | ||
394 | /* 7 */ | |
395 | fHtBackend = partialBackend; | |
396 | fStateSystem = realSS; | |
397 | ||
398 | build(provider); | |
399 | } | |
400 | ||
401 | /* | |
402 | * Create a new state system using a null history back-end. This means that | |
403 | * no history intervals will be saved anywhere, and as such only | |
404 | * {@link ITmfStateSystem#queryOngoingState} will be available. | |
405 | */ | |
84a9548a | 406 | private void createNullHistory(String id, ITmfStateProvider provider) { |
0306a843 | 407 | IStateHistoryBackend backend = StateHistoryBackendFactory.createNullBackend(id); |
84a9548a | 408 | fHtBackend = backend; |
b2f62cb5 | 409 | fStateSystem = StateSystemFactory.newStateSystem(backend); |
baa96b1d BH |
410 | provider.assignTargetStateSystem(fStateSystem); |
411 | build(provider); | |
412 | } | |
413 | ||
414 | /* | |
415 | * Create a new state system using in-memory interval storage. This should | |
416 | * only be done for very small state system, and will be naturally limited | |
417 | * to 2^31 intervals. | |
418 | */ | |
84a9548a | 419 | private void createInMemoryHistory(String id, ITmfStateProvider provider) { |
0306a843 | 420 | IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(id, provider.getStartTime()); |
84a9548a | 421 | fHtBackend = backend; |
b2f62cb5 | 422 | fStateSystem = StateSystemFactory.newStateSystem(backend); |
baa96b1d BH |
423 | provider.assignTargetStateSystem(fStateSystem); |
424 | build(provider); | |
425 | } | |
426 | ||
a1529f38 | 427 | private void disposeProvider(boolean deleteFiles) { |
baa96b1d BH |
428 | ITmfStateProvider provider = fStateProvider; |
429 | if (provider != null) { | |
430 | provider.dispose(); | |
431 | } | |
432 | if (deleteFiles && (fHtBackend != null)) { | |
433 | fHtBackend.removeFiles(); | |
434 | } | |
435 | } | |
436 | ||
437 | private void build(ITmfStateProvider provider) { | |
438 | if ((fStateSystem == null) || (fHtBackend == null)) { | |
439 | throw new IllegalArgumentException(); | |
440 | } | |
441 | ||
442 | ITmfEventRequest request = fRequest; | |
443 | if ((request != null) && (!request.isCompleted())) { | |
444 | request.cancel(); | |
445 | } | |
446 | ||
de83d1ab MAL |
447 | fTimeRange = TmfTimeRange.ETERNITY; |
448 | final ITmfTrace trace = provider.getTrace(); | |
d0c7e4ba | 449 | if (!isCompleteTrace(trace)) { |
6cfc180e | 450 | fTimeRange = trace.getTimeRange(); |
de83d1ab | 451 | } |
baa96b1d | 452 | |
baa96b1d | 453 | fStateProvider = provider; |
de83d1ab MAL |
454 | synchronized (fRequestSyncObj) { |
455 | startRequest(); | |
456 | } | |
baa96b1d | 457 | |
09ec275e AM |
458 | /* |
459 | * The state system object is now created, we can consider this module | |
460 | * "initialized" (components can retrieve it and start doing queries). | |
461 | */ | |
fa6e7869 | 462 | analysisReady(true); |
09ec275e AM |
463 | |
464 | /* | |
465 | * Block the executeAnalysis() construction is complete (so that the | |
466 | * progress monitor displays that it is running). | |
467 | */ | |
baa96b1d | 468 | try { |
de83d1ab MAL |
469 | if (fRequest != null) { |
470 | fRequest.waitForCompletion(); | |
471 | } | |
baa96b1d BH |
472 | } catch (InterruptedException e) { |
473 | e.printStackTrace(); | |
474 | } | |
475 | } | |
476 | ||
477 | private class StateSystemEventRequest extends TmfEventRequest { | |
478 | private final ITmfStateProvider sci; | |
479 | private final ITmfTrace trace; | |
480 | ||
de83d1ab | 481 | public StateSystemEventRequest(ITmfStateProvider sp, TmfTimeRange timeRange, int index) { |
e2bcc8a5 | 482 | super(ITmfEvent.class, |
de83d1ab MAL |
483 | timeRange, |
484 | index, | |
baa96b1d BH |
485 | ITmfEventRequest.ALL_DATA, |
486 | ITmfEventRequest.ExecutionType.BACKGROUND); | |
487 | this.sci = sp; | |
488 | ||
489 | // sci.getTrace() will eventually return a @NonNull | |
5db5a3a4 | 490 | trace = checkNotNull(sci.getTrace()); |
baa96b1d | 491 | |
baa96b1d BH |
492 | } |
493 | ||
494 | @Override | |
41f3b36b | 495 | public void handleData(final ITmfEvent event) { |
baa96b1d | 496 | super.handleData(event); |
41f3b36b | 497 | if (event.getTrace() == trace) { |
baa96b1d | 498 | sci.processEvent(event); |
2d208fb7 GB |
499 | } else if (trace instanceof TmfExperiment) { |
500 | /* | |
501 | * If the request is for an experiment, check if the event is | |
502 | * from one of the child trace | |
503 | */ | |
504 | for (ITmfTrace childTrace : ((TmfExperiment) trace).getTraces()) { | |
505 | if (childTrace == event.getTrace()) { | |
506 | sci.processEvent(event); | |
507 | } | |
508 | } | |
baa96b1d BH |
509 | } |
510 | } | |
511 | ||
512 | @Override | |
513 | public void handleSuccess() { | |
514 | super.handleSuccess(); | |
de83d1ab MAL |
515 | if (isCompleteTrace(trace)) { |
516 | disposeProvider(false); | |
517 | } else { | |
518 | fNbRead += getNbRead(); | |
519 | synchronized (fRequestSyncObj) { | |
520 | final TmfTimeRange timeRange = fTimeRange; | |
521 | if (timeRange != null) { | |
522 | if (getRange().getEndTime().getValue() < timeRange.getEndTime().getValue()) { | |
523 | startRequest(); | |
524 | } | |
525 | } | |
526 | } | |
527 | } | |
baa96b1d BH |
528 | } |
529 | ||
530 | @Override | |
531 | public void handleCancel() { | |
532 | super.handleCancel(); | |
de83d1ab MAL |
533 | if (isCompleteTrace(trace)) { |
534 | disposeProvider(true); | |
535 | } | |
baa96b1d BH |
536 | } |
537 | ||
538 | @Override | |
539 | public void handleFailure() { | |
540 | super.handleFailure(); | |
a1529f38 | 541 | disposeProvider(true); |
baa96b1d | 542 | } |
8a6ff07f GB |
543 | } |
544 | ||
5237a931 AM |
545 | // ------------------------------------------------------------------------ |
546 | // ITmfAnalysisModuleWithStateSystems | |
547 | // ------------------------------------------------------------------------ | |
548 | ||
549 | @Override | |
baa96b1d BH |
550 | @Nullable |
551 | public ITmfStateSystem getStateSystem(String id) { | |
5237a931 AM |
552 | if (id.equals(getId())) { |
553 | return fStateSystem; | |
554 | } | |
555 | return null; | |
556 | } | |
557 | ||
8a6ff07f | 558 | @Override |
11b771eb | 559 | public @NonNull Iterable<@NonNull ITmfStateSystem> getStateSystems() { |
aa353506 AM |
560 | ITmfStateSystemBuilder stateSystem = fStateSystem; |
561 | if (stateSystem == null) { | |
562 | return Collections.EMPTY_SET; | |
563 | } | |
564 | return Collections.singleton(stateSystem); | |
8a6ff07f | 565 | } |
de83d1ab MAL |
566 | |
567 | /** | |
568 | * Signal handler for the TmfTraceRangeUpdatedSignal signal | |
569 | * | |
570 | * @param signal The incoming signal | |
571 | */ | |
572 | @TmfSignalHandler | |
573 | public void traceRangeUpdated(final TmfTraceRangeUpdatedSignal signal) { | |
574 | fTimeRange = signal.getRange(); | |
575 | ITmfStateProvider stateProvider = fStateProvider; | |
576 | synchronized (fRequestSyncObj) { | |
577 | if (signal.getTrace() == getTrace() && stateProvider != null && stateProvider.getAssignedStateSystem() != null) { | |
578 | ITmfEventRequest request = fRequest; | |
579 | if ((request == null) || request.isCompleted()) { | |
580 | startRequest(); | |
581 | } | |
582 | } | |
583 | } | |
584 | } | |
585 | ||
586 | private void startRequest() { | |
587 | ITmfStateProvider stateProvider = fStateProvider; | |
588 | TmfTimeRange timeRange = fTimeRange; | |
589 | if (stateProvider == null || timeRange == null) { | |
590 | return; | |
591 | } | |
592 | ITmfEventRequest request = new StateSystemEventRequest(stateProvider, timeRange, fNbRead); | |
593 | stateProvider.getTrace().sendRequest(request); | |
594 | fRequest = request; | |
595 | } | |
596 | ||
597 | private static boolean isCompleteTrace(ITmfTrace trace) { | |
598 | return !(trace instanceof ITmfTraceCompleteness) || ((ITmfTraceCompleteness) trace).isComplete(); | |
599 | } | |
ef06db91 GB |
600 | |
601 | // ------------------------------------------------------------------------ | |
602 | // ITmfPropertiesProvider | |
603 | // ------------------------------------------------------------------------ | |
604 | ||
605 | /** | |
606 | * @since 2.0 | |
607 | */ | |
608 | @Override | |
609 | public @NonNull Map<@NonNull String, @NonNull String> getProperties() { | |
610 | Map<@NonNull String, @NonNull String> properties = new HashMap<>(); | |
611 | ||
612 | StateSystemBackendType backend = getBackendType(); | |
613 | properties.put(NonNullUtils.checkNotNull(Messages.TmfStateSystemAnalysisModule_PropertiesBackend), NonNullUtils.checkNotNull(backend.name())); | |
614 | switch (backend) { | |
615 | case FULL: | |
616 | case PARTIAL: | |
617 | File htFile = getSsFile(); | |
618 | if (htFile != null) { | |
619 | if (htFile.exists()) { | |
620 | properties.put(NonNullUtils.checkNotNull(Messages.TmfStateSystemAnalysisModule_PropertiesFileSize), FileUtils.byteCountToDisplaySize(htFile.length())); | |
621 | } else { | |
622 | properties.put(NonNullUtils.checkNotNull(Messages.TmfStateSystemAnalysisModule_PropertiesFileSize), NonNullUtils.checkNotNull(Messages.TmfStateSystemAnalysisModule_PropertiesAnalysisNotExecuted)); | |
623 | } | |
624 | } | |
625 | break; | |
626 | case INMEM: | |
627 | case NULL: | |
628 | default: | |
629 | break; | |
630 | ||
631 | } | |
632 | return properties; | |
633 | } | |
8a6ff07f | 634 | } |