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