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
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.ILttngControlService
;
36 import org
.eclipse
.ui
.IWorkbenchWindow
;
37 import org
.eclipse
.ui
.PlatformUI
;
41 * Base command handler implementation to enable events.
44 * @author Bernd Hufmann
46 public abstract class BaseEnableEventHandler
extends BaseControlViewHandler
{
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 * The command execution parameter.
55 protected CommandParameter fParam
= null;
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
62 * Enables a list of events for given parameters.
65 * - a parameter instance with data for the command execution
67 * - list of event names
69 * - true if kernel domain else false
70 * @param filterExpression
71 * - a filter expression
73 * - a progress monitor
74 * @throws ExecutionException
75 * If the command fails for some reason
77 public abstract void enableEvents(CommandParameter param
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
;
80 * Enables all syscall events.
83 * - a parameter instance with data for the command execution
85 * - a progress monitor
86 * @throws ExecutionException
87 * If the command fails for some reason
89 public abstract void enableSyscalls(CommandParameter param
, IProgressMonitor monitor
) throws ExecutionException
;
92 * Enables a dynamic probe.
95 * - a parameter instance with data for the command execution
99 * - true for dynamic function entry/return probe else false
101 * - a dynamic probe information
103 * - a progress monitor
104 * @throws ExecutionException
105 * If the command fails for some reason
107 public abstract void enableProbe(CommandParameter param
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
110 * Enables events using log level
113 * - a parameter instance with data for the command execution
116 * @param logLevelType
120 * @param filterExpression
121 * - a filter expression
123 * - a progress monitor
124 * @throws ExecutionException
125 * If the command fails for some reason
127 public abstract void enableLogLevel(CommandParameter param
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
;
131 * - a parameter instance with data for the command execution
132 * @return returns the relevant domain (null if domain is not known)
134 public abstract TraceDomainComponent
getDomain(CommandParameter param
);
137 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
139 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
141 if (window
== null) {
145 // Make a copy for thread safety
146 CommandParameter tmpParam
= null;
150 if (tmpParam
== null) {
153 tmpParam
= tmpParam
.clone();
157 final CommandParameter param
= tmpParam
;
159 TargetNodeComponent node
= param
.getSession().getTargetNode();
160 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
162 final IEnableEventsDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableEventsDialog();
163 dialog
.setTraceProviderGroup((TraceProviderGroup
) providers
.get(0));
164 dialog
.setTraceDomainComponent(getDomain(param
));
166 if (dialog
.open() != Window
.OK
) {
170 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
172 protected IStatus
run(IProgressMonitor monitor
) {
173 Exception error
= null;
176 String filter
= dialog
.getFilterExpression();
177 if (dialog
.isAllEvents()) {
178 enableEvents(param
, ILttngControlService
.ALL_EVENTS
, dialog
.isKernel(), filter
, monitor
);
179 } else if (dialog
.isTracepoints()) {
180 // Enable tracepoint events
181 if (dialog
.isAllTracePoints()) {
182 enableEvents(param
, null, dialog
.isKernel(), filter
, monitor
);
184 List
<String
> eventNames
= dialog
.getEventNames();
185 if (!eventNames
.isEmpty()) {
186 enableEvents(param
, eventNames
, dialog
.isKernel(), filter
, monitor
);
191 // Enable syscall events
192 if (dialog
.isAllSysCalls()) {
193 enableSyscalls(param
, monitor
);
196 // Enable dynamic probe
197 if (dialog
.isDynamicProbe() && (dialog
.getProbeEventName() != null) && (dialog
.getProbeName() != null)) {
198 enableProbe(param
, dialog
.getProbeEventName(), false, dialog
.getProbeName(), monitor
);
201 // Enable dynamic function probe
202 if (dialog
.isDynamicFunctionProbe() && (dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
203 enableProbe(param
, dialog
.getFunctionEventName(), true, dialog
.getFunction(), monitor
);
206 // Enable event using a wildcard
207 if (dialog
.isWildcard()) {
208 List
<String
> eventNames
= dialog
.getEventNames();
209 eventNames
.add(dialog
.getWildcard());
211 if (!eventNames
.isEmpty()) {
212 enableEvents(param
, eventNames
, dialog
.isKernel(), filter
, monitor
);
216 // Enable events using log level
217 if (dialog
.isLogLevel()) {
218 enableLogLevel(param
, dialog
.getLogLevelEventName(), dialog
.getLogLevelType(), dialog
.getLogLevel(), filter
, monitor
);
221 } catch (ExecutionException e
) {
225 // refresh in all cases
229 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ChangeEventStateFailure
, error
);
231 return Status
.OK_STATUS
;