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 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 // ------------------------------------------------------------------------
144 public EnableKernelEventComposite(Composite parent
, int style
, TraceProviderGroup providerGroup
) {
145 super(parent
, style
);
146 fProviderGroup
= providerGroup
;
149 // ------------------------------------------------------------------------
151 // ------------------------------------------------------------------------
154 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isTracpoints()
157 public boolean isTracepoints() {
158 return fIsTracepoints
;
162 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isAllTracePoints()
165 public boolean isAllTracePoints() {
166 return fIsAllTracepoints
;
171 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isSysCalls()
174 public boolean isSysCalls() {
179 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isAllSysCalls()
182 public boolean isAllSysCalls() {
187 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getEventNames()
190 public List
<String
> getEventNames() {
191 return new ArrayList
<String
>(fSelectedEvents
);
195 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isDynamicProbe()
198 public boolean isDynamicProbe() {
199 return fIsDynamicProbe
;
203 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getProbeName()
206 public String
getProbeName() {
211 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getProbeEventName()
214 public String
getProbeEventName() {
215 return fProbeEventName
;
220 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#isDynamicFunctionProbe()
223 public boolean isDynamicFunctionProbe() {
224 return fIsDynamicFunctionProbe
;
228 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getFunctionEventName()
231 public String
getFunctionEventName() {
232 return fFunctionEventName
;
236 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableKernelEvents#getFunction()
239 public String
getFunction() {
240 return fFunctionString
;
243 // ------------------------------------------------------------------------
245 // ------------------------------------------------------------------------
247 * Creates the composite content
249 public void createContent() {
252 createTracepointsGroup();
255 createSysCallsGroup();
257 // Dynamic Probe Group
258 createDynamicProbeGroup();
260 // Dynamic Function Probe Group
261 createDynamicFunctionPropeGroup();
263 // Set default enablements
264 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
268 * Validates the kernel composite input data.
269 * @return true if configured data is valid and can be retrieved.
271 public boolean isValid() {
272 fIsTracepoints
= fTracepointsActivateButton
.getSelection();
273 fIsSysCalls
= fSysCallsActivateButton
.getSelection();
274 fIsDynamicProbe
= fProbeActivateButton
.getSelection();
275 fIsDynamicFunctionProbe
= fFunctionActivateButton
.getSelection();
277 // initialize tracepoint fields
278 fIsAllTracepoints
= false;
279 fSelectedEvents
= new ArrayList
<String
>();
281 if (fIsTracepoints
) {
282 List
<ITraceControlComponent
> comps
= fProviderGroup
.getChildren(KernelProviderComponent
.class);
283 fIsAllTracepoints
= fTracepointsViewer
.getChecked(comps
.get(0));
285 Object
[] checkedElements
= fTracepointsViewer
.getCheckedElements();
286 for (int i
= 0; i
< checkedElements
.length
; i
++) {
287 ITraceControlComponent component
= (ITraceControlComponent
)checkedElements
[i
];
288 if (component
instanceof BaseEventComponent
) {
289 fSelectedEvents
.add(component
.getName());
294 if (fIsDynamicProbe
) {
295 String temp
= fProbeEventNameText
.getText();
296 if (!temp
.matches("^[\\s]{0,}$") && !temp
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
297 MessageDialog
.openError(getShell(),
298 Messages
.TraceControl_EnableEventsDialogTitle
,
299 Messages
.TraceControl_InvalidProbeNameError
+ " (" + temp
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
304 if(!fProbeText
.getText().matches("\\s*")) { //$NON-NLS-1$
305 fProbeEventName
= temp
;
306 // fProbeString will be validated by lttng-tools
307 fProbeString
= fProbeText
.getText();
311 // initialize function string
312 fFunctionEventName
= null;
313 fFunctionString
= null;
314 if (fIsDynamicFunctionProbe
) {
315 String functionTemp
= fFunctionEventNameText
.getText();
316 if (!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 if(!fFunctionText
.getText().matches("\\s*")) { //$NON-NLS-1$
325 fFunctionEventName
= functionTemp
;
326 // fFunctionString will be validated by lttng-tools
327 fFunctionString
= fFunctionText
.getText();
335 * Creates tracepoints group.
337 private void createTracepointsGroup() {
341 Group tpMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
342 tpMainGroup
.setText(Messages
.TraceControl_EnableEventsTracepointGroupName
);
343 layout
= new GridLayout(2, false);
344 tpMainGroup
.setLayout(layout
);
345 data
= new GridData(GridData
.FILL_BOTH
);
346 tpMainGroup
.setLayoutData(data
);
348 Composite buttonComposite
= new Composite(tpMainGroup
, SWT
.NONE
);
349 layout
= new GridLayout(1, true);
350 buttonComposite
.setLayout(layout
);
351 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
352 buttonComposite
.setLayoutData(data
);
354 fTracepointsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
355 fTracepointsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
356 data
= new GridData(GridData
.FILL_HORIZONTAL
);
357 fTracepointsActivateButton
.setLayoutData(data
);
358 fTracepointsActivateButton
.addSelectionListener(new SelectionAdapter() {
360 public void widgetSelected(SelectionEvent e
) {
361 setKernelEnablements(KernelGroupEnum
.TRACEPOINTS
);
365 Group tracepointsGroup
= new Group(tpMainGroup
, SWT
.SHADOW_NONE
);
366 layout
= new GridLayout(1, true);
367 tracepointsGroup
.setLayout(layout
);
368 data
= new GridData(GridData
.FILL_BOTH
);
369 tracepointsGroup
.setLayoutData(data
);
371 fTracepointsViewer
= new CheckboxTreeViewer(tracepointsGroup
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
372 fTracepointsViewer
.getTree().setToolTipText(Messages
.TraceControl_EnableEventsTracepointTreeTooltip
);
374 fTracepointsViewer
.setContentProvider(new KernelContentProvider());
375 fTracepointsViewer
.setLabelProvider(new KernelLabelProvider());
376 fTracepointsViewer
.addCheckStateListener(new KernelCheckListener());
377 fTracepointsViewer
.setInput(fProviderGroup
);
379 fTracepointsViewer
.getTree().setLayoutData(new GridData(GridData
.FILL_BOTH
));
383 * Creates syscalls group.
385 private void createSysCallsGroup() {
388 Group sysCallsMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
389 sysCallsMainGroup
.setText(Messages
.TraceControl_EnableEventsSyscallName
);
390 sysCallsMainGroup
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
391 layout
= new GridLayout(2, false);
392 sysCallsMainGroup
.setLayout(layout
);
393 data
= new GridData(GridData
.FILL_HORIZONTAL
);
394 sysCallsMainGroup
.setLayoutData(data
);
396 Composite buttonComposite
= new Composite(sysCallsMainGroup
, SWT
.NONE
);
397 layout
= new GridLayout(1, false);
398 buttonComposite
.setLayout(layout
);
399 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
400 buttonComposite
.setLayoutData(data
);
402 fSysCallsActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
403 fSysCallsActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
404 fSysCallsActivateButton
.setToolTipText(Messages
.TraceControl_EnableEventsSyscallTooltip
);
405 fSysCallsActivateButton
.setSelection(false);
406 data
= new GridData(GridData
.FILL_HORIZONTAL
);
407 fSysCallsActivateButton
.setLayoutData(data
);
408 fSysCallsActivateButton
.addSelectionListener(new SelectionAdapter() {
410 public void widgetSelected(SelectionEvent e
) {
411 setKernelEnablements(KernelGroupEnum
.SYSCALLS
);
417 * Creates dynamic probe group.
419 private void createDynamicProbeGroup() {
422 Group probeMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
423 probeMainGroup
.setText(Messages
.TraceControl_EnableEventsProbeGroupName
);
424 layout
= new GridLayout(2, false);
425 probeMainGroup
.setLayout(layout
);
426 data
= new GridData(GridData
.FILL_HORIZONTAL
);
427 probeMainGroup
.setLayoutData(data
);
429 Composite buttonComposite
= new Composite(probeMainGroup
, SWT
.NONE
);
430 layout
= new GridLayout(1, false);
431 buttonComposite
.setLayout(layout
);
432 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
433 buttonComposite
.setLayoutData(data
);
435 fProbeActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
436 fProbeActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
437 fProbeActivateButton
.setSelection(false);
438 data
= new GridData(GridData
.FILL_HORIZONTAL
);
439 fProbeActivateButton
.setLayoutData(data
);
440 fProbeActivateButton
.addSelectionListener(new SelectionAdapter() {
442 public void widgetSelected(SelectionEvent e
) {
443 setKernelEnablements(KernelGroupEnum
.PROBE
);
447 Group probeGroup
= new Group(probeMainGroup
, SWT
.SHADOW_NONE
);
448 layout
= new GridLayout(4, true);
449 probeGroup
.setLayout(layout
);
450 probeGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
452 Label probeNameLabel
= new Label(probeGroup
, SWT
.LEFT
);
453 probeNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
454 data
= new GridData(GridData
.FILL_BOTH
);
455 data
.horizontalSpan
= 1;
456 probeNameLabel
.setLayoutData(data
);
458 fProbeEventNameText
= new Text(probeGroup
, SWT
.LEFT
);
459 fProbeEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeEventNameTooltip
);
461 data
= new GridData(GridData
.FILL_BOTH
);
462 data
.horizontalSpan
= 3;
463 fProbeEventNameText
.setLayoutData(data
);
465 Label probeLabel
= new Label(probeGroup
, SWT
.LEFT
);
466 probeLabel
.setText(Messages
.TraceControl_EnableEventsProbeNameLabel
);
467 data
= new GridData(GridData
.FILL_BOTH
);
468 data
.horizontalSpan
= 1;
469 probeLabel
.setLayoutData(data
);
471 fProbeText
= new Text(probeGroup
, SWT
.LEFT
);
472 fProbeText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
473 data
= new GridData(GridData
.FILL_BOTH
);
474 data
.horizontalSpan
= 3;
475 fProbeText
.setLayoutData(data
);
479 * Creates dynamic function entry/return probe group.
481 private void createDynamicFunctionPropeGroup() {
484 Group functionMainGroup
= new Group(this, SWT
.SHADOW_NONE
);
485 functionMainGroup
.setText(Messages
.TraceControl_EnableEventsFucntionGroupName
);
486 layout
= new GridLayout(2, false);
487 functionMainGroup
.setLayout(layout
);
488 data
= new GridData(GridData
.FILL_HORIZONTAL
);
489 functionMainGroup
.setLayoutData(data
);
491 Composite buttonComposite
= new Composite(functionMainGroup
, SWT
.NONE
);
492 layout
= new GridLayout(1, false);
493 buttonComposite
.setLayout(layout
);
494 data
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, true);
495 buttonComposite
.setLayoutData(data
);
497 fFunctionActivateButton
= new Button(buttonComposite
, SWT
.RADIO
);
498 fFunctionActivateButton
.setText(Messages
.TraceControl_EnableGroupSelectionName
);
499 fFunctionActivateButton
.setSelection(false);
500 data
= new GridData(GridData
.FILL_HORIZONTAL
);
501 fFunctionActivateButton
.setLayoutData(data
);
502 fFunctionActivateButton
.addSelectionListener(new SelectionAdapter() {
504 public void widgetSelected(SelectionEvent e
) {
505 setKernelEnablements(KernelGroupEnum
.FUNCTION
);
509 Group functionGroup
= new Group(functionMainGroup
, SWT
.SHADOW_NONE
);
510 layout
= new GridLayout(4, true);
511 functionGroup
.setLayout(layout
);
512 functionGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
514 Label functionNameLabel
= new Label(functionGroup
, SWT
.LEFT
);
515 functionNameLabel
.setText(Messages
.TraceControl_EnableEventsEventNameLabel
);
516 data
= new GridData(GridData
.FILL_BOTH
);
517 data
.horizontalSpan
= 1;
518 functionNameLabel
.setLayoutData(data
);
520 fFunctionEventNameText
= new Text(functionGroup
, SWT
.LEFT
);
521 fFunctionEventNameText
.setToolTipText(Messages
.TraceControl_EnableEventsFunctionEventNameTooltip
);
522 data
= new GridData(GridData
.FILL_BOTH
);
523 data
.horizontalSpan
= 3;
524 fFunctionEventNameText
.setLayoutData(data
);
526 Label functionLabel
= new Label(functionGroup
, SWT
.LEFT
);
527 functionLabel
.setText(Messages
.TraceControl_EnableEventsFunctionNameLabel
);
528 data
= new GridData(GridData
.FILL_BOTH
);
529 data
.horizontalSpan
= 1;
530 functionLabel
.setLayoutData(data
);
532 fFunctionText
= new Text(functionGroup
, SWT
.LEFT
);
533 fFunctionText
.setToolTipText(Messages
.TraceControl_EnableEventsProbeNameTooltip
);
534 data
= new GridData(GridData
.FILL_BOTH
);
535 data
.horizontalSpan
= 3;
536 fFunctionText
.setLayoutData(data
);
540 * Enable/selects widgets depending on the group specified.
541 * @param group - group to enable.
543 private void setKernelEnablements(KernelGroupEnum group
) {
544 fTracepointsActivateButton
.setSelection(group
== KernelGroupEnum
.TRACEPOINTS
);
545 fTracepointsViewer
.getTree().setEnabled(group
== KernelGroupEnum
.TRACEPOINTS
);
547 fSysCallsActivateButton
.setSelection(group
== KernelGroupEnum
.SYSCALLS
);
549 fProbeActivateButton
.setSelection(group
== KernelGroupEnum
.PROBE
);
550 fProbeEventNameText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
551 fProbeText
.setEnabled(group
== KernelGroupEnum
.PROBE
);
553 fFunctionActivateButton
.setSelection(group
== KernelGroupEnum
.FUNCTION
);
554 fFunctionEventNameText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
555 fFunctionText
.setEnabled(group
== KernelGroupEnum
.FUNCTION
);
558 // ------------------------------------------------------------------------
560 // ------------------------------------------------------------------------
562 * Content provider for the tracepoints tree.
564 final static public class KernelContentProvider
extends TraceControlContentProvider
{
566 public Object
[] getChildren(Object parentElement
) {
567 if (parentElement
instanceof TraceProviderGroup
) {
568 List
<ITraceControlComponent
> children
= ((ITraceControlComponent
)parentElement
).getChildren(KernelProviderComponent
.class);
569 return (ITraceControlComponent
[]) children
.toArray(new ITraceControlComponent
[children
.size()]);
571 if (parentElement
instanceof ITraceControlComponent
) {
572 return ((ITraceControlComponent
)parentElement
).getChildren();
574 return new Object
[0];
579 * Content label for the tracepoints tree.
581 final static public class KernelLabelProvider
extends TraceControlLabelProvider
{
583 public Image
getImage(Object element
) {
587 public String
getText(Object element
) {
588 if ((element
!= null) && (element
instanceof KernelProviderComponent
)) {
589 return Messages
.TraceControl_EnableEventsTracepointTreeAllLabel
;
591 return super.getText(element
);
596 * Check state listener for the tracepoints tree.
598 final public class KernelCheckListener
implements ICheckStateListener
{
600 public void checkStateChanged(CheckStateChangedEvent event
) {
601 if (event
.getChecked()) {
602 if (event
.getElement() instanceof KernelProviderComponent
) {
603 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), true);
606 if (event
.getElement() instanceof KernelProviderComponent
) {
607 fTracepointsViewer
.setSubtreeChecked(event
.getElement(), false);
609 ITraceControlComponent component
= (ITraceControlComponent
) event
.getElement();
610 fTracepointsViewer
.setChecked(component
.getParent(), false);