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
.linuxtools
.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
.linuxtools
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.BaseEventComponent
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.KernelProviderComponent
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceControlContentProvider
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceControlLabelProvider
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceProviderGroup
;
30 import org
.eclipse
.swt
.SWT
;
31 import org
.eclipse
.swt
.events
.SelectionAdapter
;
32 import org
.eclipse
.swt
.events
.SelectionEvent
;
33 import org
.eclipse
.swt
.graphics
.Image
;
34 import org
.eclipse
.swt
.layout
.GridData
;
35 import org
.eclipse
.swt
.layout
.GridLayout
;
36 import org
.eclipse
.swt
.widgets
.Button
;
37 import org
.eclipse
.swt
.widgets
.Composite
;
38 import org
.eclipse
.swt
.widgets
.Group
;
39 import org
.eclipse
.swt
.widgets
.Label
;
40 import org
.eclipse
.swt
.widgets
.Text
;
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
;
99 * The referenced trace provider group containing the kernel provider
100 * component which contains a list of available tracepoints.
102 private final TraceProviderGroup fProviderGroup
;
104 * The flag indicating that tracepoints are selected.
106 private boolean fIsTracepoints
;
108 * The flag indicating that all tracepoints are selected.
110 private boolean fIsAllTracepoints
;
112 * The flag indicating that syscalls are selected.
114 private boolean fIsSysCalls
;
116 * The list of tracepoints to be enabled.
118 private List
<String
> fSelectedEvents
;
120 * The flag indicating that dynamic probe is selected.
122 private boolean fIsDynamicProbe
;
124 * The event name of the dynamic probe.
126 private String fProbeEventName
;
130 private String fProbeString
;
132 * The flag indicating that the dynamic function probe is selected.
134 private boolean fIsDynamicFunctionProbe
;
136 * The event name of the dynamic function entry/return probe.
138 private String fFunctionEventName
;
140 * The dynamic function entry/return probe.
142 private String fFunctionString
;
144 // ------------------------------------------------------------------------
146 // ------------------------------------------------------------------------
152 * The parent composite
154 * The index of the style for this event composite
155 * @param providerGroup
156 * The trace provider group
158 public EnableKernelEventComposite(Composite parent
, int style
, TraceProviderGroup providerGroup
) {
159 super(parent
, style
);
160 fProviderGroup
= providerGroup
;
163 // ------------------------------------------------------------------------
165 // ------------------------------------------------------------------------
168 public boolean isTracepoints() {
169 return fIsTracepoints
;
173 public boolean isAllTracePoints() {
174 return fIsAllTracepoints
;
178 public boolean isSysCalls() {
183 public boolean isAllSysCalls() {
188 public List
<String
> getEventNames() {
189 return new ArrayList
<>(fSelectedEvents
);
193 public boolean isDynamicProbe() {
194 return fIsDynamicProbe
;
198 public String
getProbeName() {
203 public String
getProbeEventName() {
204 return fProbeEventName
;
208 public boolean isDynamicFunctionProbe() {
209 return fIsDynamicFunctionProbe
;
213 public String
getFunctionEventName() {
214 return fFunctionEventName
;
218 public String
getFunction() {
219 return fFunctionString
;
222 // ------------------------------------------------------------------------
224 // ------------------------------------------------------------------------
227 * Creates the composite content
229 public void createContent() {
232 createTracepointsGroup();
235 createSysCallsGroup();
237 // Dynamic Probe Group
238 createDynamicProbeGroup();
240 // Dynamic Function Probe Group
241 createDynamicFunctionPropeGroup();
243 // Set default enablements
244 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
248 * Validates the kernel composite input data.
249 * @return true if configured data is valid and can be retrieved.
251 public boolean isValid() {
252 fIsTracepoints
= fTracepointsActivateButton
.getSelection();
253 fIsSysCalls
= fSysCallsActivateButton
.getSelection();
254 fIsDynamicProbe
= fProbeActivateButton
.getSelection();
255 fIsDynamicFunctionProbe
= fFunctionActivateButton
.getSelection();
257 // initialize tracepoint fields
258 fIsAllTracepoints
= false;
259 fSelectedEvents
= new ArrayList
<>();
261 if (fIsTracepoints
) {
262 List
<ITraceControlComponent
> comps
= fProviderGroup
.getChildren(KernelProviderComponent
.class);
263 fIsAllTracepoints
= fTracepointsViewer
.getChecked(comps
.get(0));
265 Object
[] checkedElements
= fTracepointsViewer
.getCheckedElements();
266 for (int i
= 0; i
< checkedElements
.length
; i
++) {
267 ITraceControlComponent component
= (ITraceControlComponent
)checkedElements
[i
];
268 if (component
instanceof BaseEventComponent
) {
269 fSelectedEvents
.add(component
.getName());
274 if (fIsDynamicProbe
) {
275 String temp
= fProbeEventNameText
.getText();
276 if (temp
.isEmpty() ||
277 fProbeText
.getText().matches("\\s*") || //$NON-NLS-1$
278 (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
279 MessageDialog
.openError(getShell(),
280 Messages
.TraceControl_EnableEventsDialogTitle
,
281 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
286 fProbeEventName
= temp
;
287 // fProbeString will be validated by lttng-tools
288 fProbeString
= fProbeText
.getText();
291 // initialize function string
292 fFunctionEventName
= null;
293 fFunctionString
= null;
294 if (fIsDynamicFunctionProbe
) {
295 String functionTemp
= fFunctionEventNameText
.getText();
296 if (functionTemp
.isEmpty() ||
297 functionTemp
.matches("\\s*") || //$NON-NLS-1$
298 (!functionTemp
.matches("^[\\s]{0,}$") && !functionTemp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
299 MessageDialog
.openError(getShell(),
300 Messages
.TraceControl_EnableEventsDialogTitle
,
301 Messages
.TraceControl_InvalidProbeNameError
+ " (" + functionTemp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
306 fFunctionEventName
= functionTemp
;
307 // fFunctionString will be validated by lttng-tools
308 fFunctionString
= fFunctionText
.getText();
315 * Creates tracepoints group.
317 private void createTracepointsGroup() {
321 Group tpMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
322 tpMainGroup
.setText(Messages
.TraceControl_EnableEventsTracepointGroupName
);
323 layout
= new GridLayout(2, false);
324 tpMainGroup
.setLayout(layout
);
325 data
= new GridData(GridData
.FILL_BOTH
);
326 tpMainGroup
.setLayoutData(data
);
328 Composite buttonComposite
= new Composite(tpMainGroup
, SWT
.NONE
);
329 layout
= new GridLayout(1, true);
330 buttonComposite
.setLayout(layout
);
331 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
332 buttonComposite
.setLayoutData(data
);
334 fTracepointsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
335 fTracepointsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
336 data
= new GridData(GridData
.FILL_HORIZONTAL
);
337 fTracepointsActivateButton
.setLayoutData(data
);
338 fTracepointsActivateButton
.addSelectionListener(new SelectionAdapter() {
340 public void widgetSelected(SelectionEvent e
) {
341 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
345 Group tracepointsGroup
= new Group(tpMainGroup
, SWT
.SHADOW_NONE
);
346 layout
= new GridLayout(1, true);
347 tracepointsGroup
.setLayout(layout
);
348 data
= new GridData(GridData
.FILL_BOTH
);
349 tracepointsGroup
.setLayoutData(data
);
351 new FilteredTree(tracepointsGroup
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.BORDER
, new PatternFilter(), true) {
353 protected TreeViewer
doCreateTreeViewer(Composite aparent
, int style
) {
354 fTracepointsViewer
= new CheckboxTreeViewer(aparent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
355 fTracepointsViewer
.getTree().setToolTipText(Messages
.TraceControl_EnableEventsTracepointTreeTooltip
);
357 fTracepointsViewer
.setContentProvider(new KernelContentProvider());
358 fTracepointsViewer
.setLabelProvider(new KernelLabelProvider());
359 fTracepointsViewer
.addCheckStateListener(new KernelCheckListener());
360 fTracepointsViewer
.setInput(fProviderGroup
);
362 fTracepointsViewer
.getTree().setLayoutData(new GridData(GridData
.FILL_BOTH
));
363 return fTracepointsViewer
;
369 * Creates syscalls group.
371 private void createSysCallsGroup() {
374 Group sysCallsMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
375 sysCallsMainGroup
.setText(Messages
.TraceControl_EnableEventsSyscallName
);
376 sysCallsMainGroup
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
377 layout
= new GridLayout(2, false);
378 sysCallsMainGroup
.setLayout(layout
);
379 data
= new GridData(GridData
.FILL_HORIZONTAL
);
380 sysCallsMainGroup
.setLayoutData(data
);
382 Composite buttonComposite
= new Composite(sysCallsMainGroup
, SWT
.NONE
);
383 layout
= new GridLayout(1, false);
384 buttonComposite
.setLayout(layout
);
385 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
386 buttonComposite
.setLayoutData(data
);
388 fSysCallsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
389 fSysCallsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
390 fSysCallsActivateButton
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
391 fSysCallsActivateButton
.setSelection(false);
392 data
= new GridData(GridData
.FILL_HORIZONTAL
);
393 fSysCallsActivateButton
.setLayoutData(data
);
394 fSysCallsActivateButton
.addSelectionListener(new SelectionAdapter() {
396 public void widgetSelected(SelectionEvent e
) {
397 setKernelEnablements(KernelGroupEnum
.SYSCALLS
);
403 * Creates dynamic probe group.
405 private void createDynamicProbeGroup() {
408 Group probeMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
409 probeMainGroup
.setText(Messages
.TraceControl_EnableEventsProbeGroupName
);
410 layout
= new GridLayout(2, false);
411 probeMainGroup
.setLayout(layout
);
412 data
= new GridData(GridData
.FILL_HORIZONTAL
);
413 probeMainGroup
.setLayoutData(data
);
415 Composite buttonComposite
= new Composite(probeMainGroup
, SWT
.NONE
);
416 layout
= new GridLayout(1, false);
417 buttonComposite
.setLayout(layout
);
418 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
419 buttonComposite
.setLayoutData(data
);
421 fProbeActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
422 fProbeActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
423 fProbeActivateButton
.setSelection(false);
424 data
= new GridData(GridData
.FILL_HORIZONTAL
);
425 fProbeActivateButton
.setLayoutData(data
);
426 fProbeActivateButton
.addSelectionListener(new SelectionAdapter() {
428 public void widgetSelected(SelectionEvent e
) {
429 setKernelEnablements(KernelGroupEnum
.PROBE
);
433 Group probeGroup
= new Group(probeMainGroup
, SWT
.SHADOW_NONE
);
434 layout
= new GridLayout(4, true);
435 probeGroup
.setLayout(layout
);
436 probeGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
438 Label probeNameLabel
= new Label(probeGroup
, SWT
.LEFT
);
439 probeNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
440 data
= new GridData(GridData
.FILL_BOTH
);
441 data
.horizontalSpan
= 1;
442 probeNameLabel
.setLayoutData(data
);
444 fProbeEventNameText
= new Text(probeGroup
, SWT
.LEFT
);
445 fProbeEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeEventNameTooltip
);
447 data
= new GridData(GridData
.FILL_BOTH
);
448 data
.horizontalSpan
= 3;
449 fProbeEventNameText
.setLayoutData(data
);
451 Label probeLabel
= new Label(probeGroup
, SWT
.LEFT
);
452 probeLabel
.setText(Messages
.TraceControl_EnableEventsProbeNameLabel
);
453 data
= new GridData(GridData
.FILL_BOTH
);
454 data
.horizontalSpan
= 1;
455 probeLabel
.setLayoutData(data
);
457 fProbeText
= new Text(probeGroup
, SWT
.LEFT
);
458 fProbeText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
459 data
= new GridData(GridData
.FILL_BOTH
);
460 data
.horizontalSpan
= 3;
461 fProbeText
.setLayoutData(data
);
465 * Creates dynamic function entry/return probe group.
467 private void createDynamicFunctionPropeGroup() {
470 Group functionMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
471 functionMainGroup
.setText(Messages
.TraceControl_EnableEventsFucntionGroupName
);
472 layout
= new GridLayout(2, false);
473 functionMainGroup
.setLayout(layout
);
474 data
= new GridData(GridData
.FILL_HORIZONTAL
);
475 functionMainGroup
.setLayoutData(data
);
477 Composite buttonComposite
= new Composite(functionMainGroup
, SWT
.NONE
);
478 layout
= new GridLayout(1, false);
479 buttonComposite
.setLayout(layout
);
480 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
481 buttonComposite
.setLayoutData(data
);
483 fFunctionActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
484 fFunctionActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
485 fFunctionActivateButton
.setSelection(false);
486 data
= new GridData(GridData
.FILL_HORIZONTAL
);
487 fFunctionActivateButton
.setLayoutData(data
);
488 fFunctionActivateButton
.addSelectionListener(new SelectionAdapter() {
490 public void widgetSelected(SelectionEvent e
) {
491 setKernelEnablements(KernelGroupEnum
.FUNCTION
);
495 Group functionGroup
= new Group(functionMainGroup
, SWT
.SHADOW_NONE
);
496 layout
= new GridLayout(4, true);
497 functionGroup
.setLayout(layout
);
498 functionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
500 Label functionNameLabel
= new Label(functionGroup
, SWT
.LEFT
);
501 functionNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
502 data
= new GridData(GridData
.FILL_BOTH
);
503 data
.horizontalSpan
= 1;
504 functionNameLabel
.setLayoutData(data
);
506 fFunctionEventNameText
= new Text(functionGroup
, SWT
.LEFT
);
507 fFunctionEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsFunctionEventNameTooltip
);
508 data
= new GridData(GridData
.FILL_BOTH
);
509 data
.horizontalSpan
= 3;
510 fFunctionEventNameText
.setLayoutData(data
);
512 Label functionLabel
= new Label(functionGroup
, SWT
.LEFT
);
513 functionLabel
.setText(Messages
.TraceControl_EnableEventsFunctionNameLabel
);
514 data
= new GridData(GridData
.FILL_BOTH
);
515 data
.horizontalSpan
= 1;
516 functionLabel
.setLayoutData(data
);
518 fFunctionText
= new Text(functionGroup
, SWT
.LEFT
);
519 fFunctionText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
520 data
= new GridData(GridData
.FILL_BOTH
);
521 data
.horizontalSpan
= 3;
522 fFunctionText
.setLayoutData(data
);
526 * Enable/selects widgets depending on the group specified.
527 * @param group - group to enable.
529 private void setKernelEnablements(KernelGroupEnum group
) {
530 fTracepointsActivateButton
.setSelection(group
== KernelGroupEnum
.TRACEPOINTS
);
531 fTracepointsViewer
.getTree().setEnabled(group
== KernelGroupEnum
.TRACEPOINTS
);
533 fSysCallsActivateButton
.setSelection(group
== KernelGroupEnum
.SYSCALLS
);
535 fProbeActivateButton
.setSelection(group
== KernelGroupEnum
.PROBE
);
536 fProbeEventNameText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
537 fProbeText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
539 fFunctionActivateButton
.setSelection(group
== KernelGroupEnum
.FUNCTION
);
540 fFunctionEventNameText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
541 fFunctionText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
544 // ------------------------------------------------------------------------
546 // ------------------------------------------------------------------------
548 * Content provider for the tracepoints tree.
550 public static final class KernelContentProvider
extends TraceControlContentProvider
{
552 public Object
[] getChildren(Object parentElement
) {
553 if (parentElement
instanceof TraceProviderGroup
) {
554 List
<ITraceControlComponent
> children
= ((ITraceControlComponent
)parentElement
).getChildren(KernelProviderComponent
.class);
555 return children
.toArray(new ITraceControlComponent
[children
.size()]);
557 if (parentElement
instanceof ITraceControlComponent
) {
558 return ((ITraceControlComponent
)parentElement
).getChildren();
560 return new Object
[0];
565 * Content label for the tracepoints tree.
567 public static final class KernelLabelProvider
extends TraceControlLabelProvider
{
569 public Image
getImage(Object element
) {
573 public String
getText(Object element
) {
574 if ((element
!= null) && (element
instanceof KernelProviderComponent
)) {
575 return Messages
.TraceControl_EnableEventsTracepointTreeAllLabel
;
577 return super.getText(element
);
582 * Check state listener for the tracepoints tree.
584 public final class KernelCheckListener
implements ICheckStateListener
{
586 public void checkStateChanged(CheckStateChangedEvent event
) {
587 if (event
.getChecked()) {
588 if (event
.getElement() instanceof KernelProviderComponent
) {
589 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), true);
592 if (event
.getElement() instanceof KernelProviderComponent
) {
593 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), false);
595 ITraceControlComponent component
= (ITraceControlComponent
) event
.getElement();
596 fTracepointsViewer
.setChecked(component
.getParent(), false);