Search in sources :

Example 1 with IOnDemandAnalysis

use of org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis in project tracecompass by tracecompass.

the class TmfOnDemandAnalysesElement method refreshChildren.

@Override
protected synchronized void refreshChildren() {
    ITmfTrace trace = getParent().getTrace();
    if (trace == null) {
        /* Trace is not yet initialized */
        return;
    }
    // Remove children first (create a copy as the array will be modified).
    new ArrayList<>(getChildren()).forEach(this::removeChild);
    Set<IOnDemandAnalysis> analyses = OnDemandAnalysisManager.getInstance().getOndemandAnalyses(trace);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IPath nodePath = getResource().getFullPath();
    analyses.forEach(analysis -> {
        IFolder analysisRes = checkNotNull(root.getFolder(nodePath.append(analysis.getName())));
        TmfOnDemandAnalysisElement elem;
        if (analysis.isUserDefined()) {
            elem = new TmfUserDefinedOnDemandAnalysisElement(analysis.getName(), analysisRes, this, analysis);
        } else {
            elem = new TmfBuiltInOnDemandAnalysisElement(analysis.getName(), analysisRes, this, analysis);
        }
        addChild(elem);
    });
    /* Refresh all children */
    getChildren().forEach(child -> ((TmfProjectModelElement) child).refreshChildren());
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) IOnDemandAnalysis(org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with IOnDemandAnalysis

use of org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis in project tracecompass by tracecompass.

the class OnDemandAnalysisTest method testGetNoAnalysisFromTrace.

/**
 * Test querying the manager for analyses, but for a trace that does not
 * support any.
 */
@Test
public void testGetNoAnalysisFromTrace() {
    ITmfTrace trace = fTraceThatDoesntApply;
    assertNotNull(trace);
    Set<IOnDemandAnalysis> set = OnDemandAnalysisManager.getInstance().getOndemandAnalyses(trace);
    assertTrue(set.isEmpty());
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) IOnDemandAnalysis(org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis) Test(org.junit.Test)

Example 3 with IOnDemandAnalysis

use of org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis in project tracecompass by tracecompass.

the class OnDemandAnalysisTest method testGetAnalysisFromTrace.

/**
 * Test getting an analysis via the manager. The expected way of doing
 * things.
 */
@Test
public void testGetAnalysisFromTrace() {
    ITmfTrace trace = fTraceThatApplies;
    assertNotNull(trace);
    Set<IOnDemandAnalysis> set1 = OnDemandAnalysisManager.getInstance().getOndemandAnalyses(trace);
    assertEquals(1, set1.size());
    assertTrue(Iterables.getOnlyElement(set1) instanceof OnDemandAnalysisStub);
    /* Make sure it is still true on a subsequent call */
    Set<IOnDemandAnalysis> set2 = OnDemandAnalysisManager.getInstance().getOndemandAnalyses(trace);
    assertTrue(set1.equals(set2));
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) IOnDemandAnalysis(org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis) OnDemandAnalysisStub(org.eclipse.tracecompass.tmf.tests.stubs.analysis.ondemand.OnDemandAnalysisStub) Test(org.junit.Test)

Example 4 with IOnDemandAnalysis

use of org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis 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)

Aggregations

IOnDemandAnalysis (org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis)4 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)4 Test (org.junit.Test)2 IFolder (org.eclipse.core.resources.IFolder)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)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 Nullable (org.eclipse.jdt.annotation.Nullable)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Shell (org.eclipse.swt.widgets.Shell)1 NonNullUtils.nullToEmptyString (org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString)1 LamiAnalysis (org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis)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 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)1