From e1385db96a09bee9c4f17bbc9a8dca35b19e2082 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Wed, 8 May 2013 16:34:32 -0400 Subject: [PATCH] tmf: Handle the supplementary files dir in the trace manager This centralizes the directory-getting logic in one place. Change-Id: Icc512a7f70c8023837b0cf690be95a53fe649f52 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/12658 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann Tested-by: Bernd Hufmann --- .../kernel/core/trace/LttngKernelTrace.java | 19 ++------ .../core/statistics/TmfStateStatistics.java | 17 ++----- .../tmf/core/trace/TmfTraceManager.java | 46 ++++++++++++++++++- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/LttngKernelTrace.java b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/LttngKernelTrace.java index 9c2d9ae169..cc72b09c10 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/LttngKernelTrace.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/LttngKernelTrace.java @@ -16,20 +16,18 @@ package org.eclipse.linuxtools.lttng2.kernel.core.trace; import java.io.File; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; import org.eclipse.linuxtools.internal.lttng2.kernel.core.Activator; import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider; -import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemFactory; +import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; /** * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel @@ -93,18 +91,9 @@ public class LttngKernelTrace extends CtfTmfTrace { protected void buildStateSystem() throws TmfTraceException { super.buildStateSystem(); - /* Set up the path to the history tree file we'll use */ - IResource resource = this.getResource(); - String supplDirectory = null; - - try { - // get the directory where the history file will be stored. - supplDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER); - } catch (CoreException e) { - throw new TmfTraceException(e.toString(), e); - } - - final File htFile = new File(supplDirectory + File.separator + HISTORY_TREE_FILE_NAME); + /* Build the state system specific to LTTng kernel traces */ + String directory = TmfTraceManager.getSupplementaryFileDir(this); + final File htFile = new File(directory + HISTORY_TREE_FILE_NAME); final ITmfStateProvider htInput = new LttngKernelStateProvider(this); ITmfStateSystem ss = TmfStateSystemFactory.newFullHistory(htFile, htInput, false); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java index 9ab699e6b5..45789a5fc0 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java @@ -18,9 +18,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; @@ -34,6 +31,7 @@ import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemFactory; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; +import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; /** * Implementation of ITmfStatistics which uses a state history for storing its @@ -81,19 +79,10 @@ public class TmfStateStatistics implements ITmfStatistics { * If something went wrong trying to initialize the statistics */ public TmfStateStatistics(ITmfTrace trace) throws TmfTraceException { - /* Set up the path to the history tree file we'll use */ this.trace = trace; - IResource resource = trace.getResource(); - String supplDirectory = null; - try { - // get the directory where the history file will be stored. - supplDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER); - } catch (CoreException e) { - throw new TmfTraceException(e.toString(), e); - } - - final File htFile = new File(supplDirectory + File.separator + STATS_STATE_FILENAME); + String directory = TmfTraceManager.getSupplementaryFileDir(trace); + final File htFile = new File(directory + STATS_STATE_FILENAME); final ITmfStateProvider htInput = new StatsStateProvider(trace); this.stats = TmfStateSystemFactory.newFullHistory(htFile, htInput, false); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java index 48666112aa..398cf89bea 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java @@ -12,9 +12,13 @@ package org.eclipse.linuxtools.tmf.core.trace; +import java.io.File; import java.util.LinkedHashMap; import java.util.Map; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; @@ -123,6 +127,10 @@ public final class TmfTraceManager { return curCtx; } + // ------------------------------------------------------------------------ + // Public utility methods + // ------------------------------------------------------------------------ + /** * Get the trace set of a given trace. For a standard trace, this is simply * an array with only that trace in it. For experiments, this is an array of @@ -143,6 +151,32 @@ public final class TmfTraceManager { return new ITmfTrace[] { trace }; } + /** + * Return the path (as a string) to the directory for supplementary files to + * use with a given trace. If no supplementary file directory has been + * configured, a temporary directory based on the trace's name will be + * provided. + * + * @param trace + * The trace + * @return The path to the supplementary file directory (trailing slash is + * INCLUDED!) + */ + public static String getSupplementaryFileDir(ITmfTrace trace) { + IResource resource = trace.getResource(); + if (resource == null) { + return getTemporaryDir(trace); + } + + String supplDir = null; + try { + supplDir = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER); + } catch (CoreException e) { + return getTemporaryDir(trace); + } + return supplDir + File.separator; + } + // ------------------------------------------------------------------------ // Signal handlers // ------------------------------------------------------------------------ @@ -267,7 +301,7 @@ public final class TmfTraceManager { } // ------------------------------------------------------------------------ - // Utility methods + // Private utility methods // ------------------------------------------------------------------------ /** @@ -317,4 +351,14 @@ public final class TmfTraceManager { } return new TmfTimeRange(start, end); } + + /** + * Get a temporary directory based on a trace's name + */ + private static String getTemporaryDir(ITmfTrace trace) { + return System.getProperty("java.io.tmpdir") + //$NON-NLS-1$ + File.separator + + trace.getName() + + File.separator; + } } -- 2.34.1