lttng.ust: Replace timestamp.getValue() with toNanos()
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / handlers / BaseEnableEventHandler.java
CommitLineData
498704b3 1/**********************************************************************
68d1057b 2 * Copyright (c) 2012, 2015 Ericsson
cfdb727a 3 *
498704b3
BH
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
cfdb727a
AM
8 *
9 * Contributors:
498704b3 10 * Bernd Hufmann - Initial API and implementation
ba3a9bd2 11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
498704b3 12 **********************************************************************/
9bc60be7 13package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers;
498704b3
BH
14
15import java.util.List;
16
17import org.eclipse.core.commands.ExecutionEvent;
18import org.eclipse.core.commands.ExecutionException;
19import org.eclipse.core.runtime.IProgressMonitor;
20import org.eclipse.core.runtime.IStatus;
21import org.eclipse.core.runtime.Status;
22import org.eclipse.core.runtime.jobs.Job;
68d1057b 23import org.eclipse.jdt.annotation.Nullable;
498704b3 24import org.eclipse.jface.window.Window;
9bc60be7
AM
25import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType;
26import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel;
27import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
28import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.IEnableEventsDialog;
29import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
30import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
31import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
32import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
33import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
34import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceProviderGroup;
9ee91a86 35import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.ILttngControlService;
498704b3
BH
36import org.eclipse.ui.IWorkbenchWindow;
37import org.eclipse.ui.PlatformUI;
38
39/**
498704b3 40 * <p>
ccc66d01 41 * Base command handler implementation to enable events.
498704b3 42 * </p>
cfdb727a 43 *
dbd4432d 44 * @author Bernd Hufmann
498704b3 45 */
77735e82 46public abstract class BaseEnableEventHandler extends BaseControlViewHandler {
498704b3
BH
47
48 // ------------------------------------------------------------------------
49 // Attributes
50 // ------------------------------------------------------------------------
51 /**
c56972bb 52 * The command execution parameter.
498704b3 53 */
9ee91a86
BH
54 @Nullable
55 protected CommandParameter fParam = null;
498704b3
BH
56
57 // ------------------------------------------------------------------------
58 // Operations
59 // ------------------------------------------------------------------------
cfdb727a 60
ccc66d01
BH
61 /**
62 * Enables a list of events for given parameters.
cfdb727a
AM
63 *
64 * @param param
65 * - a parameter instance with data for the command execution
66 * @param eventNames
67 * - list of event names
68 * @param isKernel
69 * - true if kernel domain else false
d4514365
BH
70 * @param filterExpression
71 * - a filter expression
91dc1c3e
BR
72 * @param excludedEvents
73 * - list of events to exclude
cfdb727a
AM
74 * @param monitor
75 * - a progress monitor
ccc66d01 76 * @throws ExecutionException
cfdb727a 77 * If the command fails for some reason
ccc66d01 78 */
91dc1c3e 79 public abstract void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExpression, List<String> excludedEvents, IProgressMonitor monitor) throws ExecutionException;
c56972bb 80
ccc66d01
BH
81 /**
82 * Enables all syscall events.
cfdb727a
AM
83 *
84 * @param param
85 * - a parameter instance with data for the command execution
86 * @param monitor
87 * - a progress monitor
ccc66d01 88 * @throws ExecutionException
cfdb727a 89 * If the command fails for some reason
ccc66d01 90 */
77735e82 91 public abstract void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException;
cfdb727a 92
ccc66d01
BH
93 /**
94 * Enables a dynamic probe.
cfdb727a
AM
95 *
96 * @param param
97 * - a parameter instance with data for the command execution
98 * @param eventName
99 * - a event name
100 * @param isFunction
101 * - true for dynamic function entry/return probe else false
102 * @param probe
103 * - a dynamic probe information
104 * @param monitor
105 * - a progress monitor
ccc66d01 106 * @throws ExecutionException
cfdb727a 107 * If the command fails for some reason
ccc66d01 108 */
77735e82 109 public abstract void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException;
cfdb727a 110
ccc66d01
BH
111 /**
112 * Enables events using log level
cfdb727a
AM
113 *
114 * @param param
115 * - a parameter instance with data for the command execution
116 * @param eventName
117 * - a event name
118 * @param logLevelType
119 * - a log level type
120 * @param level
121 * - a log level
d4514365
BH
122 * @param filterExpression
123 * - a filter expression
cfdb727a
AM
124 * @param monitor
125 * - a progress monitor
ccc66d01 126 * @throws ExecutionException
cfdb727a
AM
127 * If the command fails for some reason
128 */
77735e82 129 public abstract void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException;
cfdb727a 130
ccc66d01 131 /**
cfdb727a
AM
132 * @param param
133 * - a parameter instance with data for the command execution
ccc66d01
BH
134 * @return returns the relevant domain (null if domain is not known)
135 */
77735e82 136 public abstract TraceDomainComponent getDomain(CommandParameter param);
ccc66d01 137
498704b3
BH
138 @Override
139 public Object execute(ExecutionEvent event) throws ExecutionException {
140
141 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
142
143 if (window == null) {
144 return false;
145 }
68d1057b
BH
146
147 // Make a copy for thread safety
148 CommandParameter tmpParam = null;
c56972bb
BH
149 fLock.lock();
150 try {
68d1057b
BH
151 tmpParam = fParam;
152 if (tmpParam == null) {
c56972bb
BH
153 return null;
154 }
b8dbc09c 155 tmpParam = tmpParam.clone();
68d1057b
BH
156 } finally {
157 fLock.unlock();
158 }
159 final CommandParameter param = tmpParam;
498704b3 160
68d1057b
BH
161 TargetNodeComponent node = param.getSession().getTargetNode();
162 List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class);
ccc66d01 163
68d1057b 164 final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog();
9ee91a86 165 dialog.setTraceProviderGroup((TraceProviderGroup) providers.get(0));
68d1057b 166 dialog.setTraceDomainComponent(getDomain(param));
ccc66d01 167
68d1057b
BH
168 if (dialog.open() != Window.OK) {
169 return null;
170 }
ccc66d01 171
68d1057b
BH
172 Job job = new Job(Messages.TraceControl_ChangeEventStateJob) {
173 @Override
174 protected IStatus run(IProgressMonitor monitor) {
175 Exception error = null;
ccc66d01 176
68d1057b
BH
177 try {
178 String filter = dialog.getFilterExpression();
9ee91a86 179 if (dialog.isAllEvents()) {
91dc1c3e 180 enableEvents(param, ILttngControlService.ALL_EVENTS, dialog.isKernel(), filter, dialog.getExcludedEvents(), monitor);
9ee91a86
BH
181 } else if (dialog.isTracepoints()) {
182 // Enable tracepoint events
68d1057b 183 if (dialog.isAllTracePoints()) {
91dc1c3e 184 enableEvents(param, null, dialog.isKernel(), filter, dialog.getExcludedEvents(), monitor);
68d1057b
BH
185 } else {
186 List<String> eventNames = dialog.getEventNames();
c56972bb 187 if (!eventNames.isEmpty()) {
91dc1c3e 188 enableEvents(param, eventNames, dialog.isKernel(), filter, dialog.getExcludedEvents(), monitor);
c56972bb 189 }
498704b3 190 }
68d1057b 191 }
c56972bb 192
68d1057b
BH
193 // Enable syscall events
194 if (dialog.isAllSysCalls()) {
195 enableSyscalls(param, monitor);
196 }
197
198 // Enable dynamic probe
199 if (dialog.isDynamicProbe() && (dialog.getProbeEventName() != null) && (dialog.getProbeName() != null)) {
200 enableProbe(param, dialog.getProbeEventName(), false, dialog.getProbeName(), monitor);
201 }
c56972bb 202
68d1057b
BH
203 // Enable dynamic function probe
204 if (dialog.isDynamicFunctionProbe() && (dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) {
205 enableProbe(param, dialog.getFunctionEventName(), true, dialog.getFunction(), monitor);
ccc66d01 206 }
498704b3 207
68d1057b
BH
208 // Enable event using a wildcard
209 if (dialog.isWildcard()) {
210 List<String> eventNames = dialog.getEventNames();
211 eventNames.add(dialog.getWildcard());
498704b3 212
68d1057b 213 if (!eventNames.isEmpty()) {
91dc1c3e 214 enableEvents(param, eventNames, dialog.isKernel(), filter, dialog.getExcludedEvents(), monitor);
68d1057b
BH
215 }
216 }
217
218 // Enable events using log level
219 if (dialog.isLogLevel()) {
220 enableLogLevel(param, dialog.getLogLevelEventName(), dialog.getLogLevelType(), dialog.getLogLevel(), filter, monitor);
498704b3 221 }
68d1057b
BH
222
223 } catch (ExecutionException e) {
224 error = e;
498704b3 225 }
68d1057b
BH
226
227 // refresh in all cases
228 refresh(param);
229
230 if (error != null) {
231 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeEventStateFailure, error);
232 }
233 return Status.OK_STATUS;
234 }
235 };
236 job.setUser(true);
237 job.schedule();
498704b3
BH
238 return null;
239 }
240}
This page took 0.099248 seconds and 5 git commands to generate.