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
.lttng
.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
.lttng
.ui
.views
.control
.Messages
;
22 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.TraceControlContentProvider
;
23 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.TraceControlLabelProvider
;
24 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
25 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.impl
.BaseEventComponent
;
26 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.impl
.KernelProviderComponent
;
27 import org
.eclipse
.linuxtools
.internal
.lttng
.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
;
41 * <b><u>EnableKernelEventsComposite</u></b>
43 * A composite for collecting information about kernel events to be enabled.
46 public class EnableKernelEventComposite
extends Composite
implements IEnableKernelEvents
{
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
51 private enum KernelGroupEnum
{ TRACEPOINTS
, SYSCALLS
, PROBE
, FUNCTION
};
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 * A button to enable/disable the tracepoints group
60 private Button fTracepointsActivateButton
;
62 * A tree viewer for displaying and selection of available tracepoints.
64 private CheckboxTreeViewer fTracepointsViewer
;
66 * A button to enable/disable the syscalls group
68 private Button fSysCallsActivateButton
;
70 * A button to enable or disable the dynamic probe group.
72 private Button fProbeActivateButton
;
74 * The text field for the event name for the dynamic probe.
76 private Text fProbeEventNameText
;
78 * The text field for the dynamic probe.
80 private Text fProbeText
;
82 * A button to enable or disable the dynamic function probe group.
84 private Button fFunctionActivateButton
;
86 * The text field for the event name for the dynamic probe.
88 private Text fFunctionEventNameText
;
90 * The text field for the dynamic function entry/return probe.
92 private Text fFunctionText
;
94 * The referenced trace provider group containing the kernel provider
95 * component which contains a list of available tracepoints.
97 private TraceProviderGroup fProviderGroup
;
99 * The flag indicating that tracepoints are selected.
101 private boolean fIsTracepoints
;
103 * The flag indicating that all tracepoints are selected.
105 private boolean fIsAllTracepoints
;
107 * The flag indicating that syscalls are selected.
109 private boolean fIsSysCalls
;
111 * The list of tracepoints to be enabled.
113 private List
<String
> fSelectedEvents
;
115 * The flag indicating that dynamic probe is selected.
117 private boolean fIsDynamicProbe
;
119 * The event name of the dynamic probe.
121 private String fProbeEventName
;
125 private String fProbeString
;
127 * The flag indicating that the dynamic function probe is selected.
129 private boolean fIsDynamicFunctionProbe
;
131 * The event name of the dynamic function entry/return probe.
133 private String fFunctionEventName
;
135 * The dynamic function entry/return probe.
137 private String fFunctionString
;
139 // ------------------------------------------------------------------------
141 // ------------------------------------------------------------------------
143 public EnableKernelEventComposite(Composite parent
, int style
, TraceProviderGroup providerGroup
) {
144 super(parent
, style
);
145 fProviderGroup
= providerGroup
;
148 // ------------------------------------------------------------------------
150 // ------------------------------------------------------------------------
153 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableKernelEvents#isTracpoints()
156 public boolean isTracepoints() {
157 return fIsTracepoints
;
161 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableKernelEvents#isAllTracePoints()
164 public boolean isAllTracePoints() {
165 return fIsAllTracepoints
;
170 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableKernelEvents#isSysCalls()
173 public boolean isSysCalls() {
178 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableKernelEvents#isAllSysCalls()
181 public boolean isAllSysCalls() {
186 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableKernelEvents#getEventNames()
189 public List
<String
> getEventNames() {
190 return new ArrayList
<String
>(fSelectedEvents
);
194 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableKernelEvents#isDynamicProbe()
197 public boolean isDynamicProbe() {
198 return fIsDynamicProbe
;
202 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableKernelEvents#getProbeName()
205 public String
getProbeName() {
210 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableKernelEvents#getProbeEventName()
213 public String
getProbeEventName() {
214 return fProbeEventName
;
219 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableKernelEvents#isDynamicFunctionProbe()
222 public boolean isDynamicFunctionProbe() {
223 return fIsDynamicFunctionProbe
;
227 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableKernelEvents#getFunctionEventName()
230 public String
getFunctionEventName() {
231 return fFunctionEventName
;
235 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableKernelEvents#getFunction()
238 public String
getFunction() {
239 return fFunctionString
;
242 // ------------------------------------------------------------------------
244 // ------------------------------------------------------------------------
246 * Creates the composite content
248 public void createContent() {
251 createTracepointsGroup();
254 createSysCallsGroup();
256 // Dynamic Probe Group
257 createDynamicProbeGroup();
259 // Dynamic Function Probe Group
260 createDynamicFunctionPropeGroup();
262 // Set default enablements
263 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
267 * Validates the kernel composite input data.
268 * @return true if configured data is valid and can be retrieved.
270 public boolean isValid() {
271 fIsTracepoints
= fTracepointsActivateButton
.getSelection();
272 fIsSysCalls
= fSysCallsActivateButton
.getSelection();
273 fIsDynamicProbe
= fProbeActivateButton
.getSelection();
274 fIsDynamicFunctionProbe
= fFunctionActivateButton
.getSelection();
276 List
<ITraceControlComponent
> comps
= fProviderGroup
.getChildren(KernelProviderComponent
.class);
277 fIsAllTracepoints
= fTracepointsViewer
.getChecked(comps
.get(0));
279 Object
[] checkedElements
= fTracepointsViewer
.getCheckedElements();
280 fSelectedEvents
= new ArrayList
<String
>();
281 for (int i
= 0; i
< checkedElements
.length
; i
++) {
282 ITraceControlComponent component
= (ITraceControlComponent
)checkedElements
[i
];
283 if (component
instanceof BaseEventComponent
) {
284 fSelectedEvents
.add(component
.getName());
288 // initialize probe string
289 fProbeEventName
= null;
291 String temp
= fProbeEventNameText
.getText();
292 if (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
293 MessageDialog
.openError(getShell(),
294 Messages
.TraceControl_EnableEventsDialogTitle
,
295 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
300 if(!fProbeText
.getText().matches("\\s*")) { //$NON-NLS-1$
301 fProbeEventName
= temp
;
302 // fProbeString will be validated by lttng-tools
303 fProbeString
= fProbeText
.getText();
306 // initialize function string
307 fFunctionEventName
= null;
308 fFunctionString
= null;
310 temp
= fFunctionEventNameText
.getText();
311 if (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
312 MessageDialog
.openError(getShell(),
313 Messages
.TraceControl_EnableEventsDialogTitle
,
314 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
319 if(!fFunctionText
.getText().matches("\\s*")) { //$NON-NLS-1$
320 fFunctionEventName
= temp
;
321 // fFunctionString will be validated by lttng-tools
322 fFunctionString
= fFunctionText
.getText();
329 * Creates tracepoints group.
331 private void createTracepointsGroup() {
335 Group tpMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
336 tpMainGroup
.setText(Messages
.TraceControl_EnableEventsTracepointGroupName
);
337 layout
= new GridLayout(2, false);
338 tpMainGroup
.setLayout(layout
);
339 data
= new GridData(GridData
.FILL_BOTH
);
340 tpMainGroup
.setLayoutData(data
);
342 Composite buttonComposite
= new Composite(tpMainGroup
, SWT
.NONE
);
343 layout
= new GridLayout(1, true);
344 buttonComposite
.setLayout(layout
);
345 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
346 buttonComposite
.setLayoutData(data
);
348 fTracepointsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
349 fTracepointsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
350 data
= new GridData(GridData
.FILL_HORIZONTAL
);
351 fTracepointsActivateButton
.setLayoutData(data
);
352 fTracepointsActivateButton
.addSelectionListener(new SelectionAdapter() {
354 public void widgetSelected(SelectionEvent e
) {
355 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
359 Group tracepointsGroup
= new Group(tpMainGroup
, SWT
.SHADOW_NONE
);
360 layout
= new GridLayout(1, true);
361 tracepointsGroup
.setLayout(layout
);
362 data
= new GridData(GridData
.FILL_BOTH
);
363 tracepointsGroup
.setLayoutData(data
);
365 fTracepointsViewer
= new CheckboxTreeViewer(tracepointsGroup
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
366 fTracepointsViewer
.getTree().setToolTipText(Messages
.TraceControl_EnableEventsTracepointTreeTooltip
);
368 fTracepointsViewer
.setContentProvider(new KernelContentProvider());
369 fTracepointsViewer
.setLabelProvider(new KernelLabelProvider());
370 fTracepointsViewer
.addCheckStateListener(new KernelCheckListener());
371 fTracepointsViewer
.setInput(fProviderGroup
);
373 fTracepointsViewer
.getTree().setLayoutData(new GridData(GridData
.FILL_BOTH
));
377 * Creates syscalls group.
379 private void createSysCallsGroup() {
382 Group sysCallsMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
383 sysCallsMainGroup
.setText(Messages
.TraceControl_EnableEventsSyscallName
);
384 sysCallsMainGroup
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
385 layout
= new GridLayout(2, false);
386 sysCallsMainGroup
.setLayout(layout
);
387 data
= new GridData(GridData
.FILL_HORIZONTAL
);
388 sysCallsMainGroup
.setLayoutData(data
);
390 Composite buttonComposite
= new Composite(sysCallsMainGroup
, SWT
.NONE
);
391 layout
= new GridLayout(1, false);
392 buttonComposite
.setLayout(layout
);
393 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
394 buttonComposite
.setLayoutData(data
);
396 fSysCallsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
397 fSysCallsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
398 fSysCallsActivateButton
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
399 fSysCallsActivateButton
.setSelection(false);
400 data
= new GridData(GridData
.FILL_HORIZONTAL
);
401 fSysCallsActivateButton
.setLayoutData(data
);
402 fSysCallsActivateButton
.addSelectionListener(new SelectionAdapter() {
404 public void widgetSelected(SelectionEvent e
) {
405 setKernelEnablements(KernelGroupEnum
.SYSCALLS
);
411 * Creates dynamic probe group.
413 private void createDynamicProbeGroup() {
416 Group probeMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
417 probeMainGroup
.setText(Messages
.TraceControl_EnableEventsProbeGroupName
);
418 layout
= new GridLayout(2, false);
419 probeMainGroup
.setLayout(layout
);
420 data
= new GridData(GridData
.FILL_HORIZONTAL
);
421 probeMainGroup
.setLayoutData(data
);
423 Composite buttonComposite
= new Composite(probeMainGroup
, SWT
.NONE
);
424 layout
= new GridLayout(1, false);
425 buttonComposite
.setLayout(layout
);
426 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
427 buttonComposite
.setLayoutData(data
);
429 fProbeActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
430 fProbeActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
431 fProbeActivateButton
.setSelection(false);
432 data
= new GridData(GridData
.FILL_HORIZONTAL
);
433 fProbeActivateButton
.setLayoutData(data
);
434 fProbeActivateButton
.addSelectionListener(new SelectionAdapter() {
436 public void widgetSelected(SelectionEvent e
) {
437 setKernelEnablements(KernelGroupEnum
.PROBE
);
441 Group probeGroup
= new Group(probeMainGroup
, SWT
.SHADOW_NONE
);
442 layout
= new GridLayout(4, true);
443 probeGroup
.setLayout(layout
);
444 probeGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
446 Label probeNameLabel
= new Label(probeGroup
, SWT
.LEFT
);
447 probeNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
448 data
= new GridData(GridData
.FILL_BOTH
);
449 data
.horizontalSpan
= 1;
450 probeNameLabel
.setLayoutData(data
);
452 fProbeEventNameText
= new Text(probeGroup
, SWT
.LEFT
);
453 fProbeEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeEventNameTooltip
);
455 data
= new GridData(GridData
.FILL_BOTH
);
456 data
.horizontalSpan
= 3;
457 fProbeEventNameText
.setLayoutData(data
);
459 Label probeLabel
= new Label(probeGroup
, SWT
.LEFT
);
460 probeLabel
.setText(Messages
.TraceControl_EnableEventsProbeNameLabel
);
461 data
= new GridData(GridData
.FILL_BOTH
);
462 data
.horizontalSpan
= 1;
463 probeLabel
.setLayoutData(data
);
465 fProbeText
= new Text(probeGroup
, SWT
.LEFT
);
466 fProbeText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
467 data
= new GridData(GridData
.FILL_BOTH
);
468 data
.horizontalSpan
= 3;
469 fProbeText
.setLayoutData(data
);
473 * Creates dynamic function entry/return probe group.
475 private void createDynamicFunctionPropeGroup() {
478 Group functionMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
479 functionMainGroup
.setText(Messages
.TraceControl_EnableEventsFucntionGroupName
);
480 layout
= new GridLayout(2, false);
481 functionMainGroup
.setLayout(layout
);
482 data
= new GridData(GridData
.FILL_HORIZONTAL
);
483 functionMainGroup
.setLayoutData(data
);
485 Composite buttonComposite
= new Composite(functionMainGroup
, SWT
.NONE
);
486 layout
= new GridLayout(1, false);
487 buttonComposite
.setLayout(layout
);
488 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
489 buttonComposite
.setLayoutData(data
);
491 fFunctionActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
492 fFunctionActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
493 fFunctionActivateButton
.setSelection(false);
494 data
= new GridData(GridData
.FILL_HORIZONTAL
);
495 fFunctionActivateButton
.setLayoutData(data
);
496 fFunctionActivateButton
.addSelectionListener(new SelectionAdapter() {
498 public void widgetSelected(SelectionEvent e
) {
499 setKernelEnablements(KernelGroupEnum
.FUNCTION
);
503 Group functionGroup
= new Group(functionMainGroup
, SWT
.SHADOW_NONE
);
504 layout
= new GridLayout(4, true);
505 functionGroup
.setLayout(layout
);
506 functionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
508 Label functionNameLabel
= new Label(functionGroup
, SWT
.LEFT
);
509 functionNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
510 data
= new GridData(GridData
.FILL_BOTH
);
511 data
.horizontalSpan
= 1;
512 functionNameLabel
.setLayoutData(data
);
514 fFunctionEventNameText
= new Text(functionGroup
, SWT
.LEFT
);
515 fFunctionEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsFunctionEventNameTooltip
);
516 data
= new GridData(GridData
.FILL_BOTH
);
517 data
.horizontalSpan
= 3;
518 fFunctionEventNameText
.setLayoutData(data
);
520 Label functionLabel
= new Label(functionGroup
, SWT
.LEFT
);
521 functionLabel
.setText(Messages
.TraceControl_EnableEventsFunctionNameLabel
);
522 data
= new GridData(GridData
.FILL_BOTH
);
523 data
.horizontalSpan
= 1;
524 functionLabel
.setLayoutData(data
);
526 fFunctionText
= new Text(functionGroup
, SWT
.LEFT
);
527 fFunctionText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
528 data
= new GridData(GridData
.FILL_BOTH
);
529 data
.horizontalSpan
= 3;
530 fFunctionText
.setLayoutData(data
);
534 * Enable/selects widgets depending on the group specified.
535 * @param group - group to enable.
537 private void setKernelEnablements(KernelGroupEnum group
) {
538 fTracepointsActivateButton
.setSelection(group
== KernelGroupEnum
.TRACEPOINTS
);
539 fTracepointsViewer
.getTree().setEnabled(group
== KernelGroupEnum
.TRACEPOINTS
);
541 fSysCallsActivateButton
.setSelection(group
== KernelGroupEnum
.SYSCALLS
);
543 fProbeActivateButton
.setSelection(group
== KernelGroupEnum
.PROBE
);
544 fProbeEventNameText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
545 fProbeText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
547 fFunctionActivateButton
.setSelection(group
== KernelGroupEnum
.FUNCTION
);
548 fFunctionEventNameText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
549 fFunctionText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
552 // ------------------------------------------------------------------------
554 // ------------------------------------------------------------------------
556 * Content provider for the tracepoints tree.
558 final public class KernelContentProvider
extends TraceControlContentProvider
{
560 public Object
[] getChildren(Object parentElement
) {
561 if (parentElement
instanceof TraceProviderGroup
) {
562 List
<ITraceControlComponent
> children
= ((ITraceControlComponent
)parentElement
).getChildren(KernelProviderComponent
.class);
563 return (ITraceControlComponent
[]) children
.toArray(new ITraceControlComponent
[children
.size()]);
565 if (parentElement
instanceof ITraceControlComponent
) {
566 return ((ITraceControlComponent
)parentElement
).getChildren();
568 return new Object
[0];
573 * Content label for the tracepoints tree.
575 final public class KernelLabelProvider
extends TraceControlLabelProvider
{
577 public Image
getImage(Object element
) {
581 public String
getText(Object element
) {
582 if ((element
!= null) && (element
instanceof KernelProviderComponent
)) {
583 return Messages
.TraceControl_EnableEventsTracepointTreeAllLabel
;
585 return super.getText(element
);
590 * Check state listener for the tracepoints tree.
592 final public class KernelCheckListener
implements ICheckStateListener
{
594 public void checkStateChanged(CheckStateChangedEvent event
) {
595 if (event
.getChecked()) {
596 if (event
.getElement() instanceof KernelProviderComponent
) {
597 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), true);
600 if (event
.getElement() instanceof KernelProviderComponent
) {
601 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), false);
603 ITraceControlComponent component
= (ITraceControlComponent
) event
.getElement();
604 fTracepointsViewer
.setChecked(component
.getParent(), false);