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
.trim().isEmpty() ||
297 (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
298 MessageDialog
.openError(getShell(),
299 Messages
.TraceControl_EnableEventsDialogTitle
,
300 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
305 fProbeEventName
= temp
;
306 // fProbeString will be validated by lttng-tools
307 fProbeString
= fProbeText
.getText();
310 // initialize function string
311 fFunctionEventName
= null;
312 fFunctionString
= null;
313 if (fIsDynamicFunctionProbe
) {
314 String functionTemp
= fFunctionEventNameText
.getText();
315 if (functionTemp
.trim().isEmpty() ||
316 (!functionTemp
.matches("^[\\s]{0,}$") && !functionTemp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
317 MessageDialog
.openError(getShell(),
318 Messages
.TraceControl_EnableEventsDialogTitle
,
319 Messages
.TraceControl_InvalidProbeNameError
+ " (" + functionTemp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
324 fFunctionEventName
= functionTemp
;
325 // fFunctionString will be validated by lttng-tools
326 fFunctionString
= fFunctionText
.getText();
329 // initialize filter with null
330 fFilterExpression
= null;
331 if (fProviderGroup
.isEventFilteringSupported(true)) {
332 String tempFilter
= fFilterText
.getText();
334 if(!tempFilter
.trim().isEmpty()) {
335 fFilterExpression
= tempFilter
;
343 * Creates tracepoints group.
345 private void createTracepointsGroup() {
349 Group tpMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
350 tpMainGroup
.setText(Messages
.TraceControl_EnableEventsTracepointGroupName
);
351 layout
= new GridLayout(2, false);
352 tpMainGroup
.setLayout(layout
);
353 data
= new GridData(GridData
.FILL_BOTH
);
354 tpMainGroup
.setLayoutData(data
);
356 Composite buttonComposite
= new Composite(tpMainGroup
, SWT
.NONE
);
357 layout
= new GridLayout(1, true);
358 buttonComposite
.setLayout(layout
);
359 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
360 buttonComposite
.setLayoutData(data
);
362 fTracepointsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
363 fTracepointsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
364 data
= new GridData(GridData
.FILL_HORIZONTAL
);
365 fTracepointsActivateButton
.setLayoutData(data
);
366 fTracepointsActivateButton
.addSelectionListener(new SelectionAdapter() {
368 public void widgetSelected(SelectionEvent e
) {
369 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
373 Group tracepointsGroup
= new Group(tpMainGroup
, SWT
.SHADOW_NONE
);
374 layout
= new GridLayout(1, true);
375 tracepointsGroup
.setLayout(layout
);
376 data
= new GridData(GridData
.FILL_BOTH
);
377 tracepointsGroup
.setLayoutData(data
);
379 new FilteredTree(tracepointsGroup
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.BORDER
, new PatternFilter(), true) {
381 protected TreeViewer
doCreateTreeViewer(Composite aparent
, int style
) {
382 fTracepointsViewer
= new CheckboxTreeViewer(aparent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
383 fTracepointsViewer
.getTree().setToolTipText(Messages
.TraceControl_EnableEventsTracepointTreeTooltip
);
385 fTracepointsViewer
.setContentProvider(new KernelContentProvider());
386 fTracepointsViewer
.setLabelProvider(new KernelLabelProvider());
387 fTracepointsViewer
.addCheckStateListener(new KernelCheckListener());
388 fTracepointsViewer
.setInput(fProviderGroup
);
390 fTracepointsViewer
.getTree().setLayoutData(new GridData(GridData
.FILL_BOTH
));
391 return fTracepointsViewer
;
395 protected void updateToolbar(boolean visible
) {
396 super.updateToolbar(visible
);
397 treeViewer
.expandAll();
403 * Creates syscalls group.
405 private void createSysCallsGroup() {
408 Group sysCallsMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
409 sysCallsMainGroup
.setText(Messages
.TraceControl_EnableEventsSyscallName
);
410 sysCallsMainGroup
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
411 layout
= new GridLayout(2, false);
412 sysCallsMainGroup
.setLayout(layout
);
413 data
= new GridData(GridData
.FILL_HORIZONTAL
);
414 sysCallsMainGroup
.setLayoutData(data
);
416 Composite buttonComposite
= new Composite(sysCallsMainGroup
, SWT
.NONE
);
417 layout
= new GridLayout(1, false);
418 buttonComposite
.setLayout(layout
);
419 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
420 buttonComposite
.setLayoutData(data
);
422 fSysCallsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
423 fSysCallsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
424 fSysCallsActivateButton
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
425 fSysCallsActivateButton
.setSelection(false);
426 data
= new GridData(GridData
.FILL_HORIZONTAL
);
427 fSysCallsActivateButton
.setLayoutData(data
);
428 fSysCallsActivateButton
.addSelectionListener(new SelectionAdapter() {
430 public void widgetSelected(SelectionEvent e
) {
431 setKernelEnablements(KernelGroupEnum
.SYSCALLS
);
437 * Creates dynamic probe group.
439 private void createDynamicProbeGroup() {
442 Group probeMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
443 probeMainGroup
.setText(Messages
.TraceControl_EnableEventsProbeGroupName
);
444 layout
= new GridLayout(2, false);
445 probeMainGroup
.setLayout(layout
);
446 data
= new GridData(GridData
.FILL_HORIZONTAL
);
447 probeMainGroup
.setLayoutData(data
);
449 Composite buttonComposite
= new Composite(probeMainGroup
, SWT
.NONE
);
450 layout
= new GridLayout(1, false);
451 buttonComposite
.setLayout(layout
);
452 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
453 buttonComposite
.setLayoutData(data
);
455 fProbeActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
456 fProbeActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
457 fProbeActivateButton
.setSelection(false);
458 data
= new GridData(GridData
.FILL_HORIZONTAL
);
459 fProbeActivateButton
.setLayoutData(data
);
460 fProbeActivateButton
.addSelectionListener(new SelectionAdapter() {
462 public void widgetSelected(SelectionEvent e
) {
463 setKernelEnablements(KernelGroupEnum
.PROBE
);
467 Group probeGroup
= new Group(probeMainGroup
, SWT
.SHADOW_NONE
);
468 layout
= new GridLayout(4, true);
469 probeGroup
.setLayout(layout
);
470 probeGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
472 Label probeNameLabel
= new Label(probeGroup
, SWT
.LEFT
);
473 probeNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
474 data
= new GridData(GridData
.FILL_BOTH
);
475 data
.horizontalSpan
= 1;
476 probeNameLabel
.setLayoutData(data
);
478 fProbeEventNameText
= new Text(probeGroup
, SWT
.LEFT
);
479 fProbeEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeEventNameTooltip
);
481 data
= new GridData(GridData
.FILL_BOTH
);
482 data
.horizontalSpan
= 3;
483 fProbeEventNameText
.setLayoutData(data
);
485 Label probeLabel
= new Label(probeGroup
, SWT
.LEFT
);
486 probeLabel
.setText(Messages
.TraceControl_EnableEventsProbeNameLabel
);
487 data
= new GridData(GridData
.FILL_BOTH
);
488 data
.horizontalSpan
= 1;
489 probeLabel
.setLayoutData(data
);
491 fProbeText
= new Text(probeGroup
, SWT
.LEFT
);
492 fProbeText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
493 data
= new GridData(GridData
.FILL_BOTH
);
494 data
.horizontalSpan
= 3;
495 fProbeText
.setLayoutData(data
);
499 * Creates dynamic function entry/return probe group.
501 private void createDynamicFunctionPropeGroup() {
504 Group functionMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
505 functionMainGroup
.setText(Messages
.TraceControl_EnableEventsFucntionGroupName
);
506 layout
= new GridLayout(2, false);
507 functionMainGroup
.setLayout(layout
);
508 data
= new GridData(GridData
.FILL_HORIZONTAL
);
509 functionMainGroup
.setLayoutData(data
);
511 Composite buttonComposite
= new Composite(functionMainGroup
, SWT
.NONE
);
512 layout
= new GridLayout(1, false);
513 buttonComposite
.setLayout(layout
);
514 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
515 buttonComposite
.setLayoutData(data
);
517 fFunctionActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
518 fFunctionActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
519 fFunctionActivateButton
.setSelection(false);
520 data
= new GridData(GridData
.FILL_HORIZONTAL
);
521 fFunctionActivateButton
.setLayoutData(data
);
522 fFunctionActivateButton
.addSelectionListener(new SelectionAdapter() {
524 public void widgetSelected(SelectionEvent e
) {
525 setKernelEnablements(KernelGroupEnum
.FUNCTION
);
529 Group functionGroup
= new Group(functionMainGroup
, SWT
.SHADOW_NONE
);
530 layout
= new GridLayout(4, true);
531 functionGroup
.setLayout(layout
);
532 functionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
534 Label functionNameLabel
= new Label(functionGroup
, SWT
.LEFT
);
535 functionNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
536 data
= new GridData(GridData
.FILL_BOTH
);
537 data
.horizontalSpan
= 1;
538 functionNameLabel
.setLayoutData(data
);
540 fFunctionEventNameText
= new Text(functionGroup
, SWT
.LEFT
);
541 fFunctionEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsFunctionEventNameTooltip
);
542 data
= new GridData(GridData
.FILL_BOTH
);
543 data
.horizontalSpan
= 3;
544 fFunctionEventNameText
.setLayoutData(data
);
546 Label functionLabel
= new Label(functionGroup
, SWT
.LEFT
);
547 functionLabel
.setText(Messages
.TraceControl_EnableEventsFunctionNameLabel
);
548 data
= new GridData(GridData
.FILL_BOTH
);
549 data
.horizontalSpan
= 1;
550 functionLabel
.setLayoutData(data
);
552 fFunctionText
= new Text(functionGroup
, SWT
.LEFT
);
553 fFunctionText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
554 data
= new GridData(GridData
.FILL_BOTH
);
555 data
.horizontalSpan
= 3;
556 fFunctionText
.setLayoutData(data
);
560 * Enable/selects widgets depending on the group specified.
561 * @param group - group to enable.
563 private void setKernelEnablements(KernelGroupEnum group
) {
564 fTracepointsActivateButton
.setSelection(group
== KernelGroupEnum
.TRACEPOINTS
);
565 fTracepointsViewer
.getTree().setEnabled(group
== KernelGroupEnum
.TRACEPOINTS
);
567 fSysCallsActivateButton
.setSelection(group
== KernelGroupEnum
.SYSCALLS
);
569 fProbeActivateButton
.setSelection(group
== KernelGroupEnum
.PROBE
);
570 fProbeEventNameText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
571 fProbeText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
573 fFunctionActivateButton
.setSelection(group
== KernelGroupEnum
.FUNCTION
);
574 fFunctionEventNameText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
575 fFunctionText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
578 private void createFilterGroup() {
579 if (fProviderGroup
.isEventFilteringSupported(true)) {
580 Group filterMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
581 filterMainGroup
.setText(Messages
.TraceControl_EnableEventsFilterGroupName
);
582 GridLayout layout
= new GridLayout(3, false);
583 filterMainGroup
.setLayout(layout
);
584 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
585 filterMainGroup
.setLayoutData(data
);
587 fFilterText
= new Text(filterMainGroup
, SWT
.LEFT
);
588 fFilterText
.setToolTipText(Messages
.TraceControl_EnableEventsFilterTooltip
);
589 data
= new GridData(GridData
.FILL_HORIZONTAL
);
590 fFilterText
.setLayoutData(data
);
594 // ------------------------------------------------------------------------
596 // ------------------------------------------------------------------------
598 * Content provider for the tracepoints tree.
600 public static final class KernelContentProvider
extends TraceControlContentProvider
{
602 public Object
[] getChildren(Object parentElement
) {
603 if (parentElement
instanceof TraceProviderGroup
) {
604 List
<ITraceControlComponent
> children
= ((ITraceControlComponent
)parentElement
).getChildren(KernelProviderComponent
.class);
605 return children
.toArray(new ITraceControlComponent
[children
.size()]);
607 if (parentElement
instanceof ITraceControlComponent
) {
608 return ((ITraceControlComponent
)parentElement
).getChildren();
610 return new Object
[0];
615 * Content label for the tracepoints tree.
617 public static final class KernelLabelProvider
extends TraceControlLabelProvider
{
619 public Image
getImage(Object element
) {
623 public String
getText(Object element
) {
624 if ((element
!= null) && (element
instanceof KernelProviderComponent
)) {
625 return Messages
.TraceControl_EnableEventsTracepointTreeAllLabel
;
627 return super.getText(element
);
632 * Check state listener for the tracepoints tree.
634 public final class KernelCheckListener
implements ICheckStateListener
{
636 public void checkStateChanged(CheckStateChangedEvent event
) {
637 if (event
.getChecked()) {
638 if (event
.getElement() instanceof KernelProviderComponent
) {
639 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), true);
642 if (event
.getElement() instanceof KernelProviderComponent
) {
643 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), false);
645 ITraceControlComponent component
= (ITraceControlComponent
) event
.getElement();
646 fTracepointsViewer
.setChecked(component
.getParent(), false);