Search in sources :

Example 1 with LamiAnalysis

use of org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis in project tracecompass by tracecompass.

the class AddAnalysisHandler method execute.

@Override
@Nullable
public Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final AddAnalysisDialog dialog = new AddAnalysisDialog(shell, Messages.AddAnalysisDialog_Title, NAME_INPUT_VALIDATOR, COMMAND_INPUT_VALIDATOR);
    if (dialog.open() != Window.OK) {
        // User clicked Cancel, cancel the add operation
        return null;
    }
    Path configFilePath;
    try {
        configFilePath = LamiConfigUtils.createConfigFile(checkNotNull(dialog.getName().trim()), checkNotNull(dialog.getCommand().trim()));
    } catch (IOException e) {
        showErrorBox(shell, e);
        return null;
    }
    try {
        final LamiAnalysis analysis = LamiAnalysisFactoryFromConfigFile.buildFromConfigFile(configFilePath, true, trace -> true);
        OnDemandAnalysisManager.getInstance().registerAnalysis(analysis);
    } catch (LamiAnalysisFactoryException e) {
        showErrorBox(shell, e);
        return null;
    }
    final Object elem = HandlerUtils.getSelectedModelElement();
    if (elem != null && elem instanceof TmfOnDemandAnalysesElement) {
        final TmfOnDemandAnalysesElement analysesElem = (TmfOnDemandAnalysesElement) elem;
        analysesElem.refresh();
    }
    return null;
}
Also used : Path(java.nio.file.Path) LamiAnalysisFactoryException(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisFactoryException) Shell(org.eclipse.swt.widgets.Shell) IOException(java.io.IOException) LamiAnalysis(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis) TmfOnDemandAnalysesElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysesElement) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with LamiAnalysis

use of org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis in project tracecompass by tracecompass.

the class RunAnalysisHandler method isEnabled.

@Override
public boolean isEnabled() {
    final Object element = HandlerUtils.getSelectedModelElement();
    if (element == null) {
        return false;
    }
    /*
         * plugin.xml should have done type verifications already
         */
    TmfOnDemandAnalysisElement elem = (TmfOnDemandAnalysisElement) element;
    return (elem.getAnalysis() instanceof LamiAnalysis && elem.canRun());
}
Also used : TmfOnDemandAnalysisElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement) LamiAnalysis(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis)

Example 3 with LamiAnalysis

use of org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis in project tracecompass by tracecompass.

the class Activator method loadUserDefinedAnalyses.

private void loadUserDefinedAnalyses() {
    final Path configDirPath = LamiConfigUtils.getConfigDirPath();
    try {
        final List<LamiAnalysis> analyses = LamiAnalysisFactoryFromConfigFile.buildFromConfigDir(configDirPath, true, trace -> true);
        OnDemandAnalysisManager manager = OnDemandAnalysisManager.getInstance();
        analyses.forEach(manager::registerAnalysis);
    } catch (LamiAnalysisFactoryException e) {
        // $NON-NLS-1$
        logWarning("Cannot load user-defined external analyses", e);
    }
}
Also used : Path(java.nio.file.Path) LamiAnalysisFactoryException(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisFactoryException) OnDemandAnalysisManager(org.eclipse.tracecompass.tmf.core.analysis.ondemand.OnDemandAnalysisManager) LamiAnalysis(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis)

Example 4 with LamiAnalysis

use of org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis in project tracecompass by tracecompass.

the class RunAnalysisHandler method execute.

@Override
@Nullable
public Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
    /* Types should have been checked by the plugin.xml already */
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    Object element = ((IStructuredSelection) selection).getFirstElement();
    final TmfOnDemandAnalysisElement analysisElem = (TmfOnDemandAnalysisElement) element;
    TmfCommonProjectElement traceElem = analysisElem.getParent().getParent();
    ITmfTrace trace = traceElem.getTrace();
    if (trace == null) {
        /* That trace is not currently opened */
        return null;
    }
    /* Retrieve and initialize the analysis module, aka read the script's metadata */
    IOnDemandAnalysis ondemandAnalysis = analysisElem.getAnalysis();
    if (!(ondemandAnalysis instanceof LamiAnalysis)) {
        return null;
    }
    LamiAnalysis analysis = (LamiAnalysis) ondemandAnalysis;
    /* Retrieve the current time range, will be used as parameters to the analysis */
    TmfTraceManager tm = TmfTraceManager.getInstance();
    TmfTimeRange timeRange = tm.getCurrentTraceContext().getSelectionRange();
    if (timeRange.getStartTime().equals(timeRange.getEndTime())) {
        timeRange = null;
    }
    /* Job below needs a final reference... */
    final TmfTimeRange tr = timeRange;
    /* Pop the dialog to ask for extra parameters */
    String baseCommand = analysis.getFullCommandAsString(trace, tr);
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    ParameterDialog dialog = new ParameterDialog(shell, Messages.ParameterDialog_ExternalParameters, Messages.ParameterDialog_ExternalParametersDescription, baseCommand, null);
    if (dialog.open() != Window.OK) {
        /* User clicked Cancel, don't run */
        return null;
    }
    String extraParams = nullToEmptyString(dialog.getValue());
    /* Execute the analysis and produce the reports */
    Job job = new Job(Messages.LamiAnalysis_MainTaskName) {

        @Override
        @Nullable
        protected IStatus run(@Nullable IProgressMonitor monitor) {
            IProgressMonitor mon = (monitor == null ? new NullProgressMonitor() : monitor);
            try {
                List<LamiResultTable> results = analysis.execute(trace, tr, extraParams, mon);
                String reportName = analysis.getName() + ' ' + Messages.ParameterDialog_ReportNameSuffix;
                LamiAnalysisReport report = new LamiAnalysisReport(reportName, results);
                registerNewReport(analysisElem, report);
                /* Automatically open the report for convenience */
                Display.getDefault().syncExec(() -> {
                    try {
                        LamiReportViewFactory.createNewView(report);
                    } catch (PartInitException e) {
                    }
                });
                return Status.OK_STATUS;
            } catch (CoreException e) {
                /*
                     * The analysis execution did not complete normally, we will
                     * report it to the user.
                     */
                IStatus status = e.getStatus();
                /* Don't display a dialog if it was simply cancelled by the user */
                if (status.matches(IStatus.CANCEL)) {
                    return status;
                }
                String dialogTitle;
                String dialogMessage;
                if (status.matches(IStatus.ERROR)) {
                    dialogTitle = Messages.ErrorDialog_Error;
                    dialogMessage = Messages.ErrorDialog_ErrorMessage;
                } else {
                    dialogTitle = Messages.ErrorDialog_Info;
                    dialogMessage = Messages.ErrorDialog_InfoMessage;
                }
                Display.getDefault().asyncExec(() -> {
                    ErrorDialog.openError(shell, dialogTitle, dialogMessage, status);
                });
                /*
                     * We showed our own error message, no need for the Job to
                     * show another one.
                     */
                return Status.OK_STATUS;
            }
        }
    };
    job.schedule();
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) TmfOnDemandAnalysisElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) LamiAnalysis(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis) NonNullUtils.nullToEmptyString(org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) LamiResultTable(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiResultTable) ISelection(org.eclipse.jface.viewers.ISelection) IOnDemandAnalysis(org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis) LamiAnalysisReport(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisReport) PartInitException(org.eclipse.ui.PartInitException) Job(org.eclipse.core.runtime.jobs.Job) Nullable(org.eclipse.jdt.annotation.Nullable) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 5 with LamiAnalysis

use of org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis in project tracecompass by tracecompass.

the class LttngAnalysesLoader method load.

public static void load() throws LamiAnalysisFactoryException, IOException {
    final String[] names = getAnalysisNames();
    final ClassLoader loader = LttngAnalysesLoader.class.getClassLoader();
    for (final String name : names) {
        // $NON-NLS-1$
        final String path = String.format("/%s/%s.properties", CONFIG_DIR_NAME, name);
        try (final InputStream in = loader.getResourceAsStream(path)) {
            if (in == null) {
                continue;
            }
            final LamiAnalysis analysis = LamiAnalysisFactoryFromConfigFile.buildFromInputStream(in, false, LttngAnalysesLoader::appliesTo);
            OnDemandAnalysisManager.getInstance().registerAnalysis(analysis);
        }
    }
}
Also used : InputStream(java.io.InputStream) LamiAnalysis(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis)

Aggregations

LamiAnalysis (org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis)5 Path (java.nio.file.Path)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 Shell (org.eclipse.swt.widgets.Shell)2 LamiAnalysisFactoryException (org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisFactoryException)2 TmfOnDemandAnalysisElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 NonNullUtils.nullToEmptyString (org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString)1 LamiAnalysisReport (org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisReport)1 LamiResultTable (org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiResultTable)1 IOnDemandAnalysis (org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis)1 OnDemandAnalysisManager (org.eclipse.tracecompass.tmf.core.analysis.ondemand.OnDemandAnalysisManager)1