1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
;
14 import java
.util
.ArrayList
;
15 import java
.util
.List
;
17 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
18 import org
.eclipse
.jface
.viewers
.CheckStateChangedEvent
;
19 import org
.eclipse
.jface
.viewers
.CheckboxTreeViewer
;
20 import org
.eclipse
.jface
.viewers
.ICheckStateListener
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.BaseEventComponent
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.KernelProviderComponent
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceControlContentProvider
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceControlLabelProvider
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceProviderGroup
;
28 import org
.eclipse
.swt
.SWT
;
29 import org
.eclipse
.swt
.events
.SelectionAdapter
;
30 import org
.eclipse
.swt
.events
.SelectionEvent
;
31 import org
.eclipse
.swt
.graphics
.Image
;
32 import org
.eclipse
.swt
.layout
.GridData
;
33 import org
.eclipse
.swt
.layout
.GridLayout
;
34 import org
.eclipse
.swt
.widgets
.Button
;
35 import org
.eclipse
.swt
.widgets
.Composite
;
36 import org
.eclipse
.swt
.widgets
.Group
;
37 import org
.eclipse
.swt
.widgets
.Label
;
38 import org
.eclipse
.swt
.widgets
.Text
;
42 * A composite for collecting information about kernel events to be enabled.
45 * @author Bernd Hufmann
47 public class EnableKernelEventComposite
extends Composite
implements IEnableKernelEvents
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
52 private enum KernelGroupEnum
{ TRACEPOINTS
, SYSCALLS
, PROBE
, FUNCTION
}
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
59 * A button to enable/disable the tracepoints group
61 private Button fTracepointsActivateButton
;
63 * A tree viewer for displaying and selection of available tracepoints.
65 private CheckboxTreeViewer fTracepointsViewer
;
67 * A button to enable/disable the syscalls group
69 private Button fSysCallsActivateButton
;
71 * A button to enable or disable the dynamic probe group.
73 private Button fProbeActivateButton
;
75 * The text field for the event name for the dynamic probe.
77 private Text fProbeEventNameText
;
79 * The text field for the dynamic probe.
81 private Text fProbeText
;
83 * A button to enable or disable the dynamic function probe group.
85 private Button fFunctionActivateButton
;
87 * The text field for the event name for the dynamic probe.
89 private Text fFunctionEventNameText
;
91 * The text field for the dynamic function entry/return probe.
93 private Text fFunctionText
;
95 * The referenced trace provider group containing the kernel provider
96 * component which contains a list of available tracepoints.
98 private final TraceProviderGroup fProviderGroup
;
100 * The flag indicating that tracepoints are selected.
102 private boolean fIsTracepoints
;
104 * The flag indicating that all tracepoints are selected.
106 private boolean fIsAllTracepoints
;
108 * The flag indicating that syscalls are selected.
110 private boolean fIsSysCalls
;
112 * The list of tracepoints to be enabled.
114 private List
<String
> fSelectedEvents
;
116 * The flag indicating that dynamic probe is selected.
118 private boolean fIsDynamicProbe
;
120 * The event name of the dynamic probe.
122 private String fProbeEventName
;
126 private String fProbeString
;
128 * The flag indicating that the dynamic function probe is selected.
130 private boolean fIsDynamicFunctionProbe
;
132 * The event name of the dynamic function entry/return probe.
134 private String fFunctionEventName
;
136 * The dynamic function entry/return probe.
138 private String fFunctionString
;
140 // ------------------------------------------------------------------------
142 // ------------------------------------------------------------------------
148 * The parent composite
150 * The index of the style for this event composite
151 * @param providerGroup
152 * The trace provider group
154 public EnableKernelEventComposite(Composite parent
, int style
, TraceProviderGroup providerGroup
) {
155 super(parent
, style
);
156 fProviderGroup
= providerGroup
;
159 // ------------------------------------------------------------------------
161 // ------------------------------------------------------------------------
164 public boolean isTracepoints() {
165 return fIsTracepoints
;
169 public boolean isAllTracePoints() {
170 return fIsAllTracepoints
;
174 public boolean isSysCalls() {
179 public boolean isAllSysCalls() {
184 public List
<String
> getEventNames() {
185 return new ArrayList
<String
>(fSelectedEvents
);
189 public boolean isDynamicProbe() {
190 return fIsDynamicProbe
;
194 public String
getProbeName() {
199 public String
getProbeEventName() {
200 return fProbeEventName
;
204 public boolean isDynamicFunctionProbe() {
205 return fIsDynamicFunctionProbe
;
209 public String
getFunctionEventName() {
210 return fFunctionEventName
;
214 public String
getFunction() {
215 return fFunctionString
;
218 // ------------------------------------------------------------------------
220 // ------------------------------------------------------------------------
223 * Creates the composite content
225 public void createContent() {
228 createTracepointsGroup();
231 createSysCallsGroup();
233 // Dynamic Probe Group
234 createDynamicProbeGroup();
236 // Dynamic Function Probe Group
237 createDynamicFunctionPropeGroup();
239 // Set default enablements
240 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
244 * Validates the kernel composite input data.
245 * @return true if configured data is valid and can be retrieved.
247 public boolean isValid() {
248 fIsTracepoints
= fTracepointsActivateButton
.getSelection();
249 fIsSysCalls
= fSysCallsActivateButton
.getSelection();
250 fIsDynamicProbe
= fProbeActivateButton
.getSelection();
251 fIsDynamicFunctionProbe
= fFunctionActivateButton
.getSelection();
253 // initialize tracepoint fields
254 fIsAllTracepoints
= false;
255 fSelectedEvents
= new ArrayList
<String
>();
257 if (fIsTracepoints
) {
258 List
<ITraceControlComponent
> comps
= fProviderGroup
.getChildren(KernelProviderComponent
.class);
259 fIsAllTracepoints
= fTracepointsViewer
.getChecked(comps
.get(0));
261 Object
[] checkedElements
= fTracepointsViewer
.getCheckedElements();
262 for (int i
= 0; i
< checkedElements
.length
; i
++) {
263 ITraceControlComponent component
= (ITraceControlComponent
)checkedElements
[i
];
264 if (component
instanceof BaseEventComponent
) {
265 fSelectedEvents
.add(component
.getName());
270 if (fIsDynamicProbe
) {
271 String temp
= fProbeEventNameText
.getText();
272 if (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
273 MessageDialog
.openError(getShell(),
274 Messages
.TraceControl_EnableEventsDialogTitle
,
275 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
280 if(!fProbeText
.getText().matches("\\s*")) { //$NON-NLS-1$
281 fProbeEventName
= temp
;
282 // fProbeString will be validated by lttng-tools
283 fProbeString
= fProbeText
.getText();
287 // initialize function string
288 fFunctionEventName
= null;
289 fFunctionString
= null;
290 if (fIsDynamicFunctionProbe
) {
291 String functionTemp
= fFunctionEventNameText
.getText();
292 if (!functionTemp
.matches("^[\\s]{0,}$") && !functionTemp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
293 MessageDialog
.openError(getShell(),
294 Messages
.TraceControl_EnableEventsDialogTitle
,
295 Messages
.TraceControl_InvalidProbeNameError
+ " (" + functionTemp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
300 if(!fFunctionText
.getText().matches("\\s*")) { //$NON-NLS-1$
301 fFunctionEventName
= functionTemp
;
302 // fFunctionString will be validated by lttng-tools
303 fFunctionString
= fFunctionText
.getText();
311 * Creates tracepoints group.
313 private void createTracepointsGroup() {
317 Group tpMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
318 tpMainGroup
.setText(Messages
.TraceControl_EnableEventsTracepointGroupName
);
319 layout
= new GridLayout(2, false);
320 tpMainGroup
.setLayout(layout
);
321 data
= new GridData(GridData
.FILL_BOTH
);
322 tpMainGroup
.setLayoutData(data
);
324 Composite buttonComposite
= new Composite(tpMainGroup
, SWT
.NONE
);
325 layout
= new GridLayout(1, true);
326 buttonComposite
.setLayout(layout
);
327 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
328 buttonComposite
.setLayoutData(data
);
330 fTracepointsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
331 fTracepointsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
332 data
= new GridData(GridData
.FILL_HORIZONTAL
);
333 fTracepointsActivateButton
.setLayoutData(data
);
334 fTracepointsActivateButton
.addSelectionListener(new SelectionAdapter() {
336 public void widgetSelected(SelectionEvent e
) {
337 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
341 Group tracepointsGroup
= new Group(tpMainGroup
, SWT
.SHADOW_NONE
);
342 layout
= new GridLayout(1, true);
343 tracepointsGroup
.setLayout(layout
);
344 data
= new GridData(GridData
.FILL_BOTH
);
345 tracepointsGroup
.setLayoutData(data
);
347 fTracepointsViewer
= new CheckboxTreeViewer(tracepointsGroup
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
348 fTracepointsViewer
.getTree().setToolTipText(Messages
.TraceControl_EnableEventsTracepointTreeTooltip
);
350 fTracepointsViewer
.setContentProvider(new KernelContentProvider());
351 fTracepointsViewer
.setLabelProvider(new KernelLabelProvider());
352 fTracepointsViewer
.addCheckStateListener(new KernelCheckListener());
353 fTracepointsViewer
.setInput(fProviderGroup
);
355 fTracepointsViewer
.getTree().setLayoutData(new GridData(GridData
.FILL_BOTH
));
359 * Creates syscalls group.
361 private void createSysCallsGroup() {
364 Group sysCallsMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
365 sysCallsMainGroup
.setText(Messages
.TraceControl_EnableEventsSyscallName
);
366 sysCallsMainGroup
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
367 layout
= new GridLayout(2, false);
368 sysCallsMainGroup
.setLayout(layout
);
369 data
= new GridData(GridData
.FILL_HORIZONTAL
);
370 sysCallsMainGroup
.setLayoutData(data
);
372 Composite buttonComposite
= new Composite(sysCallsMainGroup
, SWT
.NONE
);
373 layout
= new GridLayout(1, false);
374 buttonComposite
.setLayout(layout
);
375 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
376 buttonComposite
.setLayoutData(data
);
378 fSysCallsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
379 fSysCallsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
380 fSysCallsActivateButton
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
381 fSysCallsActivateButton
.setSelection(false);
382 data
= new GridData(GridData
.FILL_HORIZONTAL
);
383 fSysCallsActivateButton
.setLayoutData(data
);
384 fSysCallsActivateButton
.addSelectionListener(new SelectionAdapter() {
386 public void widgetSelected(SelectionEvent e
) {
387 setKernelEnablements(KernelGroupEnum
.SYSCALLS
);
393 * Creates dynamic probe group.
395 private void createDynamicProbeGroup() {
398 Group probeMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
399 probeMainGroup
.setText(Messages
.TraceControl_EnableEventsProbeGroupName
);
400 layout
= new GridLayout(2, false);
401 probeMainGroup
.setLayout(layout
);
402 data
= new GridData(GridData
.FILL_HORIZONTAL
);
403 probeMainGroup
.setLayoutData(data
);
405 Composite buttonComposite
= new Composite(probeMainGroup
, SWT
.NONE
);
406 layout
= new GridLayout(1, false);
407 buttonComposite
.setLayout(layout
);
408 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
409 buttonComposite
.setLayoutData(data
);
411 fProbeActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
412 fProbeActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
413 fProbeActivateButton
.setSelection(false);
414 data
= new GridData(GridData
.FILL_HORIZONTAL
);
415 fProbeActivateButton
.setLayoutData(data
);
416 fProbeActivateButton
.addSelectionListener(new SelectionAdapter() {
418 public void widgetSelected(SelectionEvent e
) {
419 setKernelEnablements(KernelGroupEnum
.PROBE
);
423 Group probeGroup
= new Group(probeMainGroup
, SWT
.SHADOW_NONE
);
424 layout
= new GridLayout(4, true);
425 probeGroup
.setLayout(layout
);
426 probeGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
428 Label probeNameLabel
= new Label(probeGroup
, SWT
.LEFT
);
429 probeNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
430 data
= new GridData(GridData
.FILL_BOTH
);
431 data
.horizontalSpan
= 1;
432 probeNameLabel
.setLayoutData(data
);
434 fProbeEventNameText
= new Text(probeGroup
, SWT
.LEFT
);
435 fProbeEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeEventNameTooltip
);
437 data
= new GridData(GridData
.FILL_BOTH
);
438 data
.horizontalSpan
= 3;
439 fProbeEventNameText
.setLayoutData(data
);
441 Label probeLabel
= new Label(probeGroup
, SWT
.LEFT
);
442 probeLabel
.setText(Messages
.TraceControl_EnableEventsProbeNameLabel
);
443 data
= new GridData(GridData
.FILL_BOTH
);
444 data
.horizontalSpan
= 1;
445 probeLabel
.setLayoutData(data
);
447 fProbeText
= new Text(probeGroup
, SWT
.LEFT
);
448 fProbeText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
449 data
= new GridData(GridData
.FILL_BOTH
);
450 data
.horizontalSpan
= 3;
451 fProbeText
.setLayoutData(data
);
455 * Creates dynamic function entry/return probe group.
457 private void createDynamicFunctionPropeGroup() {
460 Group functionMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
461 functionMainGroup
.setText(Messages
.TraceControl_EnableEventsFucntionGroupName
);
462 layout
= new GridLayout(2, false);
463 functionMainGroup
.setLayout(layout
);
464 data
= new GridData(GridData
.FILL_HORIZONTAL
);
465 functionMainGroup
.setLayoutData(data
);
467 Composite buttonComposite
= new Composite(functionMainGroup
, SWT
.NONE
);
468 layout
= new GridLayout(1, false);
469 buttonComposite
.setLayout(layout
);
470 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
471 buttonComposite
.setLayoutData(data
);
473 fFunctionActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
474 fFunctionActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
475 fFunctionActivateButton
.setSelection(false);
476 data
= new GridData(GridData
.FILL_HORIZONTAL
);
477 fFunctionActivateButton
.setLayoutData(data
);
478 fFunctionActivateButton
.addSelectionListener(new SelectionAdapter() {
480 public void widgetSelected(SelectionEvent e
) {
481 setKernelEnablements(KernelGroupEnum
.FUNCTION
);
485 Group functionGroup
= new Group(functionMainGroup
, SWT
.SHADOW_NONE
);
486 layout
= new GridLayout(4, true);
487 functionGroup
.setLayout(layout
);
488 functionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
490 Label functionNameLabel
= new Label(functionGroup
, SWT
.LEFT
);
491 functionNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
492 data
= new GridData(GridData
.FILL_BOTH
);
493 data
.horizontalSpan
= 1;
494 functionNameLabel
.setLayoutData(data
);
496 fFunctionEventNameText
= new Text(functionGroup
, SWT
.LEFT
);
497 fFunctionEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsFunctionEventNameTooltip
);
498 data
= new GridData(GridData
.FILL_BOTH
);
499 data
.horizontalSpan
= 3;
500 fFunctionEventNameText
.setLayoutData(data
);
502 Label functionLabel
= new Label(functionGroup
, SWT
.LEFT
);
503 functionLabel
.setText(Messages
.TraceControl_EnableEventsFunctionNameLabel
);
504 data
= new GridData(GridData
.FILL_BOTH
);
505 data
.horizontalSpan
= 1;
506 functionLabel
.setLayoutData(data
);
508 fFunctionText
= new Text(functionGroup
, SWT
.LEFT
);
509 fFunctionText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
510 data
= new GridData(GridData
.FILL_BOTH
);
511 data
.horizontalSpan
= 3;
512 fFunctionText
.setLayoutData(data
);
516 * Enable/selects widgets depending on the group specified.
517 * @param group - group to enable.
519 private void setKernelEnablements(KernelGroupEnum group
) {
520 fTracepointsActivateButton
.setSelection(group
== KernelGroupEnum
.TRACEPOINTS
);
521 fTracepointsViewer
.getTree().setEnabled(group
== KernelGroupEnum
.TRACEPOINTS
);
523 fSysCallsActivateButton
.setSelection(group
== KernelGroupEnum
.SYSCALLS
);
525 fProbeActivateButton
.setSelection(group
== KernelGroupEnum
.PROBE
);
526 fProbeEventNameText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
527 fProbeText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
529 fFunctionActivateButton
.setSelection(group
== KernelGroupEnum
.FUNCTION
);
530 fFunctionEventNameText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
531 fFunctionText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
534 // ------------------------------------------------------------------------
536 // ------------------------------------------------------------------------
538 * Content provider for the tracepoints tree.
540 public static final class KernelContentProvider
extends TraceControlContentProvider
{
542 public Object
[] getChildren(Object parentElement
) {
543 if (parentElement
instanceof TraceProviderGroup
) {
544 List
<ITraceControlComponent
> children
= ((ITraceControlComponent
)parentElement
).getChildren(KernelProviderComponent
.class);
545 return children
.toArray(new ITraceControlComponent
[children
.size()]);
547 if (parentElement
instanceof ITraceControlComponent
) {
548 return ((ITraceControlComponent
)parentElement
).getChildren();
550 return new Object
[0];
555 * Content label for the tracepoints tree.
557 public static final class KernelLabelProvider
extends TraceControlLabelProvider
{
559 public Image
getImage(Object element
) {
563 public String
getText(Object element
) {
564 if ((element
!= null) && (element
instanceof KernelProviderComponent
)) {
565 return Messages
.TraceControl_EnableEventsTracepointTreeAllLabel
;
567 return super.getText(element
);
572 * Check state listener for the tracepoints tree.
574 public final class KernelCheckListener
implements ICheckStateListener
{
576 public void checkStateChanged(CheckStateChangedEvent event
) {
577 if (event
.getChecked()) {
578 if (event
.getElement() instanceof KernelProviderComponent
) {
579 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), true);
582 if (event
.getElement() instanceof KernelProviderComponent
) {
583 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), false);
585 ITraceControlComponent component
= (ITraceControlComponent
) event
.getElement();
586 fTracepointsViewer
.setChecked(component
.getParent(), false);