From 5157cadbe3c611382d0224ab9cd0e9538052be4b Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Fri, 28 Feb 2025 13:02:43 +0100 Subject: [PATCH 1/6] tmf: extend api for configuration --- .../core/analysis/InAndOutAnalysisModule.java | 112 ------------------ .../analysis/InAndOutDataProviderFactory.java | 10 +- 2 files changed, 4 insertions(+), 118 deletions(-) diff --git a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutAnalysisModule.java b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutAnalysisModule.java index 399bd5109..a11c59b75 100644 --- a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutAnalysisModule.java +++ b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutAnalysisModule.java @@ -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; @@ -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 readConfigurations(@NonNull ITmfTrace trace) throws TmfConfigurationException { - IPath rootPath = getTraceRootFolder(trace, SegmentSpecifierConfiguration.IN_AND_OUT_CONFIG_SOURCE_TYPE_ID); - File folder = rootPath.toFile(); - List 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; - } - } diff --git a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java index fa2f00fd4..358b5ce31 100644 --- a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java +++ b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java @@ -197,15 +197,13 @@ public void traceOpened(TmfTraceOpenedSignal signal) { try { if (trace instanceof TmfExperiment) { for (ITmfTrace tr : TmfTraceManager.getTraceSet(trace)) { - @SuppressWarnings("null") // Read configurations from sub-trace - List configs = InAndOutAnalysisModule.readConfigurations(tr); + List configs = TmfConfiguration.readConfigurations(tr, SegmentSpecifierConfiguration.IN_AND_OUT_CONFIG_SOURCE_TYPE_ID); readAndApplyConfiguration(trace, configs); } } else { - @SuppressWarnings("null") // Read configurations trace - List configs = InAndOutAnalysisModule.readConfigurations(trace); + List configs = TmfConfiguration.readConfigurations(trace, SegmentSpecifierConfiguration.IN_AND_OUT_CONFIG_SOURCE_TYPE_ID); readAndApplyConfiguration(trace, configs); } } catch (TmfConfigurationException e) { @@ -243,7 +241,7 @@ private void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boole return; } // Apply configuration to any trace (no need to check trace type here) - InAndOutAnalysisModule.create(config, trace, writeConfig); + TmfConfiguration.create(config, trace, writeConfig, new InAndOutAnalysisModule()); } private void removeConfiguration(ITmfTrace trace, ITmfConfiguration config) throws TmfConfigurationException { @@ -254,7 +252,7 @@ private void removeConfiguration(ITmfTrace trace, ITmfConfiguration config) thro // only remove for traces in experiment return; } - InAndOutAnalysisModule.remove(config, trace); + TmfConfiguration.remove(config, trace, InAndOutAnalysisModule.ID); } @SuppressWarnings("null") From 5ad7dd932e1ecd2b6167c0688e599b510240e6c6 Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Fri, 28 Feb 2025 14:15:21 +0100 Subject: [PATCH 2/6] tmf: extend api for configuration 2 --- .../analysis/InAndOutDataProviderFactory.java | 150 ++++-------------- 1 file changed, 29 insertions(+), 121 deletions(-) diff --git a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java index 358b5ce31..32ab8d53d 100644 --- a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java +++ b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java @@ -28,9 +28,9 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.osgi.util.NLS; import org.eclipse.tracecompass.incubator.internal.inandout.core.Activator; +import org.eclipse.tracecompass.tmf.core.config.AbstractTmfDataProviderConfigurator; import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration; import org.eclipse.tracecompass.tmf.core.config.ITmfConfigurationSourceType; -import org.eclipse.tracecompass.tmf.core.config.ITmfDataProviderConfigurator; import org.eclipse.tracecompass.tmf.core.config.TmfConfiguration; import org.eclipse.tracecompass.tmf.core.config.TmfConfigurationSourceType; import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor; @@ -41,10 +41,7 @@ import org.eclipse.tracecompass.tmf.core.model.DataProviderDescriptor; import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel; import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataProvider; -import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; -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; @@ -58,7 +55,7 @@ * to create custom InAndOut analyses. */ @NonNullByDefault -public class InAndOutDataProviderFactory implements IDataProviderFactory, ITmfDataProviderConfigurator { +public class InAndOutDataProviderFactory extends AbstractTmfDataProviderConfigurator implements IDataProviderFactory { /** Data Provider factory ID */ public static final String ID = "org.eclipse.tracecompass.incubator.inandout.core.analysis.inAndOutdataProviderFactory"; //$NON-NLS-1$ @@ -131,108 +128,21 @@ public Collection getDescriptors(ITmfTrace trace) { } @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); + @SuppressWarnings("null") + protected IDataProviderDescriptor getDescriptorFromConfig(ITmfConfiguration config) { + return new DataProviderDescriptor.Builder() + .setParentId(ID) + .setId(InAndOutAnalysisModule.ID + config.getId()) + .setName(NLS.bind(CUSTOM_IN_AND_OUT_ANALYSIS_NAME, config.getName())) + .setDescription(NLS.bind(CUSTOM_IN_AND_OUT_ANALYSIS_DESCRIPTION, config.getName())) + .setProviderType(ProviderType.NONE) + .setConfiguration(config) + .setCapabilities(new DataProviderCapabilities.Builder().setCanDelete(true).build()) + .build(); } @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); - } - - /** - * Signal handler for opened trace signal. Will populate trace - * configurations - * - * @param signal - * the signal to handle - */ - @TmfSignalHandler - public void traceOpened(TmfTraceOpenedSignal signal) { - 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 configs = TmfConfiguration.readConfigurations(tr, SegmentSpecifierConfiguration.IN_AND_OUT_CONFIG_SOURCE_TYPE_ID); - readAndApplyConfiguration(trace, configs); - } - } else { - // Read configurations trace - List configs = TmfConfiguration.readConfigurations(trace, SegmentSpecifierConfiguration.IN_AND_OUT_CONFIG_SOURCE_TYPE_ID); - readAndApplyConfiguration(trace, configs); - } - } catch (TmfConfigurationException e) { - Activator.getInstance().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 configs) throws TmfConfigurationException { - for (ITmfConfiguration config : configs) { - if (!fTmfConfigurationTable.contains(config.getId(), trace)) { - fTmfConfigurationTable.put(config.getId(), trace, config); - applyConfiguration(trace, config, false); - } - } - } - - private void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boolean writeConfig) throws TmfConfigurationException { + protected void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boolean writeConfig) { if (trace instanceof TmfExperiment) { for (ITmfTrace tr : TmfTraceManager.getTraceSet(trace)) { applyConfiguration(tr, config, writeConfig); @@ -240,11 +150,17 @@ private void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boole // Only apply for traces in experiment return; } - // Apply configuration to any trace (no need to check trace type here) - TmfConfiguration.create(config, trace, writeConfig, new InAndOutAnalysisModule()); + // Apply configuration to any trace (no need to check trace type here) + try { + TmfConfiguration.create(config, trace, writeConfig, new InAndOutAnalysisModule()); + } catch (TmfConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } - private void removeConfiguration(ITmfTrace trace, ITmfConfiguration config) throws TmfConfigurationException { + @Override + protected void removeConfiguration(ITmfTrace trace, ITmfConfiguration config) { if (trace instanceof TmfExperiment) { for (ITmfTrace tr : TmfTraceManager.getTraceSet(trace)) { removeConfiguration(tr, config); @@ -252,19 +168,11 @@ private void removeConfiguration(ITmfTrace trace, ITmfConfiguration config) thro // only remove for traces in experiment return; } - TmfConfiguration.remove(config, trace, InAndOutAnalysisModule.ID); - } - - @SuppressWarnings("null") - private static IDataProviderDescriptor getDescriptorFromConfig(ITmfConfiguration config) { - return new DataProviderDescriptor.Builder() - .setParentId(ID) - .setId(InAndOutAnalysisModule.ID + config.getId()) - .setName(NLS.bind(CUSTOM_IN_AND_OUT_ANALYSIS_NAME, config.getName())) - .setDescription(NLS.bind(CUSTOM_IN_AND_OUT_ANALYSIS_DESCRIPTION, config.getName())) - .setProviderType(ProviderType.NONE) - .setConfiguration(config) - .setCapabilities(new DataProviderCapabilities.Builder().setCanDelete(true).build()) - .build(); + try { + TmfConfiguration.remove(config, trace, InAndOutAnalysisModule.ID); + } catch (TmfConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } From 694fd31512486f5102f520f2bab4cb732676f6fc Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Thu, 6 Mar 2025 13:45:19 +0100 Subject: [PATCH 3/6] tmf: extend api for configuration 4 --- .../analysis/InAndOutDataProviderFactory.java | 103 ++++++++++++++++-- 1 file changed, 94 insertions(+), 9 deletions(-) diff --git a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java index 32ab8d53d..46b6819ee 100644 --- a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java +++ b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java @@ -28,15 +28,17 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.osgi.util.NLS; import org.eclipse.tracecompass.incubator.internal.inandout.core.Activator; +import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; import org.eclipse.tracecompass.tmf.core.config.AbstractTmfDataProviderConfigurator; import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration; import org.eclipse.tracecompass.tmf.core.config.ITmfConfigurationSourceType; -import org.eclipse.tracecompass.tmf.core.config.TmfConfiguration; import org.eclipse.tracecompass.tmf.core.config.TmfConfigurationSourceType; import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor; import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor.ProviderType; import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderFactory; +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.model.DataProviderCapabilities; import org.eclipse.tracecompass.tmf.core.model.DataProviderDescriptor; import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel; @@ -47,9 +49,6 @@ import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; import org.osgi.framework.Bundle; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.Table; - /** * Data provider factory for InAndOut analysis. It doesn't have any output but is able * to create custom InAndOut analyses. @@ -70,8 +69,6 @@ public class InAndOutDataProviderFactory extends AbstractTmfDataProviderConfigur private static final String CUSTOM_IN_AND_OUT_ANALYSIS_NAME = "InAndOut Analysis ({0})"; //$NON-NLS-1$ private static final String CUSTOM_IN_AND_OUT_ANALYSIS_DESCRIPTION = "Custom InAndOut analysis configured by \" {0}\""; //$NON-NLS-1$ - private Table fTmfConfigurationTable = HashBasedTable.create(); - static { Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID); IPath defaultPath = new Path(SegmentSpecifierConfiguration.IN_AND_OUT_CONFIG_SOURCE_SCHEMA); @@ -115,7 +112,7 @@ public InAndOutDataProviderFactory() { public Collection getDescriptors(ITmfTrace trace) { List list = new ArrayList<>(); list.add(DESCRIPTOR); - for (ITmfConfiguration config : fTmfConfigurationTable.column(trace).values()) { + for (ITmfConfiguration config : getConfigurationTable().column(trace).values()) { list.add(getDescriptorFromConfig(config)); } return list; @@ -152,7 +149,7 @@ protected void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boo } // Apply configuration to any trace (no need to check trace type here) try { - TmfConfiguration.create(config, trace, writeConfig, new InAndOutAnalysisModule()); + create(config, trace, writeConfig, new InAndOutAnalysisModule()); } catch (TmfConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -169,10 +166,98 @@ protected void removeConfiguration(ITmfTrace trace, ITmfConfiguration config) { return; } try { - TmfConfiguration.remove(config, trace, InAndOutAnalysisModule.ID); + remove(config, trace, InAndOutAnalysisModule.ID); } catch (TmfConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } + + /** + * 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 + */ + private void remove(ITmfConfiguration config, @NonNull ITmfTrace trace, String baseAnalysisId) throws TmfConfigurationException { + // IPath traceConfig = getConfigurationRootFolder(trace, config.getSourceTypeId()); + IPath traceConfig = getConfigurationRootFolder(trace); + traceConfig = traceConfig.append(File.separator).append(config.getId()).addFileExtension(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 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 = getConfigurationRootFolder(trace, config.getSourceTypeId()); + IPath traceConfigPath = getConfigurationRootFolder(trace); + 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$ + } + } + +// protected IPath getConfigurationRootFolder(ITmfTrace trace, String subFolder) { +// String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace); +// IPath supplPath = new Path(supplFolder); +// supplPath = supplPath.addTrailingSeparator().append(subFolder); +// return supplPath; +// } + + @Override + protected IPath getConfigurationRootFolder(ITmfTrace trace) { + String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace); + IPath supplPath = new Path(supplFolder); + supplPath = supplPath.addTrailingSeparator().append(ID); + return supplPath; + } + } From 5b460aadf69de6e060f50f4ebc5f3513900d6fef Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Wed, 12 Mar 2025 11:48:06 +0100 Subject: [PATCH 4/6] tmf: extend api for configuration 5 --- .../analysis/InAndOutDataProviderFactory.java | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java index 46b6819ee..3e2c6180f 100644 --- a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java +++ b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java @@ -151,8 +151,7 @@ protected void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boo try { create(config, trace, writeConfig, new InAndOutAnalysisModule()); } catch (TmfConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Activator.getInstance().logError(e.getMessage(), e); } } @@ -168,8 +167,7 @@ protected void removeConfiguration(ITmfTrace trace, ITmfConfiguration config) { try { remove(config, trace, InAndOutAnalysisModule.ID); } catch (TmfConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Activator.getInstance().logError(e.getMessage(), e); } } @@ -185,7 +183,6 @@ protected void removeConfiguration(ITmfTrace trace, ITmfConfiguration config) { * @throws TmfConfigurationException if an error occurs */ private void remove(ITmfConfiguration config, @NonNull ITmfTrace trace, String baseAnalysisId) throws TmfConfigurationException { - // IPath traceConfig = getConfigurationRootFolder(trace, config.getSourceTypeId()); IPath traceConfig = getConfigurationRootFolder(trace); traceConfig = traceConfig.append(File.separator).append(config.getId()).addFileExtension(JSON_EXTENSION); File configFile = traceConfig.toFile(); @@ -224,7 +221,6 @@ public void create(@NonNull ITmfConfiguration config, @NonNull ITmfTrace trace, */ module.setConfiguration(config); if (writeConfig) { - // IPath traceConfigPath = getConfigurationRootFolder(trace, config.getSourceTypeId()); IPath traceConfigPath = getConfigurationRootFolder(trace); writeConfiguration(config, traceConfigPath); } @@ -245,13 +241,6 @@ public void create(@NonNull ITmfConfiguration config, @NonNull ITmfTrace trace, } } -// protected IPath getConfigurationRootFolder(ITmfTrace trace, String subFolder) { -// String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace); -// IPath supplPath = new Path(supplFolder); -// supplPath = supplPath.addTrailingSeparator().append(subFolder); -// return supplPath; -// } - @Override protected IPath getConfigurationRootFolder(ITmfTrace trace) { String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace); From 8c2f3ef33e043794908e90713a5cb148e9cf18b6 Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Thu, 13 Mar 2025 14:18:10 +0100 Subject: [PATCH 5/6] tmf: extend api for configuration 5 Make create private --- .../inandout/core/analysis/InAndOutDataProviderFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java index 3e2c6180f..6ec3162c0 100644 --- a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java +++ b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java @@ -215,7 +215,7 @@ private void remove(ITmfConfiguration config, @NonNull ITmfTrace trace, String b * @throws TmfConfigurationException * if an error occurs */ - public void create(@NonNull ITmfConfiguration config, @NonNull ITmfTrace trace, boolean writeConfig, IAnalysisModule module) throws TmfConfigurationException { + private 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) */ From fa57b5d170e62f6dadc26331813ef23f0e776c83 Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Thu, 3 Apr 2025 14:53:58 +0200 Subject: [PATCH 6/6] tmf: extend api for configuration 6 Review round #1 --- .../analysis/InAndOutDataProviderFactory.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java index 6ec3162c0..649f4bb71 100644 --- a/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java +++ b/analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java @@ -43,7 +43,6 @@ import org.eclipse.tracecompass.tmf.core.model.DataProviderDescriptor; import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel; import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataProvider; -import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; 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; @@ -96,13 +95,6 @@ public class InAndOutDataProviderFactory extends AbstractTmfDataProviderConfigur .setCapabilities(new DataProviderCapabilities.Builder().setCanCreate(true).build()) .build(); - /** - * Default constructor - */ - public InAndOutDataProviderFactory() { - TmfSignalManager.register(this); - } - @Override public @Nullable ITmfTreeDataProvider createProvider(ITmfTrace trace) { return null; @@ -182,7 +174,7 @@ protected void removeConfiguration(ITmfTrace trace, ITmfConfiguration config) { * the * @throws TmfConfigurationException if an error occurs */ - private void remove(ITmfConfiguration config, @NonNull ITmfTrace trace, String baseAnalysisId) throws TmfConfigurationException { + private void remove(ITmfConfiguration config, ITmfTrace trace, String baseAnalysisId) throws TmfConfigurationException { IPath traceConfig = getConfigurationRootFolder(trace); traceConfig = traceConfig.append(File.separator).append(config.getId()).addFileExtension(JSON_EXTENSION); File configFile = traceConfig.toFile(); @@ -211,11 +203,10 @@ private void remove(ITmfConfiguration config, @NonNull ITmfTrace trace, String b * the trace to apply it to * @param writeConfig * write the config (do only once) - * @return InAndOutAnalysisModule * @throws TmfConfigurationException * if an error occurs */ - private void create(@NonNull ITmfConfiguration config, @NonNull ITmfTrace trace, boolean writeConfig, IAnalysisModule module) throws TmfConfigurationException { + private void create(ITmfConfiguration config, ITmfTrace trace, boolean writeConfig, IAnalysisModule module) throws TmfConfigurationException { /* * Apply configuration to each trace (no need to check trace type here) */ @@ -249,4 +240,9 @@ protected IPath getConfigurationRootFolder(ITmfTrace trace) { return supplPath; } + @Override + public void dispose() { + super.dispose(); + } + }