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