Search in sources :

Example 1 with FlowScopeLog

use of org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog 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();
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) FlowScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) FlowScopeLogBuilder(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder) ICoreElementResolver(org.eclipse.tracecompass.tmf.core.model.ICoreElementResolver) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 2 with FlowScopeLog

use of org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog 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()));
    }
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) FlowScopeLogBuilder(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) FlowScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 3 with FlowScopeLog

use of org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog 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();
            }
        }
    }
}
Also used : ExecutionType(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType) TmfEventThread(org.eclipse.tracecompass.internal.tmf.core.component.TmfEventThread) FlowScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog) FlowScopeLogBuilder(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder)

Example 4 with FlowScopeLog

use of org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog 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();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) TmfStartAnalysisSignal(org.eclipse.tracecompass.tmf.core.signal.TmfStartAnalysisSignal) FlowScopeLogBuilder(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) FlowScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog) Job(org.eclipse.core.runtime.jobs.Job) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 5 with FlowScopeLog

use of org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog 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();
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) AtomicReference(java.util.concurrent.atomic.AtomicReference) TmfEditorInput(org.eclipse.tracecompass.tmf.ui.editors.TmfEditorInput) FlowScopeLogBuilder(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder) InvocationTargetException(java.lang.reflect.InvocationTargetException) IWorkbench(org.eclipse.ui.IWorkbench) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) FlowScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

FlowScopeLog (org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog)24 FlowScopeLogBuilder (org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder)24 Logger (java.util.logging.Logger)7 Test (org.junit.Test)7 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)6 ArrayList (java.util.ArrayList)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IStatus (org.eclipse.core.runtime.IStatus)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 Status (org.eclipse.core.runtime.Status)3 Job (org.eclipse.core.runtime.jobs.Job)3 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)3 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2