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;
}
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();
}
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();
}
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()));
}
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;
}
Aggregations