use of org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder in project tracecompass by tracecompass.
the class AbstractTreeDataProvider method fetchTree.
@Override
public final TmfModelResponse<TmfTreeModel<M>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
fLock.readLock().lock();
try {
if (fCached != null) {
/*
* If the tree depends on the filter, isCacheable should return false (by
* contract). If the tree is not cacheable, fCached will always be null, and we
* will never enter this block.
*/
return fCached;
}
} finally {
fLock.readLock().unlock();
}
fLock.writeLock().lock();
fAnalysisModule.waitForInitialization();
ITmfStateSystem ss = fAnalysisModule.getStateSystem();
if (ss == null) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
}
boolean complete = ss.waitUntilBuilt(0);
try (FlowScopeLog scope = // $NON-NLS-1$
new FlowScopeLogBuilder(LOGGER, Level.FINE, "AbstractTreeDataProvider#fetchTree").setCategory(getClass().getSimpleName()).build()) {
TmfTreeModel<M> tree = null;
/* Don't query empty state system */
if (ss.getNbAttributes() > 0 && ss.getStartTime() != Long.MIN_VALUE) {
tree = getTree(ss, fetchParameters, monitor);
for (M model : tree.getEntries()) {
if (model instanceof ICoreElementResolver) {
fEntryMetadata.put(model.getId(), ((ICoreElementResolver) model).getMetadata());
}
}
}
if (complete) {
TmfModelResponse<TmfTreeModel<M>> response = new TmfModelResponse<>(tree, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
if (isCacheable()) {
fCached = response;
}
return response;
}
return new TmfModelResponse<>(tree, ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
} catch (StateSystemDisposedException e) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
} finally {
fLock.writeLock().unlock();
}
}
use of org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder in project tracecompass by tracecompass.
the class AbstractTreeCommonXDataProvider method fetchXY.
@Override
public final TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
A module = getAnalysisModule();
// TODO server: Parameters validation should be handle separately. It
// can be either in the data provider itself or before calling it. It
// will avoid the creation of filters and the content of the map can be
// use directly.
SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
if (filter == null) {
return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
TmfModelResponse<ITmfXyModel> res = verifyParameters(module, filter, monitor);
if (res != null) {
return res;
}
ITmfStateSystem ss = Objects.requireNonNull(module.getStateSystem(), // $NON-NLS-1$
"Statesystem should have been verified by verifyParameters");
long currentEnd = ss.getCurrentEndTime();
boolean complete = ss.waitUntilBuilt(0) || filter.getEnd() <= currentEnd;
try (FlowScopeLog scope = // $NON-NLS-1$
new FlowScopeLogBuilder(LOGGER, Level.FINE, "AbstractTreeXyDataProvider#fetchXY").setCategory(getClass().getSimpleName()).build()) {
Collection<IYModel> yModels = getYSeriesModels(ss, fetchParameters, monitor);
if (yModels == null) {
// getModels returns null if the query was cancelled.
return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
}
return TmfXyResponseFactory.create(getTitle(), filter.getTimesRequested(), ImmutableList.copyOf(yModels), complete);
} catch (StateSystemDisposedException | TimeRangeException | IndexOutOfBoundsException e) {
return TmfXyResponseFactory.createFailedResponse(String.valueOf(e.getMessage()));
}
}
use of org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder in project tracecompass by tracecompass.
the class TmfRequestExecutor method execute.
@Override
public synchronized void execute(final Runnable command) {
// We are expecting MyEventThread:s
if (!(command instanceof TmfEventThread)) {
// $NON-NLS-1$ //$NON-NLS-2$
TraceCompassLogUtils.traceInstant(LOGGER, Level.WARNING, "RequestExecutor:NotATmfEventThread", "cmd", command.toString());
return;
}
try (FlowScopeLog scope = new FlowScopeLogBuilder(LOGGER, Level.FINE, "RequestExecutor:CreatingThread").setCategory(LOG_CATEGORY).build()) {
// $NON-NLS-1$
// Wrap the thread in a MyThread
TmfEventThread thread = (TmfEventThread) command;
TmfEventThread wrapper = new TmfEventThread(thread) {
@Override
public void run() {
try (FlowScopeLog log = new FlowScopeLogBuilder(LOGGER, Level.FINE, "RequestExecutor:RunningRequest", "thread", thread.getThread(), "execution type", thread.getExecType()).setParentScope(scope).build()) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
thread.run();
} finally {
scheduleNext();
}
}
};
// Add the thread to the appropriate queue
ExecutionType priority = thread.getExecType();
if (priority == ExecutionType.FOREGROUND) {
if (!fForegroundTasks.offer(wrapper)) {
wrapper.cancel();
}
} else {
if (!fBackgroundTasks.offer(wrapper)) {
wrapper.cancel();
}
}
}
}
use of org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder in project tracecompass by tracecompass.
the class TmfAbstractAnalysisModule method execute.
private void execute(final ITmfTrace trace) {
try (FlowScopeLog analysisLog = new FlowScopeLogBuilder(LOGGER, Level.FINE, "TmfAbstractAnalysis:scheduling", "name", getName()).setCategory(getId()).build()) {
/* Do not execute if analysis has already run */
if (fFinishedLatch.getCount() == 0) {
// $NON-NLS-1$
TmfCoreTracer.traceAnalysis(getId(), getTrace(), "already executed");
return;
}
/* Do not execute if analysis already running */
synchronized (syncObj) {
if (fStarted) {
// $NON-NLS-1$
TmfCoreTracer.traceAnalysis(getId(), getTrace(), "already started, not starting again");
return;
}
fStarted = true;
// Reset cancellation and failure cause
fAnalysisCancelled = false;
fFailureCause = null;
}
/*
* Execute dependent analyses before creating the job for this one
*/
final Iterable<IAnalysisModule> dependentAnalyses = getDependentAnalyses();
int depLevel = 0;
for (IAnalysisModule module : dependentAnalyses) {
module.schedule();
// Add the dependency level of the analysis + 1 to make sure
// that if
// an analysis already depends on another, it is taken into
// account
depLevel += module.getDependencyLevel() + 1;
}
fDependencyLevel = depLevel;
/*
* Actual analysis will be run on a separate thread
*/
String jobName = checkNotNull(NLS.bind(Messages.TmfAbstractAnalysisModule_RunningAnalysis, getName()));
fJob = new Job(jobName) {
@Override
@Nullable
protected IStatus run(@Nullable final IProgressMonitor monitor) {
try (FlowScopeLog jobLog = new FlowScopeLogBuilder(LOGGER, Level.FINE, "TmfAbstractAnalysis:executing").setParentScope(analysisLog).build()) {
// $NON-NLS-1$
IProgressMonitor mon = SubMonitor.convert(monitor);
try {
broadcast(new TmfStartAnalysisSignal(TmfAbstractAnalysisModule.this, TmfAbstractAnalysisModule.this));
// $NON-NLS-1$
TmfCoreTracer.traceAnalysis(TmfAbstractAnalysisModule.this.getId(), TmfAbstractAnalysisModule.this.getTrace(), "started");
fAnalysisCancelled = !executeAnalysis(mon);
for (IAnalysisModule module : dependentAnalyses) {
module.waitForCompletion(mon);
}
// $NON-NLS-1$
TmfCoreTracer.traceAnalysis(TmfAbstractAnalysisModule.this.getId(), TmfAbstractAnalysisModule.this.getTrace(), "finished");
} catch (TmfAnalysisException e) {
// $NON-NLS-1$
Activator.logError("Error executing analysis with trace " + trace.getName(), e);
} catch (OperationCanceledException e) {
// Analysis was canceled
} catch (Exception e) {
// $NON-NLS-1$
Activator.logError("Unexpected error executing analysis with trace " + trace.getName(), e);
fail(e);
// Reset analysis so that it can be executed again.
resetAnalysis();
// $NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.OK, "Exception executing analysis", e);
} finally {
synchronized (syncObj) {
setAnalysisCompleted();
}
TmfTraceManager.refreshSupplementaryFiles(trace);
}
if (!fAnalysisCancelled) {
return Status.OK_STATUS;
}
// Reset analysis so that it can be executed again.
resetAnalysis();
return Status.CANCEL_STATUS;
}
}
@Override
protected void canceling() {
// $NON-NLS-1$
TmfCoreTracer.traceAnalysis(getId(), getTrace(), "job cancelled");
TmfAbstractAnalysisModule.this.canceling();
}
};
fJob.schedule();
}
}
use of org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder in project tracecompass by tracecompass.
the class TmfOpenTraceHelper method reopenTraceFromElement.
/**
* Reopen a trace or experiment from a project element in the provided editor
*
* @param traceElement
* the {@link TmfTraceElement} to open
* @param editor
* the reusable editor
*/
public static void reopenTraceFromElement(final TmfCommonProjectElement traceElement, final IReusableEditor editor) {
try (FlowScopeLog flow = new FlowScopeLogBuilder(LOGGER, Level.FINE, "reopenTraceFromElement").setCategory(LOCAL_CATEGORY).build()) {
// $NON-NLS-1$
AtomicReference<IFile> bookmarksFile = new AtomicReference<>();
try (FlowScopeLog scopeLog = new FlowScopeLogBuilder(LOGGER, Level.FINE, "createBookmarks").setParentScope(flow).build()) {
// $NON-NLS-1$
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(monitor -> {
try {
traceElement.refreshSupplementaryFolder(monitor);
bookmarksFile.set(traceElement.createBookmarksFile(monitor));
} catch (OperationCanceledException e) {
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
});
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
} catch (final InvocationTargetException e) {
Activator.getDefault().logError(NLS.bind(Messages.TmfOpenTraceHelper_ErrorOpeningElement, traceElement.getTypeName()) + ' ' + traceElement.getName());
TraceUtils.displayErrorMsg(NLS.bind(Messages.TmfOpenTraceHelper_OpenElement, traceElement.getTypeName()), NLS.bind(Messages.TmfOpenTraceHelper_ErrorElement, traceElement.getTypeName()) + ENDL + ENDL + e.getTargetException().getMessage(), e.getTargetException());
return;
}
IFile file = bookmarksFile.get();
if (file == null) {
return;
}
Thread thread = new Thread() {
@Override
public void run() {
try (FlowScopeLog scopeLog = new FlowScopeLogBuilder(LOGGER, Level.FINE, "createThread").setParentScope(flow).build()) {
// $NON-NLS-1$
final ITmfTrace trace = openProjectElement(traceElement);
if (trace == null) {
return;
}
final IEditorInput editorInput = new TmfEditorInput(file, trace);
Display.getDefault().asyncExec(() -> {
try (FlowScopeLog innerScopeLog = new FlowScopeLogBuilder(LOGGER, Level.FINE, "OpenEditor").setParentScope(flow).build()) {
// $NON-NLS-1$
final IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow activeWorkbenchWindow = wb.getActiveWorkbenchWindow();
if (activeWorkbenchWindow == null) {
return;
}
final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
activePage.reuseEditor(editor, editorInput);
activePage.activate(editor);
}
});
}
}
};
thread.start();
}
}
Aggregations