Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@
import java.util.List;
import java.util.Objects;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.analysis.profiling.core.instrumented.InstrumentedCallStackAnalysis;
import org.eclipse.tracecompass.incubator.internal.inandout.core.Activator;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration;
import org.eclipse.tracecompass.tmf.core.config.TmfConfiguration;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
Expand Down Expand Up @@ -183,110 +177,4 @@ public static void write(File file, List<@NonNull SegmentSpecifier> specifiers)
}
}

/**
* Create the InAndOutAnalysisModule for a given configuration and trace
*
* @param config
* the input {@link ITmfConfiguration}
* @param trace
* the trace to apply it to
* @param writeConfig
* write the config (do only once)
* @return InAndOutAnalysisModule
* @throws TmfConfigurationException
* if an error occurs
*/
public static InAndOutAnalysisModule create(@NonNull ITmfConfiguration config, @NonNull ITmfTrace trace, boolean writeConfig) throws TmfConfigurationException {
/*
* Apply configuration to each trace (no need to check trace type here)
*/
InAndOutAnalysisModule module = new InAndOutAnalysisModule();
module.setConfiguration(config);
if (writeConfig) {
IPath traceConfigPath = getTraceRootFolder(trace, config.getSourceTypeId());
TmfConfiguration.writeConfiguration(config, traceConfigPath);
}
try {
if (module.setTrace(trace)) {
IAnalysisModule oldModule = trace.addAnalysisModule(module);
if (oldModule != null) {
oldModule.dispose();
oldModule.clearPersistentData();
}
} else {
module.dispose();
throw new TmfConfigurationException("InAndOut analysis module can't be created"); //$NON-NLS-1$
}
} catch (TmfAnalysisException | TmfTraceException e) {
module.dispose();
throw new TmfConfigurationException("Exception when setting trace", e); //$NON-NLS-1$
}
return module;
}

/**
* Removes configuration from trace:
* - delete configuration file
* - remove analysis module from trace object
*
* @param config
* the configuration to remove
* @param trace
* the
* @throws TmfConfigurationException if an error occurs
*/
public static void remove(ITmfConfiguration config, @NonNull ITmfTrace trace) throws TmfConfigurationException {
IPath traceConfig = getTraceRootFolder(trace, config.getSourceTypeId());
traceConfig = traceConfig.append(File.separator).append(config.getId()).addFileExtension(TmfConfiguration.JSON_EXTENSION);
File configFile = traceConfig.toFile();
if ((!configFile.exists()) || !configFile.delete()) {
throw new TmfConfigurationException("InAndOut configuration file can't be deleted from trace: configId=" + config.getId()); //$NON-NLS-1$
}

// Remove and clear persistent data
try {
IAnalysisModule module = trace.removeAnalysisModule(ID + config.getId());
if (module != null) {
module.dispose();
module.clearPersistentData();
}
} catch (TmfTraceException e) {
throw new TmfConfigurationException("Error removing analysis module from trace: analysis ID=" + ID + config.getId(), e); //$NON-NLS-1$
}
}

@SuppressWarnings("null")
private static @NonNull IPath getTraceRootFolder(@NonNull ITmfTrace trace, String subFolder) {
String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace);
IPath supplPath = new Path(supplFolder);
supplPath = supplPath.addTrailingSeparator().append(subFolder);
return supplPath;
}

/**
* Reads the configurations for a given trace
*
* @param trace
* the trace to read configurations from
* @return list of configurations if any
* @throws TmfConfigurationException
* if an error occurs
*/
public static @NonNull List<ITmfConfiguration> readConfigurations(@NonNull ITmfTrace trace) throws TmfConfigurationException {
IPath rootPath = getTraceRootFolder(trace, SegmentSpecifierConfiguration.IN_AND_OUT_CONFIG_SOURCE_TYPE_ID);
File folder = rootPath.toFile();
List<ITmfConfiguration> list = new ArrayList<>();
if (folder.exists()) {
File[] listOfFiles = folder.listFiles();
for (File file : listOfFiles) {
IPath path = new Path(file.getName());
if (path.getFileExtension().equals(TmfConfiguration.JSON_EXTENSION)) {
ITmfConfiguration config = TmfConfiguration.fromJsonFile(file);
list.add(config);
}
}
}
return list;
}

}
Loading