Commit | Line | Data |
---|---|---|
fc526aef | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2015 Ericsson |
fc526aef AM |
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 | * Alexandre Montplaisir - Initial API and implementation | |
0fcf3b09 | 11 | * Patrick Tasse - Support selection range |
d3de0920 | 12 | * Xavier Raynaud - Support filters tracking |
fc526aef AM |
13 | *******************************************************************************/ |
14 | ||
2bdf0193 | 15 | package org.eclipse.tracecompass.tmf.core.trace; |
fc526aef | 16 | |
5db5a3a4 AM |
17 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
18 | ||
e1385db9 | 19 | import java.io.File; |
cad998a7 | 20 | import java.io.IOException; |
3ec38c4c | 21 | import java.net.URISyntaxException; |
c14c0757 | 22 | import java.util.Collection; |
fab18d20 | 23 | import java.util.Collections; |
fc526aef | 24 | import java.util.LinkedHashMap; |
0f8687b4 | 25 | import java.util.LinkedHashSet; |
e2239aea | 26 | import java.util.List; |
fc526aef | 27 | import java.util.Map; |
fab18d20 | 28 | import java.util.Set; |
fc526aef | 29 | |
cad998a7 | 30 | import org.apache.commons.io.FileUtils; |
deaae6e1 | 31 | import org.eclipse.core.resources.IFile; |
b5e8ee95 GB |
32 | import org.eclipse.core.resources.IFolder; |
33 | import org.eclipse.core.resources.IProject; | |
e1385db9 AM |
34 | import org.eclipse.core.resources.IResource; |
35 | import org.eclipse.core.runtime.CoreException; | |
1ac53e54 | 36 | import org.eclipse.core.runtime.URIUtil; |
0f8687b4 | 37 | import org.eclipse.jdt.annotation.NonNull; |
bcd8d4b1 | 38 | import org.eclipse.jdt.annotation.NonNullByDefault; |
21852dfa | 39 | import org.eclipse.jdt.annotation.Nullable; |
2bdf0193 AM |
40 | import org.eclipse.tracecompass.internal.tmf.core.Activator; |
41 | import org.eclipse.tracecompass.tmf.core.TmfCommonConstants; | |
2bdf0193 | 42 | import org.eclipse.tracecompass.tmf.core.signal.TmfEventFilterAppliedSignal; |
16801c72 | 43 | import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal; |
2bdf0193 AM |
44 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; |
45 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; | |
2bdf0193 | 46 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal; |
178d3c0e | 47 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceModelSignal; |
2bdf0193 AM |
48 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; |
49 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal; | |
16801c72 | 50 | import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal; |
2bdf0193 AM |
51 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
52 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; | |
53 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; | |
5c5fa260 | 54 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; |
fc526aef | 55 | |
c14c0757 GB |
56 | import com.google.common.collect.ImmutableSet; |
57 | ||
fc526aef AM |
58 | /** |
59 | * Central trace manager for TMF. It tracks the currently opened traces and | |
0fcf3b09 | 60 | * experiment, as well as the currently-selected time or time range and the |
d3de0920 XR |
61 | * current window time range for each one of those. It also tracks filters |
62 | * applied for each trace. | |
fc526aef AM |
63 | * |
64 | * It's a singleton class, so only one instance should exist (available via | |
65 | * {@link #getInstance()}). | |
66 | * | |
67 | * @author Alexandre Montplaisir | |
fc526aef | 68 | */ |
bcd8d4b1 | 69 | @NonNullByDefault |
fc526aef AM |
70 | public final class TmfTraceManager { |
71 | ||
72 | // ------------------------------------------------------------------------ | |
73 | // Attributes | |
74 | // ------------------------------------------------------------------------ | |
75 | ||
76 | private final Map<ITmfTrace, TmfTraceContext> fTraces; | |
77 | ||
78 | /** The currently-selected trace. Should always be part of the trace map */ | |
bcd8d4b1 | 79 | private @Nullable ITmfTrace fCurrentTrace = null; |
fc526aef | 80 | |
3ec38c4c MAL |
81 | private static final String TEMP_DIR_NAME = ".temp"; //$NON-NLS-1$ |
82 | ||
fc526aef AM |
83 | // ------------------------------------------------------------------------ |
84 | // Constructor | |
85 | // ------------------------------------------------------------------------ | |
86 | ||
87 | private TmfTraceManager() { | |
a4524c1b | 88 | fTraces = new LinkedHashMap<>(); |
fc526aef AM |
89 | TmfSignalManager.registerVIP(this); |
90 | } | |
91 | ||
92 | /** Singleton instance */ | |
bcd8d4b1 | 93 | private static @Nullable TmfTraceManager tm = null; |
fc526aef AM |
94 | |
95 | /** | |
96 | * Get an instance of the trace manager. | |
97 | * | |
98 | * @return The trace manager | |
99 | */ | |
100 | public static synchronized TmfTraceManager getInstance() { | |
bcd8d4b1 AM |
101 | TmfTraceManager mgr = tm; |
102 | if (mgr == null) { | |
103 | mgr = new TmfTraceManager(); | |
104 | tm = mgr; | |
fc526aef | 105 | } |
bcd8d4b1 | 106 | return mgr; |
fc526aef AM |
107 | } |
108 | ||
109 | // ------------------------------------------------------------------------ | |
110 | // Accessors | |
111 | // ------------------------------------------------------------------------ | |
112 | ||
fc526aef AM |
113 | /** |
114 | * Get the currently selected trace (normally, the focused editor). | |
115 | * | |
bcd8d4b1 AM |
116 | * @return The active trace, or <code>null</code> if there is no active |
117 | * trace | |
fc526aef | 118 | */ |
bcd8d4b1 | 119 | public synchronized @Nullable ITmfTrace getActiveTrace() { |
fc526aef AM |
120 | return fCurrentTrace; |
121 | } | |
122 | ||
123 | /** | |
a6fc3a28 | 124 | * Get the trace set of the currently active trace. |
fc526aef | 125 | * |
bcd8d4b1 AM |
126 | * @return The active trace set. Empty (but non-null) if there is no |
127 | * currently active trace. | |
a6fc3a28 | 128 | * @see #getTraceSet(ITmfTrace) |
fc526aef | 129 | */ |
bcd8d4b1 | 130 | public synchronized Collection<ITmfTrace> getActiveTraceSet() { |
fc526aef | 131 | final ITmfTrace trace = fCurrentTrace; |
a6fc3a28 | 132 | return getTraceSet(trace); |
fc526aef AM |
133 | } |
134 | ||
fab18d20 AM |
135 | /** |
136 | * Get the currently-opened traces, as an unmodifiable set. | |
137 | * | |
138 | * @return A set containing the opened traces | |
139 | */ | |
140 | public synchronized Set<ITmfTrace> getOpenedTraces() { | |
141 | return Collections.unmodifiableSet(fTraces.keySet()); | |
142 | } | |
143 | ||
deaae6e1 PT |
144 | /** |
145 | * Get the editor file for an opened trace. | |
146 | * | |
147 | * @param trace | |
148 | * the trace | |
149 | * @return the editor file or null if the trace is not opened | |
deaae6e1 | 150 | */ |
bcd8d4b1 | 151 | public synchronized @Nullable IFile getTraceEditorFile(ITmfTrace trace) { |
deaae6e1 PT |
152 | TmfTraceContext ctx = fTraces.get(trace); |
153 | if (ctx != null) { | |
154 | return ctx.getEditorFile(); | |
155 | } | |
156 | return null; | |
157 | } | |
158 | ||
21852dfa AM |
159 | /** |
160 | * Get the {@link TmfTraceContext} of the current active trace. This can be | |
161 | * used to retrieve the current active/selected time ranges and such. | |
162 | * | |
163 | * @return The trace's context. | |
164 | * @since 1.0 | |
165 | */ | |
166 | public synchronized TmfTraceContext getCurrentTraceContext() { | |
fc526aef AM |
167 | TmfTraceContext curCtx = fTraces.get(fCurrentTrace); |
168 | if (curCtx == null) { | |
169 | /* There are no traces opened at the moment. */ | |
170 | return TmfTraceContext.NULL_CONTEXT; | |
171 | } | |
172 | return curCtx; | |
173 | } | |
174 | ||
e1385db9 AM |
175 | // ------------------------------------------------------------------------ |
176 | // Public utility methods | |
177 | // ------------------------------------------------------------------------ | |
178 | ||
a6fc3a28 AM |
179 | /** |
180 | * Get the trace set of a given trace. For a standard trace, this is simply | |
181 | * an array with only that trace in it. For experiments, this is an array of | |
182 | * all the traces contained in this experiment. | |
183 | * | |
184 | * @param trace | |
bcd8d4b1 AM |
185 | * The trace or experiment. If it is null, an empty collection |
186 | * will be returned. | |
c14c0757 | 187 | * @return The corresponding trace set. |
a6fc3a28 | 188 | */ |
bcd8d4b1 | 189 | public static Collection<ITmfTrace> getTraceSet(@Nullable ITmfTrace trace) { |
a6fc3a28 | 190 | if (trace == null) { |
0e4f957e | 191 | return ImmutableSet.of(); |
a6fc3a28 | 192 | } |
df2597e0 | 193 | List<@NonNull ITmfTrace> traces = trace.getChildren(ITmfTrace.class); |
e2239aea | 194 | if (traces.size() > 0) { |
0e4f957e | 195 | return ImmutableSet.copyOf(traces); |
a6fc3a28 | 196 | } |
0e4f957e | 197 | return ImmutableSet.of(trace); |
a6fc3a28 AM |
198 | } |
199 | ||
0f8687b4 GB |
200 | /** |
201 | * Get the trace set of a given trace or experiment, including the | |
202 | * experiment. For a standard trace, this is simply a set containing only | |
203 | * that trace. For experiments, it is the set of all the traces contained in | |
204 | * this experiment, along with the experiment. | |
205 | * | |
206 | * @param trace | |
bcd8d4b1 AM |
207 | * The trace or experiment. If it is null, an empty collection |
208 | * will be returned. | |
c14c0757 | 209 | * @return The corresponding trace set, including the experiment. |
0f8687b4 | 210 | */ |
bcd8d4b1 | 211 | public static Collection<ITmfTrace> getTraceSetWithExperiment(@Nullable ITmfTrace trace) { |
0f8687b4 | 212 | if (trace == null) { |
0e4f957e | 213 | return ImmutableSet.of(); |
0f8687b4 GB |
214 | } |
215 | if (trace instanceof TmfExperiment) { | |
216 | TmfExperiment exp = (TmfExperiment) trace; | |
fa62dc1d BH |
217 | List<ITmfTrace> traces = exp.getTraces(); |
218 | Set<ITmfTrace> alltraces = new LinkedHashSet<>(traces); | |
0f8687b4 | 219 | alltraces.add(exp); |
0e4f957e | 220 | return ImmutableSet.copyOf(alltraces); |
0f8687b4 | 221 | } |
0e4f957e | 222 | return Collections.singleton(trace); |
0f8687b4 GB |
223 | } |
224 | ||
e1385db9 AM |
225 | /** |
226 | * Return the path (as a string) to the directory for supplementary files to | |
227 | * use with a given trace. If no supplementary file directory has been | |
228 | * configured, a temporary directory based on the trace's name will be | |
229 | * provided. | |
230 | * | |
231 | * @param trace | |
232 | * The trace | |
233 | * @return The path to the supplementary file directory (trailing slash is | |
234 | * INCLUDED!) | |
235 | */ | |
236 | public static String getSupplementaryFileDir(ITmfTrace trace) { | |
237 | IResource resource = trace.getResource(); | |
238 | if (resource == null) { | |
239 | return getTemporaryDir(trace); | |
240 | } | |
241 | ||
242 | String supplDir = null; | |
243 | try { | |
244 | supplDir = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER); | |
245 | } catch (CoreException e) { | |
246 | return getTemporaryDir(trace); | |
247 | } | |
248 | return supplDir + File.separator; | |
249 | } | |
250 | ||
b5e8ee95 GB |
251 | /** |
252 | * Refresh the supplementary files resources for a trace, so it can pick up | |
253 | * new files that got created. | |
254 | * | |
255 | * @param trace | |
256 | * The trace for which to refresh the supplementary files | |
b5e8ee95 GB |
257 | */ |
258 | public static void refreshSupplementaryFiles(ITmfTrace trace) { | |
259 | IResource resource = trace.getResource(); | |
88567ed2 | 260 | if (resource != null && resource.exists()) { |
b5e8ee95 GB |
261 | String supplFolderPath = getSupplementaryFileDir(trace); |
262 | IProject project = resource.getProject(); | |
263 | /* Remove the project's path from the supplementary path dir */ | |
cdb43c16 | 264 | if (!supplFolderPath.startsWith(project.getLocation().toOSString())) { |
b5e8ee95 GB |
265 | Activator.logWarning(String.format("Supplementary files folder for trace %s is not within the project.", trace.getName())); //$NON-NLS-1$ |
266 | return; | |
267 | } | |
268 | IFolder supplFolder = project.getFolder(supplFolderPath.substring(project.getLocationURI().getPath().length())); | |
269 | if (supplFolder.exists()) { | |
270 | try { | |
271 | supplFolder.refreshLocal(IResource.DEPTH_INFINITE, null); | |
272 | } catch (CoreException e) { | |
273 | Activator.logError("Error refreshing resources", e); //$NON-NLS-1$ | |
274 | } | |
275 | } | |
276 | } | |
277 | } | |
278 | ||
cad998a7 AM |
279 | /** |
280 | * Delete the supplementary files of a given trace. | |
281 | * | |
282 | * @param trace | |
283 | * The trace for which the supplementary files are to be deleted | |
284 | * @since 2.2 | |
285 | */ | |
286 | public static void deleteSupplementaryFiles(ITmfTrace trace) { | |
287 | try { | |
288 | FileUtils.cleanDirectory(new File(TmfTraceManager.getSupplementaryFileDir(trace))); | |
289 | } catch (IOException e) { | |
290 | Activator.logError("Error deleting supplementary files for trace " + trace.getName(), e); //$NON-NLS-1$ | |
291 | } | |
292 | refreshSupplementaryFiles(trace); | |
293 | } | |
294 | ||
fc526aef AM |
295 | // ------------------------------------------------------------------------ |
296 | // Signal handlers | |
297 | // ------------------------------------------------------------------------ | |
298 | ||
299 | /** | |
300 | * Signal handler for the traceOpened signal. | |
301 | * | |
302 | * @param signal | |
303 | * The incoming signal | |
304 | */ | |
305 | @TmfSignalHandler | |
306 | public synchronized void traceOpened(final TmfTraceOpenedSignal signal) { | |
307 | final ITmfTrace trace = signal.getTrace(); | |
deaae6e1 | 308 | final IFile editorFile = signal.getEditorFile(); |
fc526aef AM |
309 | final ITmfTimestamp startTs = trace.getStartTime(); |
310 | ||
16801c72 MK |
311 | long offset = trace.getInitialRangeOffset().toNanos(); |
312 | long endTime = startTs.toNanos() + offset; | |
21852dfa | 313 | final TmfTimeRange selectionRange = new TmfTimeRange(startTs, startTs); |
b2c971ec | 314 | final TmfTimeRange windowRange = new TmfTimeRange(startTs, TmfTimestamp.fromNanos(endTime)); |
fc526aef | 315 | |
ccc49be1 | 316 | final TmfTraceContext startCtx = trace.createTraceContext(selectionRange, windowRange, editorFile, null); |
fc526aef AM |
317 | |
318 | fTraces.put(trace, startCtx); | |
319 | ||
320 | /* We also want to set the newly-opened trace as the active trace */ | |
321 | fCurrentTrace = trace; | |
322 | } | |
323 | ||
ccc49be1 MK |
324 | /** |
325 | * Signal propagator | |
bcd8d4b1 AM |
326 | * |
327 | * @param signal | |
328 | * any signal | |
ccc49be1 MK |
329 | * @since 2.0 |
330 | */ | |
331 | @TmfSignalHandler | |
bcd8d4b1 | 332 | public synchronized void signalReceived(final TmfTraceModelSignal signal) { |
ccc49be1 MK |
333 | fTraces.forEach((t, u) -> u.receive(signal)); |
334 | } | |
335 | ||
336 | ||
fc526aef AM |
337 | /** |
338 | * Handler for the TmfTraceSelectedSignal. | |
339 | * | |
340 | * @param signal | |
341 | * The incoming signal | |
342 | */ | |
343 | @TmfSignalHandler | |
344 | public synchronized void traceSelected(final TmfTraceSelectedSignal signal) { | |
345 | final ITmfTrace newTrace = signal.getTrace(); | |
346 | if (!fTraces.containsKey(newTrace)) { | |
347 | throw new RuntimeException(); | |
348 | } | |
349 | fCurrentTrace = newTrace; | |
350 | } | |
351 | ||
d3de0920 XR |
352 | /** |
353 | * Signal handler for the filterApplied signal. | |
354 | * | |
355 | * @param signal | |
356 | * The incoming signal | |
d3de0920 XR |
357 | */ |
358 | @TmfSignalHandler | |
359 | public synchronized void filterApplied(TmfEventFilterAppliedSignal signal) { | |
360 | final ITmfTrace newTrace = signal.getTrace(); | |
361 | TmfTraceContext context = fTraces.get(newTrace); | |
362 | if (context == null) { | |
363 | throw new RuntimeException(); | |
364 | } | |
178d3c0e | 365 | final TmfTraceContext newContext = newTrace.createTraceContext(context.getSelectionRange(), |
21852dfa AM |
366 | context.getWindowRange(), |
367 | context.getEditorFile(), | |
178d3c0e JCK |
368 | signal.getEventFilter()); |
369 | newContext.setData(context.getData()); | |
370 | fTraces.put(newTrace, newContext); | |
d3de0920 XR |
371 | } |
372 | ||
fc526aef AM |
373 | /** |
374 | * Signal handler for the traceClosed signal. | |
375 | * | |
376 | * @param signal | |
377 | * The incoming signal | |
378 | */ | |
379 | @TmfSignalHandler | |
380 | public synchronized void traceClosed(final TmfTraceClosedSignal signal) { | |
3fcf269e | 381 | fTraces.remove(signal.getTrace()); |
fc526aef AM |
382 | if (fTraces.size() == 0) { |
383 | fCurrentTrace = null; | |
384 | /* | |
385 | * In other cases, we should receive a traceSelected signal that | |
386 | * will indicate which trace is the new one. | |
387 | */ | |
388 | } | |
389 | } | |
390 | ||
391 | /** | |
97c71024 | 392 | * Signal handler for the selection range signal. |
fc526aef AM |
393 | * |
394 | * The current time of *all* traces whose range contains the requested new | |
0fcf3b09 | 395 | * selection time range will be updated. |
fc526aef AM |
396 | * |
397 | * @param signal | |
398 | * The incoming signal | |
97c71024 | 399 | * @since 1.0 |
fc526aef AM |
400 | */ |
401 | @TmfSignalHandler | |
97c71024 | 402 | public synchronized void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal) { |
0fcf3b09 PT |
403 | final ITmfTimestamp beginTs = signal.getBeginTime(); |
404 | final ITmfTimestamp endTs = signal.getEndTime(); | |
fc526aef AM |
405 | |
406 | for (Map.Entry<ITmfTrace, TmfTraceContext> entry : fTraces.entrySet()) { | |
407 | final ITmfTrace trace = entry.getKey(); | |
0fcf3b09 | 408 | if (beginTs.intersects(getValidTimeRange(trace)) || endTs.intersects(getValidTimeRange(trace))) { |
21852dfa AM |
409 | TmfTraceContext prevCtx = checkNotNull(entry.getValue()); |
410 | ||
411 | /* | |
412 | * We want to update the selection range, but keep everything | |
413 | * else the same as the previous trace context. | |
414 | */ | |
415 | TmfTimeRange newSelectionRange = new TmfTimeRange(beginTs, endTs); | |
ccc49be1 | 416 | TmfTraceContext newCtx = trace.createTraceContext(newSelectionRange, |
21852dfa AM |
417 | prevCtx.getWindowRange(), |
418 | prevCtx.getEditorFile(), | |
419 | prevCtx.getFilter()); | |
178d3c0e | 420 | newCtx.setData(prevCtx.getData()); |
fc526aef AM |
421 | entry.setValue(newCtx); |
422 | } | |
423 | } | |
424 | } | |
425 | ||
426 | /** | |
97c71024 | 427 | * Signal handler for the window range signal. |
fc526aef | 428 | * |
5db5a3a4 AM |
429 | * The current window time range of *all* valid traces will be updated to |
430 | * the new requested times. | |
fc526aef AM |
431 | * |
432 | * @param signal | |
433 | * The incoming signal | |
97c71024 | 434 | * @since 1.0 |
fc526aef AM |
435 | */ |
436 | @TmfSignalHandler | |
97c71024 | 437 | public synchronized void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal) { |
fc526aef AM |
438 | for (Map.Entry<ITmfTrace, TmfTraceContext> entry : fTraces.entrySet()) { |
439 | final ITmfTrace trace = entry.getKey(); | |
21852dfa | 440 | final TmfTraceContext prevCtx = checkNotNull(entry.getValue()); |
fc526aef AM |
441 | |
442 | final TmfTimeRange validTr = getValidTimeRange(trace); | |
21852dfa AM |
443 | if (validTr == null) { |
444 | return; | |
445 | } | |
fc526aef | 446 | |
fc526aef | 447 | /* Determine the new time range */ |
21852dfa AM |
448 | TmfTimeRange targetTr = signal.getCurrentRange().getIntersection(validTr); |
449 | TmfTimeRange newWindowTr = (targetTr == null ? prevCtx.getWindowRange() : targetTr); | |
fc526aef | 450 | |
21852dfa | 451 | /* Keep the values from the old context, except for the window range */ |
ccc49be1 | 452 | TmfTraceContext newCtx = trace.createTraceContext(prevCtx.getSelectionRange(), |
21852dfa | 453 | newWindowTr, prevCtx.getEditorFile(), prevCtx.getFilter()); |
178d3c0e | 454 | newCtx.setData(prevCtx.getData()); |
fc526aef AM |
455 | entry.setValue(newCtx); |
456 | } | |
457 | } | |
458 | ||
459 | // ------------------------------------------------------------------------ | |
e1385db9 | 460 | // Private utility methods |
fc526aef AM |
461 | // ------------------------------------------------------------------------ |
462 | ||
463 | /** | |
0fcf3b09 PT |
464 | * Return the valid time range of a trace (not the current window time |
465 | * range, but the range of all possible valid timestamps). | |
fc526aef AM |
466 | * |
467 | * For a real trace this is the whole range of the trace. For an experiment, | |
468 | * it goes from the start time of the earliest trace to the end time of the | |
469 | * latest one. | |
470 | * | |
471 | * @param trace | |
472 | * The trace to check for | |
473 | * @return The valid time span, or 'null' if the trace is not valid | |
474 | */ | |
21852dfa | 475 | private @Nullable TmfTimeRange getValidTimeRange(ITmfTrace trace) { |
fc526aef AM |
476 | if (!fTraces.containsKey(trace)) { |
477 | /* Trace is not part of the currently opened traces */ | |
478 | return null; | |
479 | } | |
e2239aea BH |
480 | |
481 | List<ITmfTrace> traces = trace.getChildren(ITmfTrace.class); | |
482 | ||
483 | if (traces.isEmpty()) { | |
fc526aef AM |
484 | /* "trace" is a single trace, return its time range directly */ |
485 | return trace.getTimeRange(); | |
486 | } | |
e2239aea BH |
487 | |
488 | if (traces.size() == 1) { | |
fc526aef | 489 | /* Trace is an experiment with only 1 trace */ |
e2239aea | 490 | return traces.get(0).getTimeRange(); |
fc526aef | 491 | } |
e2239aea | 492 | |
fc526aef | 493 | /* |
e2239aea | 494 | * Trace is an trace set with 2+ traces, so get the earliest start and |
fc526aef AM |
495 | * the latest end. |
496 | */ | |
e2239aea BH |
497 | ITmfTimestamp start = traces.get(0).getStartTime(); |
498 | ITmfTimestamp end = traces.get(0).getEndTime(); | |
499 | ||
500 | for (int i = 1; i < traces.size(); i++) { | |
501 | ITmfTrace curTrace = traces.get(i); | |
fc526aef AM |
502 | if (curTrace.getStartTime().compareTo(start) < 0) { |
503 | start = curTrace.getStartTime(); | |
504 | } | |
505 | if (curTrace.getEndTime().compareTo(end) > 0) { | |
506 | end = curTrace.getEndTime(); | |
507 | } | |
508 | } | |
509 | return new TmfTimeRange(start, end); | |
510 | } | |
e1385db9 | 511 | |
3ec38c4c MAL |
512 | /** |
513 | * Get the temporary directory path. If there is an instance of Eclipse | |
514 | * running, the temporary directory will reside under the workspace. | |
515 | * | |
516 | * @return the temporary directory path suitable to be passed to the | |
517 | * java.io.File constructor without a trailing separator | |
3ec38c4c MAL |
518 | */ |
519 | public static String getTemporaryDirPath() { | |
520 | // Get the workspace path from the properties | |
521 | String property = System.getProperty("osgi.instance.area"); //$NON-NLS-1$ | |
522 | if (property != null) { | |
523 | try { | |
1ac53e54 | 524 | File dir = URIUtil.toFile(URIUtil.fromString(property)); |
3ec38c4c MAL |
525 | dir = new File(dir.getAbsolutePath() + File.separator + TEMP_DIR_NAME); |
526 | if (!dir.exists()) { | |
527 | dir.mkdirs(); | |
528 | } | |
529 | return dir.getAbsolutePath(); | |
530 | } catch (URISyntaxException e) { | |
531 | Activator.logError(e.getLocalizedMessage(), e); | |
532 | } | |
533 | } | |
534 | return System.getProperty("java.io.tmpdir"); //$NON-NLS-1$ | |
535 | } | |
536 | ||
e1385db9 | 537 | /** |
6e4358bd AM |
538 | * Get a temporary directory based on a trace's name. We will create the |
539 | * directory if it doesn't exist, so that it's ready to be used. | |
e1385db9 AM |
540 | */ |
541 | private static String getTemporaryDir(ITmfTrace trace) { | |
3ec38c4c | 542 | String pathName = getTemporaryDirPath() + |
fa62dc1d BH |
543 | File.separator + |
544 | trace.getName() + | |
545 | File.separator; | |
6e4358bd AM |
546 | File dir = new File(pathName); |
547 | if (!dir.exists()) { | |
548 | dir.mkdirs(); | |
549 | } | |
550 | return pathName; | |
e1385db9 | 551 | } |
fc526aef | 552 | } |