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
.LogLevelType
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.IEnableEventsDialog
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceDomainComponent
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceProviderGroup
;
35 import org
.eclipse
.ui
.IWorkbenchWindow
;
36 import org
.eclipse
.ui
.PlatformUI
;
40 * Base command handler implementation to enable events.
43 * @author Bernd Hufmann
45 public abstract class BaseEnableEventHandler
extends BaseControlViewHandler
{
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
51 * The command execution parameter.
53 @Nullable protected CommandParameter fParam
= null;
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 * Enables a list of events for given parameters.
63 * - a parameter instance with data for the command execution
65 * - list of event names
67 * - true if kernel domain else false
68 * @param filterExpression
69 * - a filter expression
71 * - a progress monitor
72 * @throws ExecutionException
73 * If the command fails for some reason
75 public abstract void enableEvents(CommandParameter param
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
;
78 * Enables all syscall events.
81 * - a parameter instance with data for the command execution
83 * - a progress monitor
84 * @throws ExecutionException
85 * If the command fails for some reason
87 public abstract void enableSyscalls(CommandParameter param
, IProgressMonitor monitor
) throws ExecutionException
;
90 * Enables a dynamic probe.
93 * - a parameter instance with data for the command execution
97 * - true for dynamic function entry/return probe else false
99 * - a dynamic probe information
101 * - a progress monitor
102 * @throws ExecutionException
103 * If the command fails for some reason
105 public abstract void enableProbe(CommandParameter param
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
108 * Enables events using log level
111 * - a parameter instance with data for the command execution
114 * @param logLevelType
118 * @param filterExpression
119 * - a filter expression
121 * - a progress monitor
122 * @throws ExecutionException
123 * If the command fails for some reason
125 public abstract void enableLogLevel(CommandParameter param
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
;
129 * - a parameter instance with data for the command execution
130 * @return returns the relevant domain (null if domain is not known)
132 public abstract TraceDomainComponent
getDomain(CommandParameter param
);
135 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
137 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
139 if (window
== null) {
143 // Make a copy for thread safety
144 CommandParameter tmpParam
= null;
148 if (tmpParam
== null) {
151 tmpParam
= tmpParam
.clone();
155 final CommandParameter param
= tmpParam
;
157 TargetNodeComponent node
= param
.getSession().getTargetNode();
158 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
160 final IEnableEventsDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableEventsDialog();
161 dialog
.setTraceProviderGroup((TraceProviderGroup
)providers
.get(0));
162 dialog
.setTraceDomainComponent(getDomain(param
));
164 if (dialog
.open() != Window
.OK
) {
168 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
170 protected IStatus
run(IProgressMonitor monitor
) {
171 Exception error
= null;
174 String filter
= dialog
.getFilterExpression();
176 // Enable tracepoint events
177 if (dialog
.isTracepoints()) {
178 if (dialog
.isAllTracePoints()) {
179 enableEvents(param
, null, dialog
.isKernel(), filter
, monitor
);
181 List
<String
> eventNames
= dialog
.getEventNames();
182 if (!eventNames
.isEmpty()) {
183 enableEvents(param
, eventNames
, dialog
.isKernel(), filter
, monitor
);
188 // Enable syscall events
189 if (dialog
.isAllSysCalls()) {
190 enableSyscalls(param
, monitor
);
193 // Enable dynamic probe
194 if (dialog
.isDynamicProbe() && (dialog
.getProbeEventName() != null) && (dialog
.getProbeName() != null)) {
195 enableProbe(param
, dialog
.getProbeEventName(), false, dialog
.getProbeName(), monitor
);
198 // Enable dynamic function probe
199 if (dialog
.isDynamicFunctionProbe() && (dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
200 enableProbe(param
, dialog
.getFunctionEventName(), true, dialog
.getFunction(), monitor
);
203 // Enable event using a wildcard
204 if (dialog
.isWildcard()) {
205 List
<String
> eventNames
= dialog
.getEventNames();
206 eventNames
.add(dialog
.getWildcard());
208 if (!eventNames
.isEmpty()) {
209 enableEvents(param
, eventNames
, dialog
.isKernel(), filter
, monitor
);
213 // Enable events using log level
214 if (dialog
.isLogLevel()) {
215 enableLogLevel(param
, dialog
.getLogLevelEventName(), dialog
.getLogLevelType(), dialog
.getLogLevel(), filter
, monitor
);
218 } catch (ExecutionException e
) {
222 // refresh in all cases
226 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ChangeEventStateFailure
, error
);
228 return Status
.OK_STATUS
;