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 switch (dialog
.getDomain()) {
186 if (dialog
.isAllEvents()) {
187 enableEvents(param
, null, dialog
.getDomain(), filter
, dialog
.getExcludedEvents(), monitor
);
188 } else if (dialog
.isTracepoints()) {
189 // Enable tracepoint events
190 if (dialog
.isAllTracePoints()) {
191 enableEvents(param
, null, dialog
.getDomain(), filter
, dialog
.getExcludedEvents(), monitor
);
193 List
<String
> eventNames
= dialog
.getEventNames();
194 if (!eventNames
.isEmpty()) {
195 enableEvents(param
, eventNames
, dialog
.getDomain(), filter
, dialog
.getExcludedEvents(), monitor
);
200 // Enable syscall events
201 if (dialog
.isSyscalls()) {
202 // Enable all syscall events
203 if (dialog
.isAllSyscalls()) {
204 enableSyscalls(param
, ILttngControlService
.ALL_EVENTS
, monitor
);
206 List
<String
> syscallNames
= dialog
.getEventNames();
207 if (!syscallNames
.isEmpty()) {
208 enableSyscalls(param
, syscallNames
, monitor
);
213 // Enable dynamic probe
214 if (dialog
.isDynamicProbe() && (dialog
.getProbeEventName() != null) && (dialog
.getProbeName() != null)) {
215 enableProbe(param
, dialog
.getProbeEventName(), false, dialog
.getProbeName(), monitor
);
218 // Enable dynamic function probe
219 if (dialog
.isDynamicFunctionProbe() && (dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
220 enableProbe(param
, dialog
.getFunctionEventName(), true, dialog
.getFunction(), monitor
);
223 // Enable event using a wildcard
224 if (dialog
.isWildcard()) {
225 List
<String
> eventNames
= dialog
.getEventNames();
226 eventNames
.add(dialog
.getWildcard());
228 if (!eventNames
.isEmpty()) {
229 enableEvents(param
, eventNames
, dialog
.getDomain(), filter
, dialog
.getExcludedEvents(), monitor
);
233 // Enable events using log level
234 if (dialog
.isLogLevel()) {
235 enableLogLevel(param
, dialog
.getEventNames(), dialog
.getLogLevelType(), dialog
.getLogLevel(), filter
, dialog
.getDomain(), monitor
);
239 List
<String
> eventNames
= dialog
.getEventNames();
240 if (dialog
.isAllTracePoints()) {
243 if (dialog
.isLogLevel()) {
244 enableLogLevel(param
, eventNames
, dialog
.getLogLevelType(), dialog
.getLogLevel(), filter
, dialog
.getDomain(), monitor
);
246 enableEvents(param
, eventNames
, dialog
.getDomain(), filter
, dialog
.getExcludedEvents(), monitor
);
254 } catch (ExecutionException e
) {
258 // refresh in all cases
262 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ChangeEventStateFailure
, error
);
264 return Status
.OK_STATUS
;