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
.List
;
17 import org
.eclipse
.core
.commands
.ExecutionEvent
;
18 import org
.eclipse
.core
.commands
.ExecutionException
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.core
.runtime
.Status
;
22 import org
.eclipse
.core
.runtime
.jobs
.Job
;
23 import org
.eclipse
.jdt
.annotation
.Nullable
;
24 import org
.eclipse
.jface
.window
.Window
;
25 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ITraceLogLevel
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceDomainType
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.IEnableEventsDialog
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceDomainComponent
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceProviderGroup
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.ILttngControlService
;
37 import org
.eclipse
.ui
.IWorkbenchWindow
;
38 import org
.eclipse
.ui
.PlatformUI
;
42 * Base command handler implementation to enable events.
45 * @author Bernd Hufmann
47 public abstract class BaseEnableEventHandler
extends BaseControlViewHandler
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
53 * The command execution parameter.
56 protected CommandParameter fParam
= null;
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
63 * Enables a list of events for given parameters.
66 * - a parameter instance with data for the command execution
68 * - list of event names
70 * - the domain type ({@link TraceDomainType})
71 * @param filterExpression
72 * - a filter expression
73 * @param excludedEvents
74 * - list of events to exclude
76 * - a progress monitor
77 * @throws ExecutionException
78 * If the command fails for some reason
80 public abstract void enableEvents(CommandParameter param
, List
<String
> eventNames
, TraceDomainType domain
, String filterExpression
, List
<String
> excludedEvents
, IProgressMonitor monitor
) throws ExecutionException
;
83 * Enables all syscall events.
86 * - a parameter instance with data for the command execution
88 * - a list of syscall names
90 * - a progress monitor
91 * @throws ExecutionException
92 * If the command fails for some reason
94 public abstract void enableSyscalls(CommandParameter param
, List
<String
> syscallNames
, IProgressMonitor monitor
) throws ExecutionException
;
97 * Enables a dynamic probe.
100 * - a parameter instance with data for the command execution
104 * - true for dynamic function entry/return probe else false
106 * - a dynamic probe information
108 * - a progress monitor
109 * @throws ExecutionException
110 * If the command fails for some reason
112 public abstract void enableProbe(CommandParameter param
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
115 * Enables events using log level
118 * - a parameter instance with data for the command execution
120 * - a list of event names
121 * @param logLevelType
125 * @param filterExpression
126 * - a filter expression
130 * - a progress monitor
131 * @throws ExecutionException
132 * If the command fails for some reason
134 public abstract void enableLogLevel(CommandParameter param
, List
<String
> eventNames
, LogLevelType logLevelType
, ITraceLogLevel level
, String filterExpression
, TraceDomainType domain
, IProgressMonitor monitor
) throws ExecutionException
;
138 * - a parameter instance with data for the command execution
139 * @return returns the relevant domain (null if domain is not known)
141 public abstract TraceDomainComponent
getDomain(CommandParameter param
);
144 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
146 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
148 if (window
== null) {
152 // Make a copy for thread safety
153 CommandParameter tmpParam
= null;
157 if (tmpParam
== null) {
160 tmpParam
= tmpParam
.clone();
164 final CommandParameter param
= tmpParam
;
166 TargetNodeComponent node
= param
.getSession().getTargetNode();
167 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
169 final IEnableEventsDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableEventsDialog();
170 dialog
.setTraceProviderGroup((TraceProviderGroup
) providers
.get(0));
171 dialog
.setTraceDomainComponent(getDomain(param
));
173 if (dialog
.open() != Window
.OK
) {
177 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
179 protected IStatus
run(IProgressMonitor monitor
) {
180 Exception error
= null;
182 String filter
= dialog
.getFilterExpression();
183 List
<String
> eventNames
= null;
184 switch (dialog
.getDomain()) {
187 if (dialog
.isAllEvents()) {
188 enableEvents(param
, null, dialog
.getDomain(), filter
, dialog
.getExcludedEvents(), monitor
);
189 } else if (dialog
.isTracepoints()) {
190 // Enable tracepoint events
191 if (dialog
.isAllTracePoints()) {
192 enableEvents(param
, null, dialog
.getDomain(), filter
, dialog
.getExcludedEvents(), monitor
);
194 eventNames
= dialog
.getEventNames();
195 if (!eventNames
.isEmpty()) {
196 enableEvents(param
, eventNames
, dialog
.getDomain(), filter
, dialog
.getExcludedEvents(), monitor
);
201 // Enable syscall events
202 if (dialog
.isSyscalls()) {
203 // Enable all syscall events
204 if (dialog
.isAllSyscalls()) {
205 enableSyscalls(param
, ILttngControlService
.ALL_EVENTS
, monitor
);
207 List
<String
> syscallNames
= dialog
.getEventNames();
208 if (!syscallNames
.isEmpty()) {
209 enableSyscalls(param
, syscallNames
, monitor
);
214 // Enable dynamic probe
215 if (dialog
.isDynamicProbe() && (dialog
.getProbeEventName() != null) && (dialog
.getProbeName() != null)) {
216 enableProbe(param
, dialog
.getProbeEventName(), false, dialog
.getProbeName(), monitor
);
219 // Enable dynamic function probe
220 if (dialog
.isDynamicFunctionProbe() && (dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
221 enableProbe(param
, dialog
.getFunctionEventName(), true, dialog
.getFunction(), monitor
);
224 // Enable event using a wildcard
225 if (dialog
.isWildcard()) {
226 eventNames
= dialog
.getEventNames();
227 eventNames
.add(dialog
.getWildcard());
229 if (!eventNames
.isEmpty()) {
230 enableEvents(param
, eventNames
, dialog
.getDomain(), filter
, dialog
.getExcludedEvents(), monitor
);
234 // Enable events using log level
235 if (dialog
.isLogLevel()) {
236 enableLogLevel(param
, dialog
.getEventNames(), dialog
.getLogLevelType(), dialog
.getLogLevel(), filter
, dialog
.getDomain(), monitor
);
241 eventNames
= dialog
.getEventNames();
242 if (dialog
.isAllEvents()) {
245 if (dialog
.isLogLevel()) {
246 enableLogLevel(param
, eventNames
, dialog
.getLogLevelType(), dialog
.getLogLevel(), filter
, dialog
.getDomain(), monitor
);
248 enableEvents(param
, eventNames
, dialog
.getDomain(), filter
, dialog
.getExcludedEvents(), monitor
);
255 } catch (ExecutionException e
) {
259 // refresh in all cases
263 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ChangeEventStateFailure
, error
);
265 return Status
.OK_STATUS
;