Search in sources :

Example 1 with TraceSessionComponent

use of org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent in project tracecompass by tracecompass.

the class AddContextOnDomainHandler method isEnabled.

@Override
public boolean isEnabled() {
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }
    TraceDomainComponent domain = null;
    TraceSessionComponent session = null;
    // Check if one domain is selected
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext(); ) {
            Object element = iterator.next();
            if (element instanceof TraceDomainComponent) {
                TraceDomainComponent tmpDomain = (TraceDomainComponent) element;
                session = (TraceSessionComponent) tmpDomain.getParent();
                // Add only TraceDomainComponent whose TraceSessionComponent parent is inactive and not destroyed
                if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) {
                    domain = tmpDomain;
                }
            }
        }
    }
    boolean isEnabled = domain != null;
    if (TraceDomainType.JUL.equals(domain)) {
        isEnabled = false;
    }
    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new DomainCommandParameter(checkNotNull(session), checkNotNull(domain));
        }
    } finally {
        fLock.unlock();
    }
    return isEnabled;
}
Also used : TraceDomainComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent) TraceSessionComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 2 with TraceSessionComponent

use of org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent in project tracecompass by tracecompass.

the class AddContextOnEventHandler method isEnabled.

@Override
public boolean isEnabled() {
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }
    TraceEventComponent event = null;
    TraceSessionComponent session = null;
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext(); ) {
            Object element = iterator.next();
            if (element instanceof TraceEventComponent) {
                // Add only if corresponding TraceSessionComponents is inactive and not destroyed
                TraceEventComponent tmpEvent = (TraceEventComponent) element;
                session = tmpEvent.getSession();
                if (session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
                    event = tmpEvent;
                }
            }
        }
    }
    boolean isEnabled = (event != null);
    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new EventCommandParameter(checkNotNull(session), checkNotNull(event));
        }
    } finally {
        fLock.unlock();
    }
    return isEnabled;
}
Also used : TraceSessionComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) TraceEventComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceEventComponent)

Example 3 with TraceSessionComponent

use of org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent in project tracecompass by tracecompass.

the class AssignEventHandler method isEnabled.

@Override
public boolean isEnabled() {
    @NonNull ArrayList<@NonNull BaseEventComponent> events = new ArrayList<>();
    @NonNull TraceSessionComponent[] sessions = null;
    TraceDomainType domain = null;
    TraceEventType eventType = null;
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }
    // Check if one or more session are selected
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext(); ) {
            Object element = iterator.next();
            if (element instanceof BaseEventComponent) {
                BaseEventComponent event = (BaseEventComponent) element;
                ITraceControlComponent provider = event.getParent();
                // check for the domain provider
                TraceDomainType temp = null;
                if (provider instanceof KernelProviderComponent) {
                    temp = TraceDomainType.KERNEL;
                } else if (provider instanceof UstProviderComponent) {
                    // Loggers are under the UST domain
                    temp = TraceDomainType.UST;
                } else {
                    return false;
                }
                if (domain == null) {
                    domain = temp;
                } else {
                    // don't mix events from Kernel and UST provider
                    if (!domain.equals(temp)) {
                        return false;
                    }
                }
                // The events have to be the same type
                if (eventType == null) {
                    eventType = event.getEventType();
                } else if (!eventType.equals(event.getEventType())) {
                    events.clear();
                    break;
                }
                // Add BaseEventComponents
                events.add(event);
                if (sessions == null) {
                    TargetNodeComponent root = (TargetNodeComponent) event.getParent().getParent().getParent();
                    sessions = root.getSessions();
                }
            }
        }
    }
    boolean isEnabled = ((!events.isEmpty()) && (sessions != null) && (sessions.length > 0));
    // To avoid compiler warnings check for null even if isKernel is always not null when used below
    if (domain == null) {
        return false;
    }
    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new Parameter(NonNullUtils.checkNotNull(sessions), events, domain);
        }
    } finally {
        fLock.unlock();
    }
    return isEnabled;
}
Also used : TraceDomainType(org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType) TraceSessionComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent) TraceEventType(org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEventType) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) UstProviderComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.UstProviderComponent) BaseEventComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.BaseEventComponent) NonNull(org.eclipse.jdt.annotation.NonNull) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ITraceControlComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent) TargetNodeComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent) KernelProviderComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.KernelProviderComponent)

Example 4 with TraceSessionComponent

use of org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent in project tracecompass by tracecompass.

the class AssignEventHandler method execute.

// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // Make a copy for thread safety
    Parameter tmpParam = null;
    fLock.lock();
    try {
        tmpParam = fParam;
        if (tmpParam == null) {
            return null;
        }
        tmpParam = new Parameter(tmpParam);
    } finally {
        fLock.unlock();
    }
    final Parameter param = tmpParam;
    // Open dialog box to retrieve the session and channel where the events should be enabled in.
    final IGetEventInfoDialog dialog = TraceControlDialogFactory.getInstance().getGetEventInfoDialog();
    dialog.setDomain(param.getDomain());
    dialog.setSessions(param.getSessions());
    if (dialog.open() != Window.OK) {
        return null;
    }
    Job job = new Job(Messages.TraceControl_EnableEventsJob) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            Exception error = null;
            TraceSessionComponent session = dialog.getSession();
            try {
                List<String> eventNames = new ArrayList<>();
                List<BaseEventComponent> events = param.getEvents();
                // Find the type of the events (all the events in the list are the same type)
                TraceEventType eventType = !events.isEmpty() ? events.get(0).getEventType() : null;
                // Create list of event names
                for (Iterator<BaseEventComponent> iterator = events.iterator(); iterator.hasNext(); ) {
                    BaseEventComponent baseEvent = iterator.next();
                    eventNames.add(baseEvent.getName());
                }
                TraceChannelComponent channel = dialog.getChannel();
                if (TraceEventType.TRACEPOINT.equals(eventType)) {
                    if (channel == null) {
                        // enable events on default channel (which will be created by lttng-tools)
                        session.enableEvents(eventNames, param.getDomain(), dialog.getFilterExpression(), null, monitor);
                    } else {
                        channel.enableEvents(eventNames, dialog.getFilterExpression(), null, monitor);
                    }
                } else if (TraceEventType.SYSCALL.equals(eventType)) {
                    if (channel == null) {
                        session.enableSyscalls(eventNames, monitor);
                    } else {
                        channel.enableSyscalls(eventNames, monitor);
                    }
                }
            } catch (ExecutionException e) {
                error = e;
            }
            // refresh in all cases
            if (session != null) {
                refresh(new CommandParameter(session));
            }
            if (error != null) {
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_EnableEventsFailure, error);
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TraceSessionComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent) TraceEventType(org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEventType) ArrayList(java.util.ArrayList) TraceChannelComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent) ExecutionException(org.eclipse.core.commands.ExecutionException) IGetEventInfoDialog(org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.IGetEventInfoDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) BaseEventComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.BaseEventComponent) Job(org.eclipse.core.runtime.jobs.Job) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 5 with TraceSessionComponent

use of org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent in project tracecompass by tracecompass.

the class AssignLoggerHandler method isEnabled.

@Override
public boolean isEnabled() {
    @NonNull ArrayList<@NonNull BaseLoggerComponent> loggers = new ArrayList<>();
    @NonNull TraceSessionComponent[] sessions = null;
    TraceDomainType domain = null;
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }
    // Check if one or more session are selected
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext(); ) {
            Object element = iterator.next();
            if (element instanceof BaseLoggerComponent) {
                BaseLoggerComponent logger = (BaseLoggerComponent) element;
                // The loggers have to be the same domain (multiple selection)
                if (domain == null) {
                    domain = logger.getDomain();
                } else if (!domain.equals(logger.getDomain())) {
                    loggers.clear();
                    break;
                }
                // Add BaseLoggerComponents
                loggers.add(logger);
                if (sessions == null) {
                    TargetNodeComponent root = (TargetNodeComponent) logger.getParent().getParent().getParent();
                    sessions = root.getSessions();
                }
            }
        }
    }
    boolean isEnabled = ((!loggers.isEmpty()) && (sessions != null) && (sessions.length > 0));
    if (domain == null) {
        return false;
    }
    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new Parameter(NonNullUtils.checkNotNull(sessions), loggers, domain);
        }
    } finally {
        fLock.unlock();
    }
    return isEnabled;
}
Also used : TraceDomainType(org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType) BaseLoggerComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.BaseLoggerComponent) TraceSessionComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NonNull(org.eclipse.jdt.annotation.NonNull) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) TargetNodeComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent)

Aggregations

TraceSessionComponent (org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent)36 ArrayList (java.util.ArrayList)17 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)16 ISelection (org.eclipse.jface.viewers.ISelection)15 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)15 ITraceControlComponent (org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent)11 TargetNodeComponent (org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent)11 TraceChannelComponent (org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent)11 IStatus (org.eclipse.core.runtime.IStatus)10 ExecutionException (org.eclipse.core.commands.ExecutionException)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)9 Status (org.eclipse.core.runtime.Status)9 Job (org.eclipse.core.runtime.jobs.Job)9 Test (org.junit.Test)9 TraceEventComponent (org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceEventComponent)8 CreateSessionDialogStub (org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub)7 DestroyConfirmDialogStub (org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub)7 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)7 GetEventInfoDialogStub (org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.GetEventInfoDialogStub)6 BaseEventComponent (org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.BaseEventComponent)6