1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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 * Marc-Andre Laperle - Add filtering textbox
12 **********************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
19 import org
.eclipse
.jface
.viewers
.CheckStateChangedEvent
;
20 import org
.eclipse
.jface
.viewers
.CheckboxTreeViewer
;
21 import org
.eclipse
.jface
.viewers
.ICheckStateListener
;
22 import org
.eclipse
.jface
.viewers
.TreeViewer
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.events
.SelectionAdapter
;
25 import org
.eclipse
.swt
.events
.SelectionEvent
;
26 import org
.eclipse
.swt
.graphics
.Image
;
27 import org
.eclipse
.swt
.layout
.GridData
;
28 import org
.eclipse
.swt
.layout
.GridLayout
;
29 import org
.eclipse
.swt
.widgets
.Button
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.swt
.widgets
.Group
;
32 import org
.eclipse
.swt
.widgets
.Label
;
33 import org
.eclipse
.swt
.widgets
.Text
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.BaseEventComponent
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.KernelProviderComponent
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceControlContentProvider
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceControlLabelProvider
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceProviderGroup
;
41 import org
.eclipse
.ui
.dialogs
.FilteredTree
;
42 import org
.eclipse
.ui
.dialogs
.PatternFilter
;
46 * A composite for collecting information about kernel events to be enabled.
49 * @author Bernd Hufmann
51 public class EnableKernelEventComposite
extends Composite
implements IEnableKernelEvents
{
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
56 private enum KernelGroupEnum
{ TRACEPOINTS
, SYSCALLS
, PROBE
, FUNCTION
}
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
63 * A button to enable/disable the tracepoints group
65 private Button fTracepointsActivateButton
;
67 * A tree viewer for displaying and selection of available tracepoints.
69 private CheckboxTreeViewer fTracepointsViewer
;
71 * A button to enable/disable the syscalls group
73 private Button fSysCallsActivateButton
;
75 * A button to enable or disable the dynamic probe group.
77 private Button fProbeActivateButton
;
79 * The text field for the event name for the dynamic probe.
81 private Text fProbeEventNameText
;
83 * The text field for the dynamic probe.
85 private Text fProbeText
;
87 * A button to enable or disable the dynamic function probe group.
89 private Button fFunctionActivateButton
;
91 * The text field for the event name for the dynamic probe.
93 private Text fFunctionEventNameText
;
95 * The text field for the dynamic function entry/return probe.
97 private Text fFunctionText
;
101 private Text fFilterText
;
103 * The referenced trace provider group containing the kernel provider
104 * component which contains a list of available tracepoints.
106 private final TraceProviderGroup fProviderGroup
;
108 * The flag indicating that tracepoints are selected.
110 private boolean fIsTracepoints
;
112 * The flag indicating that all tracepoints are selected.
114 private boolean fIsAllTracepoints
;
116 * The flag indicating that syscalls are selected.
118 private boolean fIsSysCalls
;
120 * The list of tracepoints to be enabled.
122 private List
<String
> fSelectedEvents
;
124 * The flag indicating that dynamic probe is selected.
126 private boolean fIsDynamicProbe
;
128 * The event name of the dynamic probe.
130 private String fProbeEventName
;
134 private String fProbeString
;
136 * The flag indicating that the dynamic function probe is selected.
138 private boolean fIsDynamicFunctionProbe
;
140 * The event name of the dynamic function entry/return probe.
142 private String fFunctionEventName
;
144 * The dynamic function entry/return probe.
146 private String fFunctionString
;
148 * The filter expression
150 private String fFilterExpression
;
152 // ------------------------------------------------------------------------
154 // ------------------------------------------------------------------------
160 * The parent composite
162 * The index of the style for this event composite
163 * @param providerGroup
164 * The trace provider group
166 public EnableKernelEventComposite(Composite parent
, int style
, TraceProviderGroup providerGroup
) {
167 super(parent
, style
);
168 fProviderGroup
= providerGroup
;
171 // ------------------------------------------------------------------------
173 // ------------------------------------------------------------------------
176 public boolean isTracepoints() {
177 return fIsTracepoints
;
181 public boolean isAllTracePoints() {
182 return fIsAllTracepoints
;
186 public boolean isSysCalls() {
191 public boolean isAllSysCalls() {
196 public List
<String
> getEventNames() {
197 return new ArrayList
<>(fSelectedEvents
);
201 public boolean isDynamicProbe() {
202 return fIsDynamicProbe
;
206 public String
getProbeName() {
211 public String
getProbeEventName() {
212 return fProbeEventName
;
216 public boolean isDynamicFunctionProbe() {
217 return fIsDynamicFunctionProbe
;
221 public String
getFunctionEventName() {
222 return fFunctionEventName
;
226 public String
getFunction() {
227 return fFunctionString
;
231 public String
getFilterExpression() {
232 return fFilterExpression
;
235 // ------------------------------------------------------------------------
237 // ------------------------------------------------------------------------
240 * Creates the composite content
242 public void createContent() {
245 createTracepointsGroup();
248 createSysCallsGroup();
250 // Dynamic Probe Group
251 createDynamicProbeGroup();
253 // Dynamic Function Probe Group
254 createDynamicFunctionPropeGroup();
259 // Set default enablements
260 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
264 * Validates the kernel composite input data.
265 * @return true if configured data is valid and can be retrieved.
267 public boolean isValid() {
268 fIsTracepoints
= fTracepointsActivateButton
.getSelection();
269 fIsSysCalls
= fSysCallsActivateButton
.getSelection();
270 fIsDynamicProbe
= fProbeActivateButton
.getSelection();
271 fIsDynamicFunctionProbe
= fFunctionActivateButton
.getSelection();
273 // initialize tracepoint fields
274 fIsAllTracepoints
= false;
275 fSelectedEvents
= new ArrayList
<>();
277 if (fIsTracepoints
) {
278 Object
[] checkedElements
= fTracepointsViewer
.getCheckedElements();
279 for (int i
= 0; i
< checkedElements
.length
; i
++) {
280 ITraceControlComponent component
= (ITraceControlComponent
)checkedElements
[i
];
281 if (component
instanceof BaseEventComponent
) {
282 fSelectedEvents
.add(component
.getName());
285 // verify if all events are selected
287 List
<ITraceControlComponent
> comps
= fProviderGroup
.getChildren(KernelProviderComponent
.class);
288 for (ITraceControlComponent comp
: comps
) {
289 nbEvents
+= comp
.getChildren().length
;
291 fIsAllTracepoints
= (nbEvents
== fSelectedEvents
.size());
294 if (fIsDynamicProbe
) {
295 String temp
= fProbeEventNameText
.getText();
296 if (temp
.isEmpty() ||
297 fProbeText
.getText().matches("\\s*") || //$NON-NLS-1$
298 (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
299 MessageDialog
.openError(getShell(),
300 Messages
.TraceControl_EnableEventsDialogTitle
,
301 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
306 fProbeEventName
= temp
;
307 // fProbeString will be validated by lttng-tools
308 fProbeString
= fProbeText
.getText();
311 // initialize function string
312 fFunctionEventName
= null;
313 fFunctionString
= null;
314 if (fIsDynamicFunctionProbe
) {
315 String functionTemp
= fFunctionEventNameText
.getText();
316 if (functionTemp
.isEmpty() ||
317 functionTemp
.matches("\\s*") || //$NON-NLS-1$
318 (!functionTemp
.matches("^[\\s]{0,}$") && !functionTemp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
319 MessageDialog
.openError(getShell(),
320 Messages
.TraceControl_EnableEventsDialogTitle
,
321 Messages
.TraceControl_InvalidProbeNameError
+ " (" + functionTemp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
326 fFunctionEventName
= functionTemp
;
327 // fFunctionString will be validated by lttng-tools
328 fFunctionString
= fFunctionText
.getText();
331 // initialize filter with null
332 fFilterExpression
= null;
333 if (fProviderGroup
.isEventFilteringSupported(true)) {
334 String tempFilter
= fFilterText
.getText();
336 if(!tempFilter
.isEmpty() && !tempFilter
.matches("\\s*")) { //$NON-NLS-1$
337 fFilterExpression
= tempFilter
;
345 * Creates tracepoints group.
347 private void createTracepointsGroup() {
351 Group tpMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
352 tpMainGroup
.setText(Messages
.TraceControl_EnableEventsTracepointGroupName
);
353 layout
= new GridLayout(2, false);
354 tpMainGroup
.setLayout(layout
);
355 data
= new GridData(GridData
.FILL_BOTH
);
356 tpMainGroup
.setLayoutData(data
);
358 Composite buttonComposite
= new Composite(tpMainGroup
, SWT
.NONE
);
359 layout
= new GridLayout(1, true);
360 buttonComposite
.setLayout(layout
);
361 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
362 buttonComposite
.setLayoutData(data
);
364 fTracepointsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
365 fTracepointsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
366 data
= new GridData(GridData
.FILL_HORIZONTAL
);
367 fTracepointsActivateButton
.setLayoutData(data
);
368 fTracepointsActivateButton
.addSelectionListener(new SelectionAdapter() {
370 public void widgetSelected(SelectionEvent e
) {
371 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
375 Group tracepointsGroup
= new Group(tpMainGroup
, SWT
.SHADOW_NONE
);
376 layout
= new GridLayout(1, true);
377 tracepointsGroup
.setLayout(layout
);
378 data
= new GridData(GridData
.FILL_BOTH
);
379 tracepointsGroup
.setLayoutData(data
);
381 new FilteredTree(tracepointsGroup
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.BORDER
, new PatternFilter(), true) {
383 protected TreeViewer
doCreateTreeViewer(Composite aparent
, int style
) {
384 fTracepointsViewer
= new CheckboxTreeViewer(aparent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
385 fTracepointsViewer
.getTree().setToolTipText(Messages
.TraceControl_EnableEventsTracepointTreeTooltip
);
387 fTracepointsViewer
.setContentProvider(new KernelContentProvider());
388 fTracepointsViewer
.setLabelProvider(new KernelLabelProvider());
389 fTracepointsViewer
.addCheckStateListener(new KernelCheckListener());
390 fTracepointsViewer
.setInput(fProviderGroup
);
392 fTracepointsViewer
.getTree().setLayoutData(new GridData(GridData
.FILL_BOTH
));
393 return fTracepointsViewer
;
397 protected void updateToolbar(boolean visible
) {
398 super.updateToolbar(visible
);
399 treeViewer
.expandAll();
405 * Creates syscalls group.
407 private void createSysCallsGroup() {
410 Group sysCallsMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
411 sysCallsMainGroup
.setText(Messages
.TraceControl_EnableEventsSyscallName
);
412 sysCallsMainGroup
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
413 layout
= new GridLayout(2, false);
414 sysCallsMainGroup
.setLayout(layout
);
415 data
= new GridData(GridData
.FILL_HORIZONTAL
);
416 sysCallsMainGroup
.setLayoutData(data
);
418 Composite buttonComposite
= new Composite(sysCallsMainGroup
, SWT
.NONE
);
419 layout
= new GridLayout(1, false);
420 buttonComposite
.setLayout(layout
);
421 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
422 buttonComposite
.setLayoutData(data
);
424 fSysCallsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
425 fSysCallsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
426 fSysCallsActivateButton
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
427 fSysCallsActivateButton
.setSelection(false);
428 data
= new GridData(GridData
.FILL_HORIZONTAL
);
429 fSysCallsActivateButton
.setLayoutData(data
);
430 fSysCallsActivateButton
.addSelectionListener(new SelectionAdapter() {
432 public void widgetSelected(SelectionEvent e
) {
433 setKernelEnablements(KernelGroupEnum
.SYSCALLS
);
439 * Creates dynamic probe group.
441 private void createDynamicProbeGroup() {
444 Group probeMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
445 probeMainGroup
.setText(Messages
.TraceControl_EnableEventsProbeGroupName
);
446 layout
= new GridLayout(2, false);
447 probeMainGroup
.setLayout(layout
);
448 data
= new GridData(GridData
.FILL_HORIZONTAL
);
449 probeMainGroup
.setLayoutData(data
);
451 Composite buttonComposite
= new Composite(probeMainGroup
, SWT
.NONE
);
452 layout
= new GridLayout(1, false);
453 buttonComposite
.setLayout(layout
);
454 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
455 buttonComposite
.setLayoutData(data
);
457 fProbeActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
458 fProbeActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
459 fProbeActivateButton
.setSelection(false);
460 data
= new GridData(GridData
.FILL_HORIZONTAL
);
461 fProbeActivateButton
.setLayoutData(data
);
462 fProbeActivateButton
.addSelectionListener(new SelectionAdapter() {
464 public void widgetSelected(SelectionEvent e
) {
465 setKernelEnablements(KernelGroupEnum
.PROBE
);
469 Group probeGroup
= new Group(probeMainGroup
, SWT
.SHADOW_NONE
);
470 layout
= new GridLayout(4, true);
471 probeGroup
.setLayout(layout
);
472 probeGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
474 Label probeNameLabel
= new Label(probeGroup
, SWT
.LEFT
);
475 probeNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
476 data
= new GridData(GridData
.FILL_BOTH
);
477 data
.horizontalSpan
= 1;
478 probeNameLabel
.setLayoutData(data
);
480 fProbeEventNameText
= new Text(probeGroup
, SWT
.LEFT
);
481 fProbeEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeEventNameTooltip
);
483 data
= new GridData(GridData
.FILL_BOTH
);
484 data
.horizontalSpan
= 3;
485 fProbeEventNameText
.setLayoutData(data
);
487 Label probeLabel
= new Label(probeGroup
, SWT
.LEFT
);
488 probeLabel
.setText(Messages
.TraceControl_EnableEventsProbeNameLabel
);
489 data
= new GridData(GridData
.FILL_BOTH
);
490 data
.horizontalSpan
= 1;
491 probeLabel
.setLayoutData(data
);
493 fProbeText
= new Text(probeGroup
, SWT
.LEFT
);
494 fProbeText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
495 data
= new GridData(GridData
.FILL_BOTH
);
496 data
.horizontalSpan
= 3;
497 fProbeText
.setLayoutData(data
);
501 * Creates dynamic function entry/return probe group.
503 private void createDynamicFunctionPropeGroup() {
506 Group functionMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
507 functionMainGroup
.setText(Messages
.TraceControl_EnableEventsFucntionGroupName
);
508 layout
= new GridLayout(2, false);
509 functionMainGroup
.setLayout(layout
);
510 data
= new GridData(GridData
.FILL_HORIZONTAL
);
511 functionMainGroup
.setLayoutData(data
);
513 Composite buttonComposite
= new Composite(functionMainGroup
, SWT
.NONE
);
514 layout
= new GridLayout(1, false);
515 buttonComposite
.setLayout(layout
);
516 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
517 buttonComposite
.setLayoutData(data
);
519 fFunctionActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
520 fFunctionActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
521 fFunctionActivateButton
.setSelection(false);
522 data
= new GridData(GridData
.FILL_HORIZONTAL
);
523 fFunctionActivateButton
.setLayoutData(data
);
524 fFunctionActivateButton
.addSelectionListener(new SelectionAdapter() {
526 public void widgetSelected(SelectionEvent e
) {
527 setKernelEnablements(KernelGroupEnum
.FUNCTION
);
531 Group functionGroup
= new Group(functionMainGroup
, SWT
.SHADOW_NONE
);
532 layout
= new GridLayout(4, true);
533 functionGroup
.setLayout(layout
);
534 functionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
536 Label functionNameLabel
= new Label(functionGroup
, SWT
.LEFT
);
537 functionNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
538 data
= new GridData(GridData
.FILL_BOTH
);
539 data
.horizontalSpan
= 1;
540 functionNameLabel
.setLayoutData(data
);
542 fFunctionEventNameText
= new Text(functionGroup
, SWT
.LEFT
);
543 fFunctionEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsFunctionEventNameTooltip
);
544 data
= new GridData(GridData
.FILL_BOTH
);
545 data
.horizontalSpan
= 3;
546 fFunctionEventNameText
.setLayoutData(data
);
548 Label functionLabel
= new Label(functionGroup
, SWT
.LEFT
);
549 functionLabel
.setText(Messages
.TraceControl_EnableEventsFunctionNameLabel
);
550 data
= new GridData(GridData
.FILL_BOTH
);
551 data
.horizontalSpan
= 1;
552 functionLabel
.setLayoutData(data
);
554 fFunctionText
= new Text(functionGroup
, SWT
.LEFT
);
555 fFunctionText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
556 data
= new GridData(GridData
.FILL_BOTH
);
557 data
.horizontalSpan
= 3;
558 fFunctionText
.setLayoutData(data
);
562 * Enable/selects widgets depending on the group specified.
563 * @param group - group to enable.
565 private void setKernelEnablements(KernelGroupEnum group
) {
566 fTracepointsActivateButton
.setSelection(group
== KernelGroupEnum
.TRACEPOINTS
);
567 fTracepointsViewer
.getTree().setEnabled(group
== KernelGroupEnum
.TRACEPOINTS
);
569 fSysCallsActivateButton
.setSelection(group
== KernelGroupEnum
.SYSCALLS
);
571 fProbeActivateButton
.setSelection(group
== KernelGroupEnum
.PROBE
);
572 fProbeEventNameText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
573 fProbeText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
575 fFunctionActivateButton
.setSelection(group
== KernelGroupEnum
.FUNCTION
);
576 fFunctionEventNameText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
577 fFunctionText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
580 private void createFilterGroup() {
581 if (fProviderGroup
.isEventFilteringSupported(true)) {
582 Group filterMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
583 filterMainGroup
.setText(Messages
.TraceControl_EnableEventsFilterGroupName
);
584 GridLayout layout
= new GridLayout(3, false);
585 filterMainGroup
.setLayout(layout
);
586 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
587 filterMainGroup
.setLayoutData(data
);
589 fFilterText
= new Text(filterMainGroup
, SWT
.LEFT
);
590 fFilterText
.setToolTipText(Messages
.TraceControl_EnableEventsFilterTooltip
);
591 data
= new GridData(GridData
.FILL_HORIZONTAL
);
592 fFilterText
.setLayoutData(data
);
596 // ------------------------------------------------------------------------
598 // ------------------------------------------------------------------------
600 * Content provider for the tracepoints tree.
602 public static final class KernelContentProvider
extends TraceControlContentProvider
{
604 public Object
[] getChildren(Object parentElement
) {
605 if (parentElement
instanceof TraceProviderGroup
) {
606 List
<ITraceControlComponent
> children
= ((ITraceControlComponent
)parentElement
).getChildren(KernelProviderComponent
.class);
607 return children
.toArray(new ITraceControlComponent
[children
.size()]);
609 if (parentElement
instanceof ITraceControlComponent
) {
610 return ((ITraceControlComponent
)parentElement
).getChildren();
612 return new Object
[0];
617 * Content label for the tracepoints tree.
619 public static final class KernelLabelProvider
extends TraceControlLabelProvider
{
621 public Image
getImage(Object element
) {
625 public String
getText(Object element
) {
626 if ((element
!= null) && (element
instanceof KernelProviderComponent
)) {
627 return Messages
.TraceControl_EnableEventsTracepointTreeAllLabel
;
629 return super.getText(element
);
634 * Check state listener for the tracepoints tree.
636 public final class KernelCheckListener
implements ICheckStateListener
{
638 public void checkStateChanged(CheckStateChangedEvent event
) {
639 if (event
.getChecked()) {
640 if (event
.getElement() instanceof KernelProviderComponent
) {
641 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), true);
644 if (event
.getElement() instanceof KernelProviderComponent
) {
645 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), false);
647 ITraceControlComponent component
= (ITraceControlComponent
) event
.getElement();
648 fTracepointsViewer
.setChecked(component
.getParent(), false);