1 /**********************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.handlers
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Arrays
;
17 import java
.util
.Iterator
;
18 import java
.util
.List
;
20 import org
.eclipse
.core
.commands
.ExecutionEvent
;
21 import org
.eclipse
.core
.commands
.ExecutionException
;
22 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
23 import org
.eclipse
.core
.runtime
.IStatus
;
24 import org
.eclipse
.core
.runtime
.Status
;
25 import org
.eclipse
.core
.runtime
.jobs
.Job
;
26 import org
.eclipse
.jdt
.annotation
.NonNull
;
27 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
28 import org
.eclipse
.jface
.viewers
.ISelection
;
29 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
30 import org
.eclipse
.jface
.window
.Window
;
31 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceDomainType
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.ControlView
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.IGetEventInfoDialog
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.BaseEventComponent
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.KernelProviderComponent
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
44 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
45 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.UstProviderComponent
;
46 import org
.eclipse
.ui
.IWorkbenchPage
;
50 * Command handler implementation to assign events to a session and channel and enable/configure them.
51 * This is done on the trace provider level.
54 * @author Bernd Hufmann
56 public class AssignEventHandler
extends BaseControlViewHandler
{
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
63 * The command execution parameter.
65 private Parameter fParam
;
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
72 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
73 // Make a copy for thread safety
74 Parameter tmpParam
= null;
78 if (tmpParam
== null) {
81 tmpParam
= new Parameter(tmpParam
);
85 final Parameter param
= tmpParam
;
87 // Open dialog box to retrieve the session and channel where the events should be enabled in.
88 final IGetEventInfoDialog dialog
= TraceControlDialogFactory
.getInstance().getGetEventInfoDialog();
89 dialog
.setDomain(param
.getDomain());
90 dialog
.setSessions(param
.getSessions());
92 if (dialog
.open() != Window
.OK
) {
96 Job job
= new Job(Messages
.TraceControl_EnableEventsJob
) {
98 protected IStatus
run(IProgressMonitor monitor
) {
100 Exception error
= null;
101 TraceSessionComponent session
= dialog
.getSession();
103 List
<String
> eventNames
= new ArrayList
<>();
104 List
<BaseEventComponent
> events
= param
.getEvents();
105 // Find the type of the events (all the events in the list are the same type)
106 TraceEventType eventType
= !events
.isEmpty() ? events
.get(0).getEventType() : null;
107 // Create list of event names
108 for (Iterator
<BaseEventComponent
> iterator
= events
.iterator(); iterator
.hasNext();) {
109 BaseEventComponent baseEvent
= iterator
.next();
110 eventNames
.add(baseEvent
.getName());
113 TraceChannelComponent channel
= dialog
.getChannel();
114 if (TraceEventType
.TRACEPOINT
.equals(eventType
)) {
115 if (channel
== null) {
116 // enable events on default channel (which will be created by lttng-tools)
117 session
.enableEvents(eventNames
, param
.getDomain(), dialog
.getFilterExpression(), null, monitor
);
119 channel
.enableEvents(eventNames
, dialog
.getFilterExpression(), null, monitor
);
121 } else if (TraceEventType
.SYSCALL
.equals(eventType
)) {
122 if (channel
== null) {
123 session
.enableSyscalls(eventNames
, monitor
);
125 channel
.enableSyscalls(eventNames
, monitor
);
129 } catch (ExecutionException e
) {
133 // refresh in all cases
134 if (session
!= null) {
135 refresh(new CommandParameter(session
));
139 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_EnableEventsFailure
, error
);
141 return Status
.OK_STATUS
;
151 public boolean isEnabled() {
152 @NonNull ArrayList
<@NonNull BaseEventComponent
> events
= new ArrayList
<>();
153 @NonNull TraceSessionComponent
[] sessions
= null;
154 TraceDomainType domain
= null;
155 TraceEventType eventType
= null;
157 // Get workbench page for the Control View
158 IWorkbenchPage page
= getWorkbenchPage();
163 // Check if one or more session are selected
164 ISelection selection
= page
.getSelection(ControlView
.ID
);
165 if (selection
instanceof StructuredSelection
) {
167 StructuredSelection structered
= ((StructuredSelection
) selection
);
168 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
169 Object element
= iterator
.next();
170 if (element
instanceof BaseEventComponent
) {
171 BaseEventComponent event
= (BaseEventComponent
) element
;
172 ITraceControlComponent provider
= event
.getParent();
174 // check for the domain provider
175 TraceDomainType temp
= null;
176 if (provider
instanceof KernelProviderComponent
) {
177 temp
= TraceDomainType
.KERNEL
;
178 } else if (provider
instanceof UstProviderComponent
) {
179 temp
= TraceDomainType
.UST
; // Loggers are under the UST domain
184 if (domain
== null) {
187 // don't mix events from Kernel and UST provider
188 if (!domain
.equals(temp
)) {
192 // The events have to be the same type
193 if (eventType
== null) {
194 eventType
= event
.getEventType();
195 } else if (!eventType
.equals(event
.getEventType())) {
200 // Add BaseEventComponents
203 if (sessions
== null) {
204 TargetNodeComponent root
= (TargetNodeComponent
)event
.getParent().getParent().getParent();
205 sessions
= root
.getSessions();
211 boolean isEnabled
= ((!events
.isEmpty()) && (sessions
!= null) && (sessions
.length
> 0));
213 // To avoid compiler warnings check for null even if isKernel is always not null when used below
214 if (domain
== null) {
222 fParam
= new Parameter(NonNullUtils
.checkNotNull(sessions
), events
, domain
);
231 * Class containing parameter for the command execution.
234 private static final class Parameter
{
237 * The list of event components the command is to be executed on.
239 private final List
<BaseEventComponent
> fEvents
;
242 * The list of available sessions.
244 private final @NonNull TraceSessionComponent
[] fSessions
;
247 * The domain type ({@link TraceDomainType})
249 private final TraceDomainType fDomain
;
254 * @param sessions - a array of trace sessions
255 * @param events - a lists of events to enable
256 * @param domain - domain type ({@link TraceDomainType})
258 public Parameter(@NonNull TraceSessionComponent
[] sessions
, List
<BaseEventComponent
> events
, TraceDomainType domain
) {
259 fSessions
= NonNullUtils
.checkNotNull(Arrays
.copyOf(sessions
, sessions
.length
));
260 fEvents
= new ArrayList
<>();
261 fEvents
.addAll(events
);
267 * @param other - a parameter to copy
269 public Parameter(Parameter other
) {
270 this(other
.fSessions
, other
.fEvents
, other
.fDomain
);
273 public TraceSessionComponent
[] getSessions() {
277 public List
<BaseEventComponent
> getEvents() {
281 public TraceDomainType
getDomain() {