Skip to content
Open
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 @@ -4,6 +4,5 @@ Bundle-Name: Trace Compass SLF4J Simple Binding Properties Fragment Plug-in
Bundle-SymbolicName: org.eclipse.tracecompass.slf4j.binding.simple.properties
Bundle-Version: 1.0.2.qualifier
Bundle-Vendor: Eclipse Trace Compass
Fragment-Host: slf4j.simple
Automatic-Module-Name: org.eclipse.tracecompass.slf4j.binding.simple.properties
Bundle-RequiredExecutionEnvironment: JavaSE-11
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
org.eclipse.jdt.core.codeComplete.argumentPrefixes=
org.eclipse.jdt.core.codeComplete.argumentSuffixes=
org.eclipse.jdt.core.codeComplete.fieldPrefixes=f
Expand All @@ -15,9 +16,12 @@ org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonN
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.notowning=org.eclipse.jdt.annotation.NotOwning
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.annotation.owning=org.eclipse.jdt.annotation.Owning
org.eclipse.jdt.core.compiler.annotation.resourceanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
Expand Down Expand Up @@ -51,8 +55,10 @@ org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=error
org.eclipse.jdt.core.compiler.problem.incompatibleOwningContract=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=error
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error
org.eclipse.jdt.core.compiler.problem.insufficientResourceAnalysis=warning
org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
Expand Down Expand Up @@ -117,7 +123,7 @@ org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warni
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=error
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=error
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
Expand All @@ -127,6 +133,7 @@ org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverridin
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=error
org.eclipse.jdt.core.compiler.problem.unusedLabel=error
org.eclipse.jdt.core.compiler.problem.unusedLambdaParameter=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=error
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=error
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package org.eclipse.tracecompass.tmf.core.config;

import java.util.List;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;

/**
*
*/
public abstract class AbstractTmfDataProviderConfigurator implements ITmfDataProviderConfigurator{

private static final Table<String, ITmfTrace, ITmfConfiguration> fTmfConfigurationTable = HashBasedTable.create();

@Override
public @NonNull IDataProviderDescriptor createDataProviderDescriptors(ITmfTrace trace, ITmfConfiguration configuration) throws TmfConfigurationException {

if (configuration.getName().equals(TmfConfiguration.UNKNOWN)) {
throw new TmfConfigurationException("Missing configuration name of InAndOut analysis"); //$NON-NLS-1$
}

if (configuration.getSourceTypeId().equals(TmfConfiguration.UNKNOWN)) {
throw new TmfConfigurationException("Missing configuration type for InAndOut analysis"); //$NON-NLS-1$
}

String description = configuration.getDescription();
if (configuration.getDescription().equals(TmfConfiguration.UNKNOWN)) {
description = "InAndOut Analysis defined by configuration " + configuration.getName(); //$NON-NLS-1$
}

TmfConfiguration.Builder builder = new TmfConfiguration.Builder();
builder.setId(configuration.getId())
.setSourceTypeId(configuration.getSourceTypeId())
.setName(configuration.getName())
.setDescription(description)
.setParameters(configuration.getParameters())
.build();

ITmfConfiguration config = builder.build();

applyConfiguration(trace, config, true);
if (fTmfConfigurationTable.contains(config.getId(), trace)) {
throw new TmfConfigurationException("Configuration already existis with label: " + config.getName()); //$NON-NLS-1$
}
fTmfConfigurationTable.put(config.getId(), trace, config);
return getDescriptorFromConfig(config);
}

/**
* @param config
* @return A data provider descriptor based on the configuration parameter
*/
protected abstract IDataProviderDescriptor getDescriptorFromConfig(ITmfConfiguration config);

/**
* This is the method that handles what happens when a configuration is applied
* @param trace
* @param config
* @param writeConfig
*/
protected abstract void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boolean writeConfig);

// efrooo: the below move to open source
@Override
public void removeDataProviderDescriptor(ITmfTrace trace, IDataProviderDescriptor descriptor) throws TmfConfigurationException {
ITmfConfiguration creationConfiguration = descriptor.getConfiguration();
if (creationConfiguration == null) {
throw new TmfConfigurationException("Data provider was not created by a configuration"); //$NON-NLS-1$
}

String configId = creationConfiguration.getId();
ITmfConfiguration config = fTmfConfigurationTable.get(configId, trace);
if (config == null) {
return;
}
config = fTmfConfigurationTable.remove(configId, trace);
removeConfiguration(trace, config);
}

/**
* This is the method that handles what happens when a configuration is removed (e.g. remove analysis, dp etc)
* @param trace
* @param config
*/
protected abstract void removeConfiguration(@NonNull ITmfTrace trace, @NonNull ITmfConfiguration config);

// efroroo: to open source
/**
* Signal handler for opened trace signal. Will populate trace
* configurations
*
* @param signal
* the signal to handle
*/
@TmfSignalHandler
public void traceOpened(TmfTraceOpenedSignal signal, String subfolder) {
ITmfTrace trace = signal.getTrace();
if (trace == null) {
return;
}
try {
if (trace instanceof TmfExperiment) {
for (ITmfTrace tr : TmfTraceManager.getTraceSet(trace)) {
// Read configurations from sub-trace
List<ITmfConfiguration> configs = TmfConfiguration.readConfigurations(tr, subfolder);
readAndApplyConfiguration(trace, configs);
}
} else {
// Read configurations trace
List<ITmfConfiguration> configs = TmfConfiguration.readConfigurations(trace, subfolder);
readAndApplyConfiguration(trace, configs);
}
} catch (TmfConfigurationException e) {
// FIXME: use proper logging
// Activator.logError("Error applying configurations for trace " + trace.getName(), e); //$NON-NLS-1$
}
}

/**
* Handles trace closed signal
*
* @param signal
* the close signal to handle
*/
@TmfSignalHandler
public void traceClosed(TmfTraceClosedSignal signal) {
ITmfTrace trace = signal.getTrace();
fTmfConfigurationTable.column(trace).clear();
}

private void readAndApplyConfiguration(ITmfTrace trace, List<ITmfConfiguration> configs) throws TmfConfigurationException {
for (ITmfConfiguration config : configs) {
if (!fTmfConfigurationTable.contains(config.getId(), trace)) {
fTmfConfigurationTable.put(config.getId(), trace, config);
applyConfiguration(trace, config, false);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

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.internal.tmf.core.Activator;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
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.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;

import com.google.gson.Gson;
import com.google.gson.JsonParseException;
Expand Down Expand Up @@ -343,4 +352,109 @@ public static void writeConfiguration(ITmfConfiguration configuration, IPath roo
throw new TmfConfigurationException("Error writing configuration.", e); //$NON-NLS-1$
}
}

@SuppressWarnings("null")
private static @NonNull IPath getConfigurationRootFolder(@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, String subfolder) throws TmfConfigurationException {
IPath rootPath = getConfigurationRootFolder(trace, subfolder);
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;
}

/**
* 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, String baseAnalysisId) throws TmfConfigurationException {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create() and remove() includes how the analysis module is initialized and how the configuration file is managed. But we're writing config files in our own specified location (per data provider id), so those are preferably in our own code?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if we move create() and remove() to internal code, AbstractTmfDataProviderConfigurator.traceOpened() and TmfConfiguration.readConfigurations() also needs to be in internal code, because we no longer have control over where we store the files.

IPath traceConfig = getConfigurationRootFolder(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("Configuration file can't be deleted from trace: configId=" + config.getId()); //$NON-NLS-1$
}

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

/**
* 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 void create(@NonNull ITmfConfiguration config, @NonNull ITmfTrace trace, boolean writeConfig, IAnalysisModule module) throws TmfConfigurationException {
/*
* Apply configuration to each trace (no need to check trace type here)
*/
module.setConfiguration(config);
if (writeConfig) {
IPath traceConfigPath = TmfConfiguration.getConfigurationRootFolder(trace, config.getSourceTypeId());
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can't store it per config.getSourceTypeId() as it'll cause conflict when different data providers are using the same config source type id.

TmfConfiguration.writeConfiguration(config, traceConfigPath);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here we'll be writing a configuration to file whenever we create an analysis module, which is still binding one configuration file to one analysis module. So the configuration on data provider level will still needs to be a parallel implementation. Which means we'll be writing configuration to file in different places in the code.

}
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$
}
}

}