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
;
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 Object
[] checkedElements
= fTracepointsViewer
.getCheckedElements();
263 for (int i
= 0; i
< checkedElements
.length
; i
++) {
264 ITraceControlComponent component
= (ITraceControlComponent
)checkedElements
[i
];
265 if (component
instanceof BaseEventComponent
) {
266 fSelectedEvents
.add(component
.getName());
269 // verify if all events are selected
271 List
<ITraceControlComponent
> comps
= fProviderGroup
.getChildren(KernelProviderComponent
.class);
272 for (ITraceControlComponent comp
: comps
) {
273 nbEvents
+= comp
.getChildren().length
;
275 fIsAllTracepoints
= (nbEvents
== fSelectedEvents
.size());
278 if (fIsDynamicProbe
) {
279 String temp
= fProbeEventNameText
.getText();
280 if (temp
.isEmpty() ||
281 fProbeText
.getText().matches("\\s*") || //$NON-NLS-1$
282 (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
283 MessageDialog
.openError(getShell(),
284 Messages
.TraceControl_EnableEventsDialogTitle
,
285 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
290 fProbeEventName
= temp
;
291 // fProbeString will be validated by lttng-tools
292 fProbeString
= fProbeText
.getText();
295 // initialize function string
296 fFunctionEventName
= null;
297 fFunctionString
= null;
298 if (fIsDynamicFunctionProbe
) {
299 String functionTemp
= fFunctionEventNameText
.getText();
300 if (functionTemp
.isEmpty() ||
301 functionTemp
.matches("\\s*") || //$NON-NLS-1$
302 (!functionTemp
.matches("^[\\s]{0,}$") && !functionTemp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$
303 MessageDialog
.openError(getShell(),
304 Messages
.TraceControl_EnableEventsDialogTitle
,
305 Messages
.TraceControl_InvalidProbeNameError
+ " (" + functionTemp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
310 fFunctionEventName
= functionTemp
;
311 // fFunctionString will be validated by lttng-tools
312 fFunctionString
= fFunctionText
.getText();
319 * Creates tracepoints group.
321 private void createTracepointsGroup() {
325 Group tpMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
326 tpMainGroup
.setText(Messages
.TraceControl_EnableEventsTracepointGroupName
);
327 layout
= new GridLayout(2, false);
328 tpMainGroup
.setLayout(layout
);
329 data
= new GridData(GridData
.FILL_BOTH
);
330 tpMainGroup
.setLayoutData(data
);
332 Composite buttonComposite
= new Composite(tpMainGroup
, SWT
.NONE
);
333 layout
= new GridLayout(1, true);
334 buttonComposite
.setLayout(layout
);
335 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
336 buttonComposite
.setLayoutData(data
);
338 fTracepointsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
339 fTracepointsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
340 data
= new GridData(GridData
.FILL_HORIZONTAL
);
341 fTracepointsActivateButton
.setLayoutData(data
);
342 fTracepointsActivateButton
.addSelectionListener(new SelectionAdapter() {
344 public void widgetSelected(SelectionEvent e
) {
345 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
349 Group tracepointsGroup
= new Group(tpMainGroup
, SWT
.SHADOW_NONE
);
350 layout
= new GridLayout(1, true);
351 tracepointsGroup
.setLayout(layout
);
352 data
= new GridData(GridData
.FILL_BOTH
);
353 tracepointsGroup
.setLayoutData(data
);
355 new FilteredTree(tracepointsGroup
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.BORDER
, new PatternFilter(), true) {
357 protected TreeViewer
doCreateTreeViewer(Composite aparent
, int style
) {
358 fTracepointsViewer
= new CheckboxTreeViewer(aparent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
359 fTracepointsViewer
.getTree().setToolTipText(Messages
.TraceControl_EnableEventsTracepointTreeTooltip
);
361 fTracepointsViewer
.setContentProvider(new KernelContentProvider());
362 fTracepointsViewer
.setLabelProvider(new KernelLabelProvider());
363 fTracepointsViewer
.addCheckStateListener(new KernelCheckListener());
364 fTracepointsViewer
.setInput(fProviderGroup
);
366 fTracepointsViewer
.getTree().setLayoutData(new GridData(GridData
.FILL_BOTH
));
367 return fTracepointsViewer
;
373 * Creates syscalls group.
375 private void createSysCallsGroup() {
378 Group sysCallsMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
379 sysCallsMainGroup
.setText(Messages
.TraceControl_EnableEventsSyscallName
);
380 sysCallsMainGroup
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
381 layout
= new GridLayout(2, false);
382 sysCallsMainGroup
.setLayout(layout
);
383 data
= new GridData(GridData
.FILL_HORIZONTAL
);
384 sysCallsMainGroup
.setLayoutData(data
);
386 Composite buttonComposite
= new Composite(sysCallsMainGroup
, SWT
.NONE
);
387 layout
= new GridLayout(1, false);
388 buttonComposite
.setLayout(layout
);
389 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
390 buttonComposite
.setLayoutData(data
);
392 fSysCallsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
393 fSysCallsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
394 fSysCallsActivateButton
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
395 fSysCallsActivateButton
.setSelection(false);
396 data
= new GridData(GridData
.FILL_HORIZONTAL
);
397 fSysCallsActivateButton
.setLayoutData(data
);
398 fSysCallsActivateButton
.addSelectionListener(new SelectionAdapter() {
400 public void widgetSelected(SelectionEvent e
) {
401 setKernelEnablements(KernelGroupEnum
.SYSCALLS
);
407 * Creates dynamic probe group.
409 private void createDynamicProbeGroup() {
412 Group probeMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
413 probeMainGroup
.setText(Messages
.TraceControl_EnableEventsProbeGroupName
);
414 layout
= new GridLayout(2, false);
415 probeMainGroup
.setLayout(layout
);
416 data
= new GridData(GridData
.FILL_HORIZONTAL
);
417 probeMainGroup
.setLayoutData(data
);
419 Composite buttonComposite
= new Composite(probeMainGroup
, SWT
.NONE
);
420 layout
= new GridLayout(1, false);
421 buttonComposite
.setLayout(layout
);
422 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
423 buttonComposite
.setLayoutData(data
);
425 fProbeActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
426 fProbeActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
427 fProbeActivateButton
.setSelection(false);
428 data
= new GridData(GridData
.FILL_HORIZONTAL
);
429 fProbeActivateButton
.setLayoutData(data
);
430 fProbeActivateButton
.addSelectionListener(new SelectionAdapter() {
432 public void widgetSelected(SelectionEvent e
) {
433 setKernelEnablements(KernelGroupEnum
.PROBE
);
437 Group probeGroup
= new Group(probeMainGroup
, SWT
.SHADOW_NONE
);
438 layout
= new GridLayout(4, true);
439 probeGroup
.setLayout(layout
);
440 probeGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
442 Label probeNameLabel
= new Label(probeGroup
, SWT
.LEFT
);
443 probeNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
444 data
= new GridData(GridData
.FILL_BOTH
);
445 data
.horizontalSpan
= 1;
446 probeNameLabel
.setLayoutData(data
);
448 fProbeEventNameText
= new Text(probeGroup
, SWT
.LEFT
);
449 fProbeEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeEventNameTooltip
);
451 data
= new GridData(GridData
.FILL_BOTH
);
452 data
.horizontalSpan
= 3;
453 fProbeEventNameText
.setLayoutData(data
);
455 Label probeLabel
= new Label(probeGroup
, SWT
.LEFT
);
456 probeLabel
.setText(Messages
.TraceControl_EnableEventsProbeNameLabel
);
457 data
= new GridData(GridData
.FILL_BOTH
);
458 data
.horizontalSpan
= 1;
459 probeLabel
.setLayoutData(data
);
461 fProbeText
= new Text(probeGroup
, SWT
.LEFT
);
462 fProbeText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
463 data
= new GridData(GridData
.FILL_BOTH
);
464 data
.horizontalSpan
= 3;
465 fProbeText
.setLayoutData(data
);
469 * Creates dynamic function entry/return probe group.
471 private void createDynamicFunctionPropeGroup() {
474 Group functionMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
475 functionMainGroup
.setText(Messages
.TraceControl_EnableEventsFucntionGroupName
);
476 layout
= new GridLayout(2, false);
477 functionMainGroup
.setLayout(layout
);
478 data
= new GridData(GridData
.FILL_HORIZONTAL
);
479 functionMainGroup
.setLayoutData(data
);
481 Composite buttonComposite
= new Composite(functionMainGroup
, SWT
.NONE
);
482 layout
= new GridLayout(1, false);
483 buttonComposite
.setLayout(layout
);
484 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
485 buttonComposite
.setLayoutData(data
);
487 fFunctionActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
488 fFunctionActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
489 fFunctionActivateButton
.setSelection(false);
490 data
= new GridData(GridData
.FILL_HORIZONTAL
);
491 fFunctionActivateButton
.setLayoutData(data
);
492 fFunctionActivateButton
.addSelectionListener(new SelectionAdapter() {
494 public void widgetSelected(SelectionEvent e
) {
495 setKernelEnablements(KernelGroupEnum
.FUNCTION
);
499 Group functionGroup
= new Group(functionMainGroup
, SWT
.SHADOW_NONE
);
500 layout
= new GridLayout(4, true);
501 functionGroup
.setLayout(layout
);
502 functionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
504 Label functionNameLabel
= new Label(functionGroup
, SWT
.LEFT
);
505 functionNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
506 data
= new GridData(GridData
.FILL_BOTH
);
507 data
.horizontalSpan
= 1;
508 functionNameLabel
.setLayoutData(data
);
510 fFunctionEventNameText
= new Text(functionGroup
, SWT
.LEFT
);
511 fFunctionEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsFunctionEventNameTooltip
);
512 data
= new GridData(GridData
.FILL_BOTH
);
513 data
.horizontalSpan
= 3;
514 fFunctionEventNameText
.setLayoutData(data
);
516 Label functionLabel
= new Label(functionGroup
, SWT
.LEFT
);
517 functionLabel
.setText(Messages
.TraceControl_EnableEventsFunctionNameLabel
);
518 data
= new GridData(GridData
.FILL_BOTH
);
519 data
.horizontalSpan
= 1;
520 functionLabel
.setLayoutData(data
);
522 fFunctionText
= new Text(functionGroup
, SWT
.LEFT
);
523 fFunctionText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
524 data
= new GridData(GridData
.FILL_BOTH
);
525 data
.horizontalSpan
= 3;
526 fFunctionText
.setLayoutData(data
);
530 * Enable/selects widgets depending on the group specified.
531 * @param group - group to enable.
533 private void setKernelEnablements(KernelGroupEnum group
) {
534 fTracepointsActivateButton
.setSelection(group
== KernelGroupEnum
.TRACEPOINTS
);
535 fTracepointsViewer
.getTree().setEnabled(group
== KernelGroupEnum
.TRACEPOINTS
);
537 fSysCallsActivateButton
.setSelection(group
== KernelGroupEnum
.SYSCALLS
);
539 fProbeActivateButton
.setSelection(group
== KernelGroupEnum
.PROBE
);
540 fProbeEventNameText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
541 fProbeText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
543 fFunctionActivateButton
.setSelection(group
== KernelGroupEnum
.FUNCTION
);
544 fFunctionEventNameText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
545 fFunctionText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
548 // ------------------------------------------------------------------------
550 // ------------------------------------------------------------------------
552 * Content provider for the tracepoints tree.
554 public static final class KernelContentProvider
extends TraceControlContentProvider
{
556 public Object
[] getChildren(Object parentElement
) {
557 if (parentElement
instanceof TraceProviderGroup
) {
558 List
<ITraceControlComponent
> children
= ((ITraceControlComponent
)parentElement
).getChildren(KernelProviderComponent
.class);
559 return children
.toArray(new ITraceControlComponent
[children
.size()]);
561 if (parentElement
instanceof ITraceControlComponent
) {
562 return ((ITraceControlComponent
)parentElement
).getChildren();
564 return new Object
[0];
569 * Content label for the tracepoints tree.
571 public static final class KernelLabelProvider
extends TraceControlLabelProvider
{
573 public Image
getImage(Object element
) {
577 public String
getText(Object element
) {
578 if ((element
!= null) && (element
instanceof KernelProviderComponent
)) {
579 return Messages
.TraceControl_EnableEventsTracepointTreeAllLabel
;
581 return super.getText(element
);
586 * Check state listener for the tracepoints tree.
588 public final class KernelCheckListener
implements ICheckStateListener
{
590 public void checkStateChanged(CheckStateChangedEvent event
) {
591 if (event
.getChecked()) {
592 if (event
.getElement() instanceof KernelProviderComponent
) {
593 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), true);
596 if (event
.getElement() instanceof KernelProviderComponent
) {
597 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), false);
599 ITraceControlComponent component
= (ITraceControlComponent
) event
.getElement();
600 fTracepointsViewer
.setChecked(component
.getParent(), false);