Search in sources :

Example 6 with TmfTraceManager

use of org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager in project tracecompass by tracecompass.

the class TrimTraceHandler method execute.

@Override
@Nullable
public Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    Object firstElement = ((IStructuredSelection) selection).getFirstElement();
    final TmfCommonProjectElement traceElem = (firstElement instanceof TmfTraceElement) ? ((TmfTraceElement) firstElement).getElementUnderTraceFolder() : (TmfCommonProjectElement) firstElement;
    ITmfTrace trace = traceElem.getTrace();
    if (trace == null || !isValid(trace)) {
        /* That trace is not currently opened */
        return null;
    }
    /* Retrieve the current time range */
    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    TmfTraceManager tm = TmfTraceManager.getInstance();
    TmfTimeRange timeRange = tm.getTraceContext(trace).getSelectionRange();
    if (Objects.equals(timeRange.getStartTime(), timeRange.getEndTime())) {
        MessageDialog.openError(shell, Messages.TrimTraces_InvalidTimeRange_DialogTitle, Messages.TrimTraces_InvalidTimeRange_DialogText);
        return null;
    }
    /* Ensure the time range is in the right direction */
    final TmfTimeRange tr = ((timeRange.getStartTime().compareTo(timeRange.getEndTime()) > 0) ? new TmfTimeRange(timeRange.getEndTime(), timeRange.getStartTime()) : timeRange);
    /*
         * Pop a dialog asking the user to select a parent directory for the new
         * trace.
         */
    TrimTraceDialog dialog = new TrimTraceDialog(shell, traceElem);
    if (dialog.open() != Window.OK) {
        return null;
    }
    Object result = dialog.getFirstResult();
    if (result == null) {
        /* Dialog was cancelled, take no further action. */
        return null;
    }
    /* Verify that the selected path is valid and writeable */
    final Path destinationPath = checkNotNull(Paths.get(result.toString()));
    if (destinationPath.toFile().exists()) {
        MessageDialog.openError(shell, Messages.TrimTraces_InvalidDirectory_DialogTitle, Messages.TrimTraces_InvalidDirectory_DialogText);
        return null;
    }
    TraceToTrim toTrim = TraceToTrim.create(traceElem, destinationPath);
    if (toTrim == null) {
        return null;
    }
    try {
        toTrim.createDir();
    } catch (IOException e) {
        /* Should not happen since we have checked permissions, etc. */
        throw new ExecutionException(e.getMessage(), e);
    }
    TmfWorkspaceModifyOperation trimOperation = new TmfWorkspaceModifyOperation() {

        @Override
        public void execute(@Nullable IProgressMonitor monitor) throws CoreException {
            SubMonitor mon = SubMonitor.convert(monitor, 2);
            toTrim.trim(tr, mon);
            /*
                 * Import the new trace into the current project, at the
                 * top-level.
                 */
            TmfProjectElement currentProjectElement = traceElem.getProject();
            TmfTraceFolder traceFolder = currentProjectElement.getTracesFolder();
            toTrim.importTrace(mon);
            if (mon.isCanceled()) {
                return;
            }
            if (traceFolder != null) {
                Display.getDefault().asyncExec(toTrim::open);
            } else {
                // $NON-NLS-1$
                Activator.getDefault().logWarning("Trace folder does not exist: " + toTrim.fDestinationPath);
            }
        }
    };
    try {
        PlatformUI.getWorkbench().getProgressService().run(true, true, trimOperation);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (InvocationTargetException e) {
        TraceUtils.displayErrorMsg(Messages.TrimTraceHandler_failMsg, e.getMessage(), e);
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) SubMonitor(org.eclipse.core.runtime.SubMonitor) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) IOException(java.io.IOException) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) InvocationTargetException(java.lang.reflect.InvocationTargetException) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Shell(org.eclipse.swt.widgets.Shell) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) TrimTraceDialog(org.eclipse.tracecompass.tmf.ui.project.wizards.TrimTraceDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) ISelection(org.eclipse.jface.viewers.ISelection) TmfWorkspaceModifyOperation(org.eclipse.tracecompass.internal.tmf.ui.project.operations.TmfWorkspaceModifyOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) Nullable(org.eclipse.jdt.annotation.Nullable) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 7 with TmfTraceManager

use of org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager in project tracecompass by tracecompass.

the class PinAndCloneTest method testFollow.

/**
 * Test the follow time updates functionality
 */
@Test
public void testFollow() {
    TmfTraceManager traceManager = TmfTraceManager.getInstance();
    ITmfTrace ust = traceManager.getActiveTrace();
    assertNotNull(ust);
    ITmfTrace kernelTest = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.CONTEXT_SWITCHES_KERNEL);
    SWTBotUtils.openTrace(TRACE_PROJECT_NAME, kernelTest.getPath(), TRACETYPE_ID);
    /* Finish waiting for the trace to index */
    WaitUtils.waitForJobs();
    SWTBotEditor kernelEditor = SWTBotUtils.activateEditor(fBot, kernelTest.getName());
    // wait for the editor to be ready.
    fBot.editorByTitle(kernelTest.getName());
    ITmfTrace kernel = traceManager.getActiveTrace();
    assertNotNull(kernel);
    SWTBotTable kernelEventTable = kernelEditor.bot().table();
    SWTBotTableItem kernelEvent = kernelEventTable.getTableItem(5);
    kernelEvent.contextMenu(FOLLOW_TIME_UPDATES_FROM_OTHER_TRACES).click();
    SWTBotUtils.activateEditor(fBot, ust.getName());
    TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, RANGE, ust));
    // assert that the kernel trace followed the ust trace's range
    IWorkbenchPart part = fOriginalViewBot.getViewReference().getPart(false);
    assertTrue(part instanceof AbstractTimeGraphView);
    AbstractTimeGraphView abstractTimeGraphView = (AbstractTimeGraphView) part;
    fBot.waitUntil(ConditionHelpers.timeGraphRangeCondition(abstractTimeGraphView, ust, RANGE));
    SWTBotUtils.activateEditor(fBot, kernel.getName());
    fBot.waitUntil(ConditionHelpers.timeGraphRangeCondition(abstractTimeGraphView, kernel, RANGE));
    // unfollow (don't use context menu on table item to avoid updating selection)
    kernelEventTable.contextMenu(FOLLOW_TIME_UPDATES_FROM_OTHER_TRACES).click();
    TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, ust.getInitialTimeRange(), ust));
    fBot.waitUntil(ConditionHelpers.timeGraphRangeCondition(abstractTimeGraphView, kernel, RANGE));
    kernelTest.dispose();
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor) AbstractTimeGraphView(org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) TmfWindowRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal) SWTBotTableItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem) Test(org.junit.Test)

Example 8 with TmfTraceManager

use of org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager in project tracecompass by tracecompass.

the class PinAndCloneTest method testCloneSingleTrace.

/**
 * Test the cloning feature.
 */
@Test
public void testCloneSingleTrace() {
    // single trace.
    SWTBotMenu cloneMenu = fOriginalViewBot.viewMenu().menu(NEW_VIEW_MENU);
    /*
         * assert that the original editor was not renamed and that the cloned one
         * exists and is pinned to the UST trace.
         */
    cloneMenu.menu(PINNED_TO_PREFIX + fUstTestTrace.getName()).click();
    assertOriginalViewTitle(TIME_GRAPH_VIEW_TITLE);
    SWTBotView clonedView = fBot.viewByTitle(PINNED_TO_UST_TIME_GRAPH_VIEW_TITLE);
    assertEquals("Should not have created a new instance", 1, fBot.editors().size());
    clonedView.close();
    /*
         * Assert that a new instance is created.
         */
    cloneMenu.menu(PINNED_TO_PREFIX + fUstTestTrace.getName() + " | new instance").click();
    assertOriginalViewTitle(TIME_GRAPH_VIEW_TITLE);
    clonedView = fBot.viewByTitle(PINNED_TO_UST_TIME_GRAPH_VIEW_TITLE2);
    assertEquals("Should have created a new instance", 2, fBot.editors().size());
    SWTBotEditor cloneEditor = fBot.editorByTitle(fUstTestTrace.getName() + CLONED_TRACE_SUFFIX);
    // Get the window range of the cloned trace
    TmfTraceManager traceManager = TmfTraceManager.getInstance();
    ITmfTrace cloneTrace = traceManager.getActiveTrace();
    assertNotNull(cloneTrace);
    // go back to original trace, pin it
    SWTBotUtils.activateEditor(fBot, fUstTestTrace.getName());
    fOriginalViewBot.toolbarButton(PIN_VIEW_BUTTON_NAME).click();
    ITmfTrace ust = traceManager.getActiveTrace();
    TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, RANGE, ust));
    // assert that the cloned trace's window range did not change
    SWTBotUtils.activateEditor(fBot, cloneTrace.getName() + CLONED_TRACE_SUFFIX);
    IWorkbenchPart part = clonedView.getViewReference().getPart(false);
    assertTrue(part instanceof AbstractTimeGraphView);
    AbstractTimeGraphView abstractTimeGraphView = (AbstractTimeGraphView) part;
    fBot.waitUntil(ConditionHelpers.timeGraphRangeCondition(abstractTimeGraphView, cloneTrace, INITIAL_UST_RANGE));
    cloneEditor.close();
}
Also used : SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) AbstractTimeGraphView(org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) SWTBotMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) TmfWindowRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal) Test(org.junit.Test)

Example 9 with TmfTraceManager

use of org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager in project tracecompass by tracecompass.

the class TrimTraceHandler method isEnabled.

@Override
public boolean isEnabled() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench == null) {
        return false;
    }
    @SuppressWarnings("null") IHandlerService service = workbench.getService(IHandlerService.class);
    // we need the current state, and the map, but the command and the
    // trigger are
    // not necessary for getCurrentSelection
    ExecutionEvent executionEvent = new ExecutionEvent(null, Collections.emptyMap(), null, service.getCurrentState());
    final Object element = HandlerUtil.getCurrentSelection(executionEvent);
    if (!(element instanceof TreeSelection)) {
        return false;
    }
    /*
         * plugin.xml should have done type/count verification already
         */
    Object firstElement = ((TreeSelection) element).getFirstElement();
    ITmfTrace trace = null;
    if (firstElement instanceof TmfCommonProjectElement) {
        TmfCommonProjectElement traceElem = (TmfCommonProjectElement) firstElement;
        if (traceElem instanceof TmfTraceElement) {
            traceElem = ((TmfTraceElement) traceElem).getElementUnderTraceFolder();
        }
        trace = traceElem.getTrace();
    }
    if (trace == null || !isValid(trace)) {
        return false;
    }
    /* Only enable the action if a time range is currently selected */
    TmfTraceManager tm = TmfTraceManager.getInstance();
    TmfTimeRange selectionRange = tm.getTraceContext(trace).getSelectionRange();
    return !(selectionRange.getStartTime().equals(selectionRange.getEndTime()));
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) IHandlerService(org.eclipse.ui.handlers.IHandlerService) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) TreeSelection(org.eclipse.jface.viewers.TreeSelection) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)

Example 10 with TmfTraceManager

use of org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager 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

TmfTraceManager (org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager)11 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)9 SWTBotEditor (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor)6 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)6 Test (org.junit.Test)6 TmfWindowRangeUpdatedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal)5 SWTBotView (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView)3 TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Shell (org.eclipse.swt.widgets.Shell)2 WidgetNotFoundException (org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException)2 DefaultCondition (org.eclipse.swtbot.swt.finder.waits.DefaultCondition)2 SWTBotMenu (org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu)2 SWTBotTable (org.eclipse.swtbot.swt.finder.widgets.SWTBotTable)2 SWTBotTableItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem)2 SWTBotToolbarDropDownButton (org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarDropDownButton)2 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)2