lttng.control: Add support for enabling syscall by name
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / model / impl / TraceChannelComponent.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
3 *
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
8 *
9 * Contributors:
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.model.impl;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.swt.graphics.Image;
21 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType;
22 import org.eclipse.tracecompass.internal.lttng2.control.core.model.IChannelInfo;
23 import org.eclipse.tracecompass.internal.lttng2.control.core.model.IEventInfo;
24 import org.eclipse.tracecompass.internal.lttng2.control.core.model.ITraceLogLevel;
25 import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType;
26 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceChannelOutputType;
27 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEnablement;
28 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.ChannelInfo;
29 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.ProbeEventInfo;
30 import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
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.property.TraceChannelPropertySource;
34 import org.eclipse.ui.views.properties.IPropertySource;
35
36
37 /**
38 * <p>
39 * Implementation of the trace channel component.
40 * </p>
41 *
42 * @author Bernd Hufmann
43 */
44 public class TraceChannelComponent extends TraceControlComponent {
45
46 // ------------------------------------------------------------------------
47 // Constants
48 // ------------------------------------------------------------------------
49
50 /**
51 * Path to icon file for this component (state enabled).
52 */
53 public static final String TRACE_CHANNEL_ICON_FILE_ENABLED = "icons/obj16/channel.gif"; //$NON-NLS-1$
54 /**
55 * Path to icon file for this component (state disabled).
56 */
57 public static final String TRACE_CHANNEL_ICON_FILE_DISABLED = "icons/obj16/channel_disabled.gif"; //$NON-NLS-1$
58
59 // ------------------------------------------------------------------------
60 // Attributes
61 // ------------------------------------------------------------------------
62
63 /**
64 * The channel information.
65 */
66 private IChannelInfo fChannelInfo = null;
67 /**
68 * The image to be displayed in disabled state.
69 */
70 private Image fDisabledImage = null;
71
72 // ------------------------------------------------------------------------
73 // Constructors
74 // ------------------------------------------------------------------------
75
76 /**
77 * Constructor
78 * @param name - the name of the component.
79 * @param parent - the parent of this component.
80 */
81 public TraceChannelComponent(String name, ITraceControlComponent parent) {
82 super(name, parent);
83 setImage(TRACE_CHANNEL_ICON_FILE_ENABLED);
84 setToolTip(Messages.TraceControl_ChannelDisplayName);
85 fChannelInfo = new ChannelInfo(name);
86 fDisabledImage = Activator.getDefault().loadIcon(TRACE_CHANNEL_ICON_FILE_DISABLED);
87 }
88
89 // ------------------------------------------------------------------------
90 // Accessors
91 // ------------------------------------------------------------------------
92
93 @Override
94 public Image getImage() {
95 if (fChannelInfo.getState() == TraceEnablement.DISABLED) {
96 return fDisabledImage;
97 }
98 return super.getImage();
99 }
100
101 /**
102 * Sets the channel information.
103 *
104 * @param channelInfo
105 * The channel info to assign to this component
106 */
107 public void setChannelInfo(IChannelInfo channelInfo) {
108 fChannelInfo = channelInfo;
109 IEventInfo[] events = fChannelInfo.getEvents();
110 List<ITraceControlComponent> eventComponents = new ArrayList<>();
111 for (int i = 0; i < events.length; i++) {
112 TraceEventComponent event = null;
113 if (events[i].getClass() == ProbeEventInfo.class) {
114 event = new TraceProbeEventComponent(events[i].getName(), this);
115 } else {
116 event = new TraceEventComponent(events[i].getName(), this);
117 }
118
119 eventComponents.add(event);
120 event.setEventInfo(events[i]);
121 }
122 if (!eventComponents.isEmpty()) {
123 setChildren(eventComponents);
124 }
125 }
126
127 /**
128 * @return the overwrite mode value.
129 */
130 public boolean isOverwriteMode() {
131 return fChannelInfo.isOverwriteMode();
132 }
133 /**
134 * Sets the overwrite mode value to the given mode.
135 * @param mode - mode to set.
136 */
137 public void setOverwriteMode(boolean mode){
138 fChannelInfo.setOverwriteMode(mode);
139 }
140 /**
141 * @return the sub-buffer size.
142 */
143 public long getSubBufferSize() {
144 return fChannelInfo.getSubBufferSize();
145 }
146 /**
147 * Sets the sub-buffer size to the given value.
148 * @param bufferSize - size to set to set.
149 */
150 public void setSubBufferSize(long bufferSize) {
151 fChannelInfo.setSubBufferSize(bufferSize);
152 }
153 /**
154 * @return the number of sub-buffers.
155 */
156 public int getNumberOfSubBuffers() {
157 return fChannelInfo.getNumberOfSubBuffers();
158 }
159 /**
160 * Sets the number of sub-buffers to the given value.
161 * @param numberOfSubBuffers - value to set.
162 */
163 public void setNumberOfSubBuffers(int numberOfSubBuffers) {
164 fChannelInfo.setNumberOfSubBuffers(numberOfSubBuffers);
165 }
166 /**
167 * @return the switch timer interval.
168 */
169 public long getSwitchTimer() {
170 return fChannelInfo.getSwitchTimer();
171 }
172 /**
173 * Sets the switch timer interval to the given value.
174 * @param timer - timer value to set.
175 */
176 public void setSwitchTimer(long timer) {
177 fChannelInfo.setSwitchTimer(timer);
178 }
179 /**
180 * @return the read timer interval.
181 */
182 public long getReadTimer() {
183 return fChannelInfo.getReadTimer();
184 }
185 /**
186 * Sets the read timer interval to the given value.
187 * @param timer - timer value to set..
188 */
189 public void setReadTimer(long timer) {
190 fChannelInfo.setReadTimer(timer);
191 }
192 /**
193 * @return the output type.
194 */
195 public TraceChannelOutputType getOutputType() {
196 return fChannelInfo.getOutputType();
197 }
198 /**
199 * Sets the output type to the given value.
200 * @param type - type to set.
201 */
202 public void setOutputType(TraceChannelOutputType type) {
203 fChannelInfo.setOutputType(type);
204 }
205 /**
206 * Sets the output type to the given value.
207 * @param type - type to set.
208 */
209 public void setOutputType(String type) {
210 fChannelInfo.setOutputType(type);
211 }
212
213 /**
214 * @return the channel state (enabled or disabled).
215 */
216 public TraceEnablement getState() {
217 return fChannelInfo.getState();
218 }
219 /**
220 * Sets the channel state (enablement) to the given value.
221 * @param state - state to set.
222 */
223 public void setState(TraceEnablement state) {
224 fChannelInfo.setState(state);
225 }
226 /**
227 * Sets the channel state (enablement) to the value specified by the given name.
228 * @param stateName - state to set.
229 */
230 public void setState(String stateName) {
231 fChannelInfo.setState(stateName);
232 }
233
234 /**
235 * @return number of discarded events
236 */
237 public long getNumberOfDiscardedEvents() {
238 return fChannelInfo.getNumberOfDiscardedEvents();
239 }
240 /**
241 * @return number of lost packets
242 */
243 public long getNumberOfLostPackets() {
244 return fChannelInfo.getNumberOfLostPackets();
245 }
246
247 /**
248 * @return maximum size of trace files
249 */
250 public long getMaxSizeTraceFiles() {
251 return fChannelInfo.getMaxSizeTraceFiles();
252 }
253 /**
254 * @return maximum number of trace files
255 */
256 public int getMaxNumberTraceFiles() {
257 return fChannelInfo.getMaxNumberTraceFiles();
258 }
259
260 @Override
261 public <T> T getAdapter(Class<T> adapter) {
262 if (adapter == IPropertySource.class) {
263 return adapter.cast(new TraceChannelPropertySource(this));
264 }
265 return null;
266 }
267
268 /**
269 * @return session name from parent
270 */
271 public String getSessionName() {
272 return ((TraceDomainComponent)getParent()).getSessionName();
273 }
274
275 /**
276 * @return session from parent
277 */
278 public TraceSessionComponent getSession() {
279 return ((TraceDomainComponent)getParent()).getSession();
280 }
281
282 /**
283 * @return the domain type ({@link TraceDomainType})
284 */
285 public TraceDomainType getDomain() {
286 return ((TraceDomainComponent)getParent()).getDomain();
287 }
288
289 /**
290 * @return the parent target node
291 */
292 public TargetNodeComponent getTargetNode() {
293 return ((TraceDomainComponent)getParent()).getTargetNode();
294 }
295
296 // ------------------------------------------------------------------------
297 // Operations
298 // ------------------------------------------------------------------------
299
300 /**
301 * Enables a list of events with no additional parameters.
302 *
303 * @param eventNames
304 * - a list of event names to enabled.
305 * @param monitor
306 * - a progress monitor
307 * @throws ExecutionException
308 * If the command fails
309 */
310 public void enableEvents(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException {
311 enableEvents(eventNames, null, null, monitor);
312 }
313
314 /**
315 * Enables a list of events with no additional parameters.
316 *
317 * @param eventNames
318 * - a list of event names to enabled.
319 * @param filterExpression
320 * - a filter expression
321 * @param excludedEvents
322 * - a list of events to exclude.
323 * @param monitor
324 * - a progress monitor
325 * @throws ExecutionException
326 * If the command fails
327 */
328 public void enableEvents(List<String> eventNames, String filterExpression, List<String> excludedEvents, IProgressMonitor monitor) throws ExecutionException {
329 getControlService().enableEvents(getSessionName(), getName(), eventNames, getDomain(), filterExpression, excludedEvents, monitor);
330 }
331
332 /**
333 * Enables all syscalls (for kernel domain)
334 *
335 * @param syscallNames
336 * - a list of syscall to enable
337 * @param monitor
338 * - a progress monitor
339 * @throws ExecutionException
340 * If the command fails
341 */
342 public void enableSyscalls(List<String> syscallNames, IProgressMonitor monitor) throws ExecutionException {
343 getControlService().enableSyscalls(getSessionName(), getName(), syscallNames, monitor);
344 }
345
346 /**
347 * Enables a dynamic probe (for kernel domain)
348 *
349 * @param eventName
350 * - event name for probe
351 * @param isFunction
352 * - true for dynamic function entry/return probe else false
353 * @param probe
354 * - the actual probe
355 * @param monitor
356 * - a progress monitor
357 * @throws ExecutionException
358 * If the command fails
359 */
360 public void enableProbe(String eventName, boolean isFunction, String probe,
361 IProgressMonitor monitor) throws ExecutionException {
362 getControlService().enableProbe(getSessionName(), getName(), eventName, isFunction, probe, monitor);
363 }
364
365 /**
366 * Enables events using log level.
367 *
368 * @param eventNames
369 * - a list of event names
370 * @param logLevelType
371 * - a log level type
372 * @param level
373 * - a log level
374 * @param filterExpression
375 * - a filter expression
376 * @param domain
377 * - the domain type ({@link TraceDomainType})
378 * @param monitor
379 * - a progress monitor
380 * @throws ExecutionException
381 * If the command fails
382 */
383 public void enableLogLevel(List<String> eventNames, LogLevelType logLevelType,
384 ITraceLogLevel level, String filterExpression, TraceDomainType domain, IProgressMonitor monitor)
385 throws ExecutionException {
386 getControlService().enableLogLevel(getSessionName(), getName(), eventNames, logLevelType, level, filterExpression, domain, monitor);
387 }
388
389 /**
390 * Enables a list of events with no additional parameters.
391 *
392 * @param eventNames
393 * - a list of event names to enabled.
394 * @param monitor
395 * - a progress monitor
396 * @throws ExecutionException
397 * If the command fails
398 */
399 public void disableEvent(List<String> eventNames, IProgressMonitor monitor)
400 throws ExecutionException {
401 getControlService().disableEvent(getParent().getParent().getName(),
402 getName(), eventNames, getDomain(), monitor);
403 }
404
405 /**
406 * Add contexts to given channels and or events
407 *
408 * @param contexts
409 * - a list of contexts to add
410 * @param monitor
411 * - a progress monitor
412 * @throws ExecutionException
413 * If the command fails
414 */
415 public void addContexts(List<String> contexts, IProgressMonitor monitor)
416 throws ExecutionException {
417 getControlService().addContexts(getSessionName(), getName(), null,
418 getDomain(), contexts, monitor);
419 }
420 }
This page took 0.041694 seconds and 5 git commands to generate.