1 /**********************************************************************
2 * Copyright (c) 2012 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 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isTracpoints()
167 public boolean isTracepoints() {
168 return fIsTracepoints
;
172 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isAllTracePoints()
175 public boolean isAllTracePoints() {
176 return fIsAllTracepoints
;
181 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isSysCalls()
184 public boolean isSysCalls() {
189 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isAllSysCalls()
192 public boolean isAllSysCalls() {
197 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getEventNames()
200 public List
<String
> getEventNames() {
201 return new ArrayList
<String
>(fSelectedEvents
);
205 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isDynamicProbe()
208 public boolean isDynamicProbe() {
209 return fIsDynamicProbe
;
213 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getProbeName()
216 public String
getProbeName() {
221 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getProbeEventName()
224 public String
getProbeEventName() {
225 return fProbeEventName
;
230 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isDynamicFunctionProbe()
233 public boolean isDynamicFunctionProbe() {
234 return fIsDynamicFunctionProbe
;
238 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getFunctionEventName()
241 public String
getFunctionEventName() {
242 return fFunctionEventName
;
246 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getFunction()
249 public String
getFunction() {
250 return fFunctionString
;
253 // ------------------------------------------------------------------------
255 // ------------------------------------------------------------------------
257 * Creates the composite content
259 public void createContent() {
262 createTracepointsGroup();
265 createSysCallsGroup();
267 // Dynamic Probe Group
268 createDynamicProbeGroup();
270 // Dynamic Function Probe Group
271 createDynamicFunctionPropeGroup();
273 // Set default enablements
274 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
278 * Validates the kernel composite input data.
279 * @return true if configured data is valid and can be retrieved.
281 public boolean isValid() {
282 fIsTracepoints
= fTracepointsActivateButton
.getSelection();
283 fIsSysCalls
= fSysCallsActivateButton
.getSelection();
284 fIsDynamicProbe
= fProbeActivateButton
.getSelection();
285 fIsDynamicFunctionProbe
= fFunctionActivateButton
.getSelection();
287 // initialize tracepoint fields
288 fIsAllTracepoints
= false;
289 fSelectedEvents
= new ArrayList
<String
>();
291 if (fIsTracepoints
) {
292 List
<ITraceControlComponent
> comps
= fProviderGroup
.getChildren(KernelProviderComponent
.class);
293 fIsAllTracepoints
= fTracepointsViewer
.getChecked(comps
.get(0));
295 Object
[] checkedElements
= fTracepointsViewer
.getCheckedElements();
296 for (int i
= 0; i
< checkedElements
.length
; i
++) {
297 ITraceControlComponent component
= (ITraceControlComponent
)checkedElements
[i
];
298 if (component
instanceof BaseEventComponent
) {
299 fSelectedEvents
.add(component
.getName());
304 if (fIsDynamicProbe
) {
305 String temp
= fProbeEventNameText
.getText();
306 if (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
307 MessageDialog
.openError(getShell(),
308 Messages
.TraceControl_EnableEventsDialogTitle
,
309 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
314 if(!fProbeText
.getText().matches("\\s*")) { //$NON-NLS-1$
315 fProbeEventName
= temp
;
316 // fProbeString will be validated by lttng-tools
317 fProbeString
= fProbeText
.getText();
321 // initialize function string
322 fFunctionEventName
= null;
323 fFunctionString
= null;
324 if (fIsDynamicFunctionProbe
) {
325 String functionTemp
= fFunctionEventNameText
.getText();
326 if (!functionTemp
.matches("^[\\s]{0,}$") && !functionTemp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
327 MessageDialog
.openError(getShell(),
328 Messages
.TraceControl_EnableEventsDialogTitle
,
329 Messages
.TraceControl_InvalidProbeNameError
+ " (" + functionTemp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
334 if(!fFunctionText
.getText().matches("\\s*")) { //$NON-NLS-1$
335 fFunctionEventName
= functionTemp
;
336 // fFunctionString will be validated by lttng-tools
337 fFunctionString
= fFunctionText
.getText();
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 fTracepointsViewer
= new CheckboxTreeViewer(tracepointsGroup
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
382 fTracepointsViewer
.getTree().setToolTipText(Messages
.TraceControl_EnableEventsTracepointTreeTooltip
);
384 fTracepointsViewer
.setContentProvider(new KernelContentProvider());
385 fTracepointsViewer
.setLabelProvider(new KernelLabelProvider());
386 fTracepointsViewer
.addCheckStateListener(new KernelCheckListener());
387 fTracepointsViewer
.setInput(fProviderGroup
);
389 fTracepointsViewer
.getTree().setLayoutData(new GridData(GridData
.FILL_BOTH
));
393 * Creates syscalls group.
395 private void createSysCallsGroup() {
398 Group sysCallsMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
399 sysCallsMainGroup
.setText(Messages
.TraceControl_EnableEventsSyscallName
);
400 sysCallsMainGroup
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
401 layout
= new GridLayout(2, false);
402 sysCallsMainGroup
.setLayout(layout
);
403 data
= new GridData(GridData
.FILL_HORIZONTAL
);
404 sysCallsMainGroup
.setLayoutData(data
);
406 Composite buttonComposite
= new Composite(sysCallsMainGroup
, SWT
.NONE
);
407 layout
= new GridLayout(1, false);
408 buttonComposite
.setLayout(layout
);
409 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
410 buttonComposite
.setLayoutData(data
);
412 fSysCallsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
413 fSysCallsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
414 fSysCallsActivateButton
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
415 fSysCallsActivateButton
.setSelection(false);
416 data
= new GridData(GridData
.FILL_HORIZONTAL
);
417 fSysCallsActivateButton
.setLayoutData(data
);
418 fSysCallsActivateButton
.addSelectionListener(new SelectionAdapter() {
420 public void widgetSelected(SelectionEvent e
) {
421 setKernelEnablements(KernelGroupEnum
.SYSCALLS
);
427 * Creates dynamic probe group.
429 private void createDynamicProbeGroup() {
432 Group probeMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
433 probeMainGroup
.setText(Messages
.TraceControl_EnableEventsProbeGroupName
);
434 layout
= new GridLayout(2, false);
435 probeMainGroup
.setLayout(layout
);
436 data
= new GridData(GridData
.FILL_HORIZONTAL
);
437 probeMainGroup
.setLayoutData(data
);
439 Composite buttonComposite
= new Composite(probeMainGroup
, SWT
.NONE
);
440 layout
= new GridLayout(1, false);
441 buttonComposite
.setLayout(layout
);
442 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
443 buttonComposite
.setLayoutData(data
);
445 fProbeActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
446 fProbeActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
447 fProbeActivateButton
.setSelection(false);
448 data
= new GridData(GridData
.FILL_HORIZONTAL
);
449 fProbeActivateButton
.setLayoutData(data
);
450 fProbeActivateButton
.addSelectionListener(new SelectionAdapter() {
452 public void widgetSelected(SelectionEvent e
) {
453 setKernelEnablements(KernelGroupEnum
.PROBE
);
457 Group probeGroup
= new Group(probeMainGroup
, SWT
.SHADOW_NONE
);
458 layout
= new GridLayout(4, true);
459 probeGroup
.setLayout(layout
);
460 probeGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
462 Label probeNameLabel
= new Label(probeGroup
, SWT
.LEFT
);
463 probeNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
464 data
= new GridData(GridData
.FILL_BOTH
);
465 data
.horizontalSpan
= 1;
466 probeNameLabel
.setLayoutData(data
);
468 fProbeEventNameText
= new Text(probeGroup
, SWT
.LEFT
);
469 fProbeEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeEventNameTooltip
);
471 data
= new GridData(GridData
.FILL_BOTH
);
472 data
.horizontalSpan
= 3;
473 fProbeEventNameText
.setLayoutData(data
);
475 Label probeLabel
= new Label(probeGroup
, SWT
.LEFT
);
476 probeLabel
.setText(Messages
.TraceControl_EnableEventsProbeNameLabel
);
477 data
= new GridData(GridData
.FILL_BOTH
);
478 data
.horizontalSpan
= 1;
479 probeLabel
.setLayoutData(data
);
481 fProbeText
= new Text(probeGroup
, SWT
.LEFT
);
482 fProbeText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
483 data
= new GridData(GridData
.FILL_BOTH
);
484 data
.horizontalSpan
= 3;
485 fProbeText
.setLayoutData(data
);
489 * Creates dynamic function entry/return probe group.
491 private void createDynamicFunctionPropeGroup() {
494 Group functionMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
495 functionMainGroup
.setText(Messages
.TraceControl_EnableEventsFucntionGroupName
);
496 layout
= new GridLayout(2, false);
497 functionMainGroup
.setLayout(layout
);
498 data
= new GridData(GridData
.FILL_HORIZONTAL
);
499 functionMainGroup
.setLayoutData(data
);
501 Composite buttonComposite
= new Composite(functionMainGroup
, SWT
.NONE
);
502 layout
= new GridLayout(1, false);
503 buttonComposite
.setLayout(layout
);
504 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
505 buttonComposite
.setLayoutData(data
);
507 fFunctionActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
508 fFunctionActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
509 fFunctionActivateButton
.setSelection(false);
510 data
= new GridData(GridData
.FILL_HORIZONTAL
);
511 fFunctionActivateButton
.setLayoutData(data
);
512 fFunctionActivateButton
.addSelectionListener(new SelectionAdapter() {
514 public void widgetSelected(SelectionEvent e
) {
515 setKernelEnablements(KernelGroupEnum
.FUNCTION
);
519 Group functionGroup
= new Group(functionMainGroup
, SWT
.SHADOW_NONE
);
520 layout
= new GridLayout(4, true);
521 functionGroup
.setLayout(layout
);
522 functionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
524 Label functionNameLabel
= new Label(functionGroup
, SWT
.LEFT
);
525 functionNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
526 data
= new GridData(GridData
.FILL_BOTH
);
527 data
.horizontalSpan
= 1;
528 functionNameLabel
.setLayoutData(data
);
530 fFunctionEventNameText
= new Text(functionGroup
, SWT
.LEFT
);
531 fFunctionEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsFunctionEventNameTooltip
);
532 data
= new GridData(GridData
.FILL_BOTH
);
533 data
.horizontalSpan
= 3;
534 fFunctionEventNameText
.setLayoutData(data
);
536 Label functionLabel
= new Label(functionGroup
, SWT
.LEFT
);
537 functionLabel
.setText(Messages
.TraceControl_EnableEventsFunctionNameLabel
);
538 data
= new GridData(GridData
.FILL_BOTH
);
539 data
.horizontalSpan
= 1;
540 functionLabel
.setLayoutData(data
);
542 fFunctionText
= new Text(functionGroup
, SWT
.LEFT
);
543 fFunctionText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
544 data
= new GridData(GridData
.FILL_BOTH
);
545 data
.horizontalSpan
= 3;
546 fFunctionText
.setLayoutData(data
);
550 * Enable/selects widgets depending on the group specified.
551 * @param group - group to enable.
553 private void setKernelEnablements(KernelGroupEnum group
) {
554 fTracepointsActivateButton
.setSelection(group
== KernelGroupEnum
.TRACEPOINTS
);
555 fTracepointsViewer
.getTree().setEnabled(group
== KernelGroupEnum
.TRACEPOINTS
);
557 fSysCallsActivateButton
.setSelection(group
== KernelGroupEnum
.SYSCALLS
);
559 fProbeActivateButton
.setSelection(group
== KernelGroupEnum
.PROBE
);
560 fProbeEventNameText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
561 fProbeText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
563 fFunctionActivateButton
.setSelection(group
== KernelGroupEnum
.FUNCTION
);
564 fFunctionEventNameText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
565 fFunctionText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
568 // ------------------------------------------------------------------------
570 // ------------------------------------------------------------------------
572 * Content provider for the tracepoints tree.
574 final static public class KernelContentProvider
extends TraceControlContentProvider
{
576 public Object
[] getChildren(Object parentElement
) {
577 if (parentElement
instanceof TraceProviderGroup
) {
578 List
<ITraceControlComponent
> children
= ((ITraceControlComponent
)parentElement
).getChildren(KernelProviderComponent
.class);
579 return children
.toArray(new ITraceControlComponent
[children
.size()]);
581 if (parentElement
instanceof ITraceControlComponent
) {
582 return ((ITraceControlComponent
)parentElement
).getChildren();
584 return new Object
[0];
589 * Content label for the tracepoints tree.
591 final static public class KernelLabelProvider
extends TraceControlLabelProvider
{
593 public Image
getImage(Object element
) {
597 public String
getText(Object element
) {
598 if ((element
!= null) && (element
instanceof KernelProviderComponent
)) {
599 return Messages
.TraceControl_EnableEventsTracepointTreeAllLabel
;
601 return super.getText(element
);
606 * Check state listener for the tracepoints tree.
608 final public class KernelCheckListener
implements ICheckStateListener
{
610 public void checkStateChanged(CheckStateChangedEvent event
) {
611 if (event
.getChecked()) {
612 if (event
.getElement() instanceof KernelProviderComponent
) {
613 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), true);
616 if (event
.getElement() instanceof KernelProviderComponent
) {
617 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), false);
619 ITraceControlComponent component
= (ITraceControlComponent
) event
.getElement();
620 fTracepointsViewer
.setChecked(component
.getParent(), false);