Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 64483958fb7768ecfe6d9b464ca9906c5a013327 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*******************************************************************************
 * Copyright (c) 2004, 2018 Red Hat, Inc. and others.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Keith Seitz <keiths@redhat.com> - initial API and implementation
 *    Kent Sebastian <ksebasti@redhat.com> -
 *    Thavidu Ranatunga (IBM) - derived from
 *       org.eclipse.linuxtools.oprofile.launch.configuration.OprofileSetupTab
 *******************************************************************************/
package org.eclipse.linuxtools.internal.perf.launch;

import java.io.File;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.linuxtools.internal.perf.PerfCore;
import org.eclipse.linuxtools.internal.perf.PerfPlugin;
import org.eclipse.linuxtools.internal.perf.PerfVersion;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

public class PerfOptionsTab extends AbstractLaunchConfigurationTab {
    private ILaunchConfiguration lastConfig;

    protected Text txtKernelLocation;
    protected Button chkRecordRealtime;
    protected Spinner rtPriority;
    protected Button chkRecordVerbose;
    protected Button chkSourceLineNumbers;
    protected Button chkKernelSourceLineNumbers;
    protected Button chkMultiplexEvents;
    protected Button chkModuleSymbols;
    protected Button chkHideUnresolvedSymbols;
    protected Button chkShowSourceDisassembly;
    protected Button chkShowStat;
    protected Spinner statRunCount;

    private Composite top;
    private ScrolledComposite scrollTop;

    private final PerfVersion multiplexEventsVersion = new PerfVersion (2, 6, 35);

    @Override
    public Image getImage() {
        return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
    }

    @Override
    public boolean isValid(ILaunchConfiguration config) {
        if (txtKernelLocation != null) {
            String filename = txtKernelLocation.getText();
            if (filename.length() > 0) {
                File file = new File(filename);
                return (file.exists() && file.isFile());
            }
        }
        return true;
    }

    @Override
    public void createControl(Composite parent) {
        scrollTop = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
        scrollTop.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        scrollTop.setExpandVertical(true);
        scrollTop.setExpandHorizontal(true);

        setControl(scrollTop);

        top = new Composite(scrollTop, SWT.NONE);
        top.setLayout(new GridLayout());

        createVerticalSpacer(top, 1);
        GridData data;

        // Kernel Selection
        Composite kernelComp = new Composite(top, SWT.NONE);
        GridLayout parallelLayout = new GridLayout(2, false);
        data = new GridData(GridData.FILL_HORIZONTAL);
        parallelLayout.marginHeight = 0;
        parallelLayout.marginWidth = 0;
        kernelComp.setLayout(parallelLayout);
        kernelComp.setLayoutData(data);

        Label kernelLabel = new Label(kernelComp, SWT.NONE);
        kernelLabel.setText(PerfPlugin.STRINGS_Kernel_Location);
        data = new GridData();
        data.horizontalSpan = 2;
        kernelLabel.setLayoutData(data);

        txtKernelLocation = new Text(kernelComp, SWT.SINGLE | SWT.BORDER);
        data = new GridData(GridData.FILL_HORIZONTAL);
        txtKernelLocation.setLayoutData(data);
        txtKernelLocation.addModifyListener(mev -> handleKernelImageFileTextModify(txtKernelLocation));

        Button button = createPushButton(kernelComp, Messages.PerfOptionsTab_Browse, null);
        final Shell shell = top.getShell();
		button.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> showFileDialog(shell)));

        createVerticalSpacer(top, 1);

        // Create checkbox options container
        Composite chkBoxComp = new Composite(top, SWT.NONE);
        GridLayout chkBoxLayout = new GridLayout();
        chkBoxLayout.marginHeight = 0;
        chkBoxLayout.marginWidth = 0;
        chkBoxComp.setLayout(chkBoxLayout);

        chkRecordVerbose = createCheckButtonHelper(chkBoxComp, PerfPlugin.STRINGS_Record_Verbose);
        chkModuleSymbols = createCheckButtonHelper(chkBoxComp, PerfPlugin.STRINGS_ModuleSymbols);
        chkHideUnresolvedSymbols = createCheckButtonHelper(chkBoxComp, PerfPlugin.STRINGS_HideUnresolvedSymbols);
        chkSourceLineNumbers = createCheckButtonHelper(chkBoxComp, PerfPlugin.STRINGS_SourceLineNumbers);
        chkShowSourceDisassembly = createCheckButtonHelper(chkBoxComp, PerfPlugin.STRINGS_ShowSourceDisassembly);

        Composite showStatComp = new Composite(top, SWT.NONE);
        showStatComp.setLayout(parallelLayout);

        chkShowStat = createCheckButtonHelper(showStatComp, PerfPlugin.STRINGS_ShowStat);
		chkShowStat.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> handleShowStatSelection()));
        statRunCount = new Spinner(showStatComp, SWT.BORDER);
        statRunCount.setEnabled(false);
        statRunCount.setMinimum(1);
        statRunCount.addModifyListener(e -> updateLaunchConfigurationDialog());

		chkSourceLineNumbers.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
			if ((chkKernelSourceLineNumbers != null) && (!chkSourceLineNumbers.getSelection())) {
				chkKernelSourceLineNumbers.setEnabled(false);
			} else {
				chkKernelSourceLineNumbers.setEnabled(true);
			}
		}));
        chkKernelSourceLineNumbers = createCheckButtonHelper(chkBoxComp, PerfPlugin.STRINGS_Kernel_SourceLineNumbers);

        Composite realtimeComp = new Composite(top, SWT.NONE);
        realtimeComp.setLayout(parallelLayout);

        chkRecordRealtime = createCheckButtonHelper(realtimeComp, PerfPlugin.STRINGS_Record_Realtime);
		chkRecordRealtime.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
			rtPriority.setEnabled(chkRecordRealtime.getSelection());
		}));
        rtPriority = new Spinner(realtimeComp, SWT.BORDER);
        rtPriority.setEnabled(chkRecordRealtime.getSelection());
        rtPriority.setMinimum(1);
        rtPriority.addModifyListener(e -> updateLaunchConfigurationDialog());

        // A disabled button does not respond to mouse events so use a composite.
        final Composite multiplexEventsComp = new Composite(chkBoxComp, SWT.NONE);
        multiplexEventsComp.setLayout(chkBoxLayout);
        multiplexEventsComp.addListener(SWT.MouseHover, event -> multiplexEventsComp.setToolTipText(Messages.PerfOptionsTab_Requires_LTE + multiplexEventsVersion));
        chkMultiplexEvents = createCheckButtonHelper(multiplexEventsComp, PerfPlugin.STRINGS_Multiplex);

        scrollTop.setContent(top);
        recomputeSize();
        updateLaunchConfigurationDialog();
    }

    private void recomputeSize() {
        Point point = top.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        top.setSize(point);
        scrollTop.setMinSize(point);
    }

    // Helper function for creating buttons.
    private Button createCheckButtonHelper(Composite parent, String label) {
        final Button b = new Button(parent, SWT.CHECK);
        b.setText(label);
		b.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
			setDirty(true);
			updateLaunchConfigurationDialog();
		}));
        return b;
    }

    // handles text modification event for kernel file location
    private void handleKernelImageFileTextModify(Text text) {
        String errorMessage = null;
        String filename = text.getText();

        if (filename.length() > 0) {
            File file = new File(filename);
            if (!file.exists() || !file.isFile()) {
                errorMessage = Messages.PerfOptionsTab_Loc_DNE;
            }
        }

        // Update dialog and error message
        setErrorMessage(errorMessage);
        updateLaunchConfigurationDialog();
    }

    /**
     * Handle selection of show stat button
     */
    private void handleShowStatSelection() {
        if (chkShowStat.getSelection()) {
            statRunCount.setEnabled(true);
            toggleButtonsEnablement(false);
        } else {
            statRunCount.setEnabled(false);
            toggleButtonsEnablement(true);
        }
    }

    // Displays a file dialog to allow the user to select the kernel image file
    private void showFileDialog(Shell shell) {
        FileDialog fDialog = new FileDialog(shell, SWT.OPEN);
        File kernel = new File(txtKernelLocation.getText());
        if (!kernel.exists()) {
            kernel = new File("/boot"); //$NON-NLS-1$
            if (!kernel.exists()) {
                kernel = new File("/"); //$NON-NLS-1$
            }
        }
        fDialog.setFileName(kernel.toString());
        fDialog.setText(Messages.PerfOptionsTab_Kernel_Prompt);
        String newKernel = fDialog.open();
        if (newKernel != null) {
            kernel = new File(newKernel);
            if (!kernel.exists()) {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.RETRY | SWT.CANCEL);
                mb.setMessage(Messages.PerfOptionsTab_File_DNE);
                switch (mb.open()) {
                    case SWT.RETRY:
                        showFileDialog(shell);
                        break;
                    default:
                }
            } else {
                txtKernelLocation.setText(newKernel);
            }
        }
    }

    /**
     * Toggle enablement of all buttons, excluding the stat button.
     * @param enable enablement of buttons
     */
    private void toggleButtonsEnablement(boolean enable) {
    	PerfVersion version = PerfCore.getPerfVersion(lastConfig);
        txtKernelLocation.setEnabled(enable);
        chkRecordRealtime.setEnabled(enable);
        chkRecordVerbose.setEnabled(enable);
        chkSourceLineNumbers.setEnabled(enable);
        chkKernelSourceLineNumbers.setEnabled(enable);
        if (version != null && multiplexEventsVersion.isNewer(version)) {
            chkMultiplexEvents.setEnabled(enable);
        } else {
            chkMultiplexEvents.setEnabled(false);
        }
        chkModuleSymbols.setEnabled(enable);
        chkHideUnresolvedSymbols.setEnabled(enable);
        chkShowSourceDisassembly.setEnabled(enable);
    }

    @Override
    public String getName() {
        return Messages.PerfOptionsTab_Options;
    }

    @Override
    public void initializeFrom(ILaunchConfiguration config) {

        // Keep track of the last configuration loaded
        lastConfig = config;
        PerfVersion perfVersion = PerfCore.getPerfVersion(config);

        try {

            if (perfVersion != null && multiplexEventsVersion.isNewer(perfVersion)) {
                chkMultiplexEvents.setSelection(config.getAttribute(PerfPlugin.ATTR_Multiplex, PerfPlugin.ATTR_Multiplex_default));
            }

            txtKernelLocation.setText(config.getAttribute(PerfPlugin.ATTR_Kernel_Location, PerfPlugin.ATTR_Kernel_Location_default));
            chkRecordRealtime.setSelection(config.getAttribute(PerfPlugin.ATTR_Record_Realtime, PerfPlugin.ATTR_Record_Realtime_default));
            int priority = config.getAttribute(PerfPlugin.ATTR_Record_Realtime_Priority, PerfPlugin.ATTR_Record_Realtime_Priority_default);
            rtPriority.setEnabled(chkRecordRealtime.getSelection());
            rtPriority.setSelection(priority);
            chkRecordVerbose.setSelection(config.getAttribute(PerfPlugin.ATTR_Record_Verbose, PerfPlugin.ATTR_Record_Verbose_default));
            chkSourceLineNumbers.setSelection(config.getAttribute(PerfPlugin.ATTR_SourceLineNumbers, PerfPlugin.ATTR_SourceLineNumbers_default));
            chkKernelSourceLineNumbers.setSelection(config.getAttribute(PerfPlugin.ATTR_Kernel_SourceLineNumbers, PerfPlugin.ATTR_Kernel_SourceLineNumbers_default));

            chkModuleSymbols.setSelection(config.getAttribute(PerfPlugin.ATTR_ModuleSymbols, PerfPlugin.ATTR_ModuleSymbols_default));
            chkHideUnresolvedSymbols.setSelection(config.getAttribute(PerfPlugin.ATTR_HideUnresolvedSymbols, PerfPlugin.ATTR_HideUnresolvedSymbols_default));
            chkShowSourceDisassembly.setSelection(config.getAttribute(PerfPlugin.ATTR_ShowSourceDisassembly, PerfPlugin.ATTR_ShowSourceDisassembly_default));
            chkShowStat.setSelection(config.getAttribute(PerfPlugin.ATTR_ShowStat, PerfPlugin.ATTR_ShowStat_default));
            int runCount = config.getAttribute(PerfPlugin.ATTR_StatRunCount, PerfPlugin.ATTR_StatRunCount_default);
            statRunCount.setSelection(runCount);
            handleShowStatSelection();
        } catch (CoreException e) {
            // do nothing
        }
    }

    @Override
    public void performApply(ILaunchConfigurationWorkingCopy wconfig) {

        PerfVersion perfVersion = PerfCore.getPerfVersion(wconfig);

        if (perfVersion != null && multiplexEventsVersion.isNewer(perfVersion)) {
            wconfig.setAttribute(PerfPlugin.ATTR_Multiplex, chkMultiplexEvents.getSelection());
        }

        wconfig.setAttribute(PerfPlugin.ATTR_Kernel_Location, txtKernelLocation.getText());
        wconfig.setAttribute(PerfPlugin.ATTR_Record_Realtime, chkRecordRealtime.getSelection());
        wconfig.setAttribute(PerfPlugin.ATTR_Record_Realtime_Priority, rtPriority.getSelection());
        wconfig.setAttribute(PerfPlugin.ATTR_Record_Verbose, chkRecordVerbose.getSelection());
        wconfig.setAttribute(PerfPlugin.ATTR_SourceLineNumbers, chkSourceLineNumbers.getSelection());
        wconfig.setAttribute(PerfPlugin.ATTR_Kernel_SourceLineNumbers, chkKernelSourceLineNumbers.getSelection());
        wconfig.setAttribute(PerfPlugin.ATTR_ModuleSymbols, chkModuleSymbols.getSelection());
        wconfig.setAttribute(PerfPlugin.ATTR_HideUnresolvedSymbols, chkHideUnresolvedSymbols.getSelection());
        wconfig.setAttribute(PerfPlugin.ATTR_ShowSourceDisassembly, chkShowSourceDisassembly.getSelection());
        wconfig.setAttribute(PerfPlugin.ATTR_ShowStat, chkShowStat.getSelection());
        wconfig.setAttribute(PerfPlugin.ATTR_StatRunCount, statRunCount.getSelection());
    }

    @Override
    public void setDefaults(ILaunchConfigurationWorkingCopy wconfig) {
        wconfig.setAttribute(PerfPlugin.ATTR_Kernel_Location, PerfPlugin.ATTR_Kernel_Location_default);
        wconfig.setAttribute(PerfPlugin.ATTR_Record_Realtime, PerfPlugin.ATTR_Record_Realtime_default);
        wconfig.setAttribute(PerfPlugin.ATTR_Record_Realtime_Priority, PerfPlugin.ATTR_Record_Realtime_Priority_default);
        wconfig.setAttribute(PerfPlugin.ATTR_Record_Verbose, PerfPlugin.ATTR_Record_Verbose_default);
        wconfig.setAttribute(PerfPlugin.ATTR_SourceLineNumbers, PerfPlugin.ATTR_SourceLineNumbers_default);
        wconfig.setAttribute(PerfPlugin.ATTR_Kernel_SourceLineNumbers, PerfPlugin.ATTR_Kernel_SourceLineNumbers_default);
        wconfig.setAttribute(PerfPlugin.ATTR_Multiplex, PerfPlugin.ATTR_Multiplex_default);
        wconfig.setAttribute(PerfPlugin.ATTR_ModuleSymbols, PerfPlugin.ATTR_ModuleSymbols_default);
        wconfig.setAttribute(PerfPlugin.ATTR_HideUnresolvedSymbols, PerfPlugin.ATTR_HideUnresolvedSymbols_default);
        wconfig.setAttribute(PerfPlugin.ATTR_ShowSourceDisassembly, PerfPlugin.ATTR_ShowSourceDisassembly_default);
        wconfig.setAttribute(PerfPlugin.ATTR_ShowStat, PerfPlugin.ATTR_ShowStat_default);
        wconfig.setAttribute(PerfPlugin.ATTR_StatRunCount, PerfPlugin.ATTR_StatRunCount_default);
    }

}

Back to the top