Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a43472c15f5eb714c37d7f89d44ff3893f481460 (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
355
356
357
358
359
360
361
362
363
364
365
/*******************************************************************************
 * Copyright (c) 2009, 2018 Red Hat, Inc.
 * 
 * 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:
 *    Elliott Baron <ebaron@redhat.com> - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.internal.valgrind.cachegrind;

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.valgrind.launch.LaunchConfigurationConstants;
import org.eclipse.linuxtools.valgrind.launch.IValgrindToolPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionListener;
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.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;
import org.osgi.framework.Version;

public class CachegrindToolPage extends AbstractLaunchConfigurationTab
        implements IValgrindToolPage {
    // Cachegrind controls
    private Button cacheButton;
    private Button branchButton;
    private Spinner i1SizeSpinner;
    private Spinner i1AssocSpinner;
    private Spinner i1LineSizeSpinner;
    private Button i1Button;
    private Spinner d1SizeSpinner;
    private Spinner d1AssocSpinner;
    private Spinner d1LineSizeSpinner;
    private Button d1Button;
    private Spinner l2SizeSpinner;
    private Spinner l2AssocSpinner;
    private Spinner l2LineSizeSpinner;
    private Button l2Button;

    private boolean isInitializing = false;
    private SelectionListener selectListener = SelectionListener.widgetSelectedAdapter(e -> updateLaunchConfigurationDialog());
    private ModifyListener modifyListener = e -> updateLaunchConfigurationDialog();

    @Override
    public void createControl(Composite parent) {
        Composite top = new Composite(parent, SWT.NONE);
        top.setLayout(new GridLayout());
        top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        // Event options
        cacheButton = new Button(top, SWT.CHECK);
        cacheButton.setText(Messages.getString("CachegrindToolPage.Profile_Cache")); //$NON-NLS-1$
        cacheButton.addSelectionListener(selectListener);

        branchButton = new Button(top, SWT.CHECK);
        branchButton.setText(Messages.getString("CachegrindToolPage.Profile_Branch")); //$NON-NLS-1$
        branchButton.addSelectionListener(selectListener);

        createVerticalSpacer(top, 1);

        Group cacheGroup = new Group(top, SWT.SHADOW_OUT);
        cacheGroup.setLayout(new GridLayout(2, false));
        cacheGroup.setText(Messages.getString("CachegrindToolPage.Manually_Set_Cache")); //$NON-NLS-1$

        // I1 Cache
        i1Button = new Button(cacheGroup, SWT.CHECK);
        i1Button.setText(Messages.getString("CachegrindToolPage.I1_Cache")); //$NON-NLS-1$
		i1Button.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
			checkI1Enablement();
			updateLaunchConfigurationDialog();
		}));

        Composite i1Top = new Composite(cacheGroup, SWT.BORDER);
        GridLayout i1Layout = new GridLayout(6, false);
        i1Layout.horizontalSpacing = 10;
        i1Top.setLayout(i1Layout);

        Label i1SizeLabel = new Label(i1Top, SWT.NONE);
        i1SizeLabel.setText(Messages.getString("CachegrindToolPage.Size")); //$NON-NLS-1$

        i1SizeSpinner = new Spinner(i1Top, SWT.BORDER);
        i1SizeSpinner.setMaximum(Integer.MAX_VALUE);
        i1SizeSpinner.addModifyListener(modifyListener);

        Label i1AssocLabel = new Label(i1Top, SWT.NONE);
        i1AssocLabel.setText(Messages.getString("CachegrindToolPage.Assoc")); //$NON-NLS-1$

        i1AssocSpinner = new Spinner(i1Top, SWT.BORDER);
        i1AssocSpinner.setMaximum(Integer.MAX_VALUE);
        i1AssocSpinner.addModifyListener(modifyListener);

        Label i1LineSizeLabel = new Label(i1Top, SWT.NONE);
        i1LineSizeLabel.setText(Messages.getString("CachegrindToolPage.Line_Size")); //$NON-NLS-1$

        i1LineSizeSpinner = new Spinner(i1Top, SWT.BORDER);
        i1LineSizeSpinner.setMaximum(Integer.MAX_VALUE);
        i1LineSizeSpinner.addModifyListener(modifyListener);

        // D1 Cache
        d1Button = new Button(cacheGroup, SWT.CHECK);
        d1Button.setText(Messages.getString("CachegrindToolPage.D1_Cache")); //$NON-NLS-1$
		d1Button.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
			checkD1Enablement();
			updateLaunchConfigurationDialog();
		}));

        Composite d1Top = new Composite(cacheGroup, SWT.BORDER);
        GridLayout d1Layout = new GridLayout(6, false);
        d1Layout.horizontalSpacing = 10;
        d1Top.setLayout(d1Layout);

        Label d1SizeLabel = new Label(d1Top, SWT.NONE);
        d1SizeLabel.setText(Messages.getString("CachegrindToolPage.Size")); //$NON-NLS-1$

        d1SizeSpinner = new Spinner(d1Top, SWT.BORDER);
        d1SizeSpinner.setMaximum(Integer.MAX_VALUE);
        d1SizeSpinner.addModifyListener(modifyListener);

        Label d1AssocLabel = new Label(d1Top, SWT.NONE);
        d1AssocLabel.setText(Messages.getString("CachegrindToolPage.Assoc")); //$NON-NLS-1$

        d1AssocSpinner = new Spinner(d1Top, SWT.BORDER);
        d1AssocSpinner.setMaximum(Integer.MAX_VALUE);
        d1AssocSpinner.addModifyListener(modifyListener);

        Label d1LineSizeLabel = new Label(d1Top, SWT.NONE);
        d1LineSizeLabel.setText(Messages.getString("CachegrindToolPage.Line_Size")); //$NON-NLS-1$

        d1LineSizeSpinner = new Spinner(d1Top, SWT.BORDER);
        d1LineSizeSpinner.setMaximum(Integer.MAX_VALUE);
        d1LineSizeSpinner.addModifyListener(modifyListener);

        // D1 Cache
        l2Button = new Button(cacheGroup, SWT.CHECK);
        l2Button.setText(Messages.getString("CachegrindToolPage.L2_Cache")); //$NON-NLS-1$
		l2Button.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
			checkL2Enablement();
			updateLaunchConfigurationDialog();
		}));

        Composite l2Top = new Composite(cacheGroup, SWT.BORDER);
        GridLayout l2Layout = new GridLayout(6, false);
        l2Layout.horizontalSpacing = 10;
        l2Top.setLayout(l2Layout);

        Label l2SizeLabel = new Label(l2Top, SWT.NONE);
        l2SizeLabel.setText(Messages.getString("CachegrindToolPage.Size")); //$NON-NLS-1$

        l2SizeSpinner = new Spinner(l2Top, SWT.BORDER);
        l2SizeSpinner.setMaximum(Integer.MAX_VALUE);
        l2SizeSpinner.addModifyListener(modifyListener);

        Label l2AssocLabel = new Label(l2Top, SWT.NONE);
        l2AssocLabel.setText(Messages.getString("CachegrindToolPage.Assoc")); //$NON-NLS-1$

        l2AssocSpinner = new Spinner(l2Top, SWT.BORDER);
        l2AssocSpinner.setMaximum(Integer.MAX_VALUE);
        l2AssocSpinner.addModifyListener(modifyListener);

        Label l2LineSizeLabel = new Label(l2Top, SWT.NONE);
        l2LineSizeLabel.setText(Messages.getString("CachegrindToolPage.Line_Size")); //$NON-NLS-1$

        l2LineSizeSpinner = new Spinner(l2Top, SWT.BORDER);
        l2LineSizeSpinner.setMaximum(Integer.MAX_VALUE);
        l2LineSizeSpinner.addModifyListener(modifyListener);
    }

    @Override
    public String getName() {
        return Messages.getString("CachegrindToolPage.Cachegrind_Options"); //$NON-NLS-1$
    }

    @Override
    public void initializeFrom(ILaunchConfiguration config) {
        isInitializing = true;

        try
        {
            cacheButton.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_CACHE_SIM, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_CACHE_SIM));
            branchButton.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_BRANCH_SIM, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_BRANCH_SIM));

            i1Button.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_I1));
            i1SizeSpinner.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1_SIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_I1_SIZE));
            i1AssocSpinner.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1_ASSOC, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_I1_ASSOC));
            i1LineSizeSpinner.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1_LSIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_I1_LSIZE));
            checkI1Enablement();

            d1Button.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_D1));
            d1SizeSpinner.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1_SIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_D1_SIZE));
            d1AssocSpinner.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1_ASSOC, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_D1_ASSOC));
            d1LineSizeSpinner.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1_LSIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_D1_LSIZE));
            checkD1Enablement();

            l2Button.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_L2));
            l2SizeSpinner.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2_SIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_L2_SIZE));
            l2AssocSpinner.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2_ASSOC, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_L2_ASSOC));
            l2LineSizeSpinner.setSelection(config.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2_LSIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_L2_LSIZE));
            checkL2Enablement();

        } catch (CoreException e) {
            e.printStackTrace();
        }
        isInitializing = false;
    }

    @Override
    public void performApply(ILaunchConfigurationWorkingCopy config) {
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_CACHE_SIM, cacheButton.getSelection());
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_BRANCH_SIM, branchButton.getSelection());

        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1, i1Button.getSelection());
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1_SIZE, i1SizeSpinner.getSelection());
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1_ASSOC, i1AssocSpinner.getSelection());
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1_LSIZE, i1LineSizeSpinner.getSelection());

        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1, d1Button.getSelection());
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1_SIZE, d1SizeSpinner.getSelection());
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1_ASSOC, d1AssocSpinner.getSelection());
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1_LSIZE, d1LineSizeSpinner.getSelection());

        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2, l2Button.getSelection());
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2_SIZE, l2SizeSpinner.getSelection());
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2_ASSOC, l2AssocSpinner.getSelection());
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2_LSIZE, l2LineSizeSpinner.getSelection());
    }

    @Override
    public void setDefaults(ILaunchConfigurationWorkingCopy config) {
        config.setAttribute(LaunchConfigurationConstants.ATTR_TOOL, CachegrindPlugin.TOOL_ID);
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_CACHE_SIM, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_CACHE_SIM);
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_BRANCH_SIM, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_BRANCH_SIM);

        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_I1);
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1_SIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_I1_SIZE);
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1_ASSOC, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_I1_ASSOC);
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_I1_LSIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_I1_LSIZE);

        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_D1);
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1_SIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_D1_SIZE);
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1_ASSOC, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_D1_ASSOC);
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_D1_LSIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_D1_LSIZE);

        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_L2);
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2_SIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_L2_SIZE);
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2_ASSOC, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_L2_ASSOC);
        config.setAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_L2_LSIZE, CachegrindLaunchConstants.DEFAULT_CACHEGRIND_L2_LSIZE);
    }

    @Override
    public boolean isValid(ILaunchConfiguration launchConfig) {
        setErrorMessage(null);

        boolean result = false;
        try {
            result = launchConfig.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_CACHE_SIM, true)
            || launchConfig.getAttribute(CachegrindLaunchConstants.ATTR_CACHEGRIND_BRANCH_SIM, false);
        } catch (CoreException e) {
            e.printStackTrace();
        }
        if (!result) {
            setErrorMessage(Messages.getString("CachegrindToolPage.At_least_one_of")); //$NON-NLS-1$
        }
        return result;
    }

    @Override
    public void setValgrindVersion(Version ver) {
        // Not used
    }

    @Override
    protected void updateLaunchConfigurationDialog() {
        if (!isInitializing) {
            super.updateLaunchConfigurationDialog();
        }
    }

    private void checkI1Enablement() {
        boolean checked = i1Button.getSelection();
        i1SizeSpinner.setEnabled(checked);
        i1AssocSpinner.setEnabled(checked);
        i1LineSizeSpinner.setEnabled(checked);
    }

    private void checkD1Enablement() {
        boolean checked = d1Button.getSelection();
        d1SizeSpinner.setEnabled(checked);
        d1AssocSpinner.setEnabled(checked);
        d1LineSizeSpinner.setEnabled(checked);
    }

    private void checkL2Enablement() {
        boolean checked = l2Button.getSelection();
        l2SizeSpinner.setEnabled(checked);
        l2AssocSpinner.setEnabled(checked);
        l2LineSizeSpinner.setEnabled(checked);
    }

    public Button getCacheButton() {
        return cacheButton;
    }

    public Button getBranchButton() {
        return branchButton;
    }

    public Spinner getI1SizeSpinner() {
        return i1SizeSpinner;
    }

    public Spinner getI1AssocSpinner() {
        return i1AssocSpinner;
    }

    public Spinner getI1LineSizeSpinner() {
        return i1LineSizeSpinner;
    }

    public Button getI1Button() {
        return i1Button;
    }

    public Spinner getD1SizeSpinner() {
        return d1SizeSpinner;
    }

    public Spinner getD1AssocSpinner() {
        return d1AssocSpinner;
    }

    public Spinner getD1LineSizeSpinner() {
        return d1LineSizeSpinner;
    }

    public Button getD1Button() {
        return d1Button;
    }

    public Spinner getL2SizeSpinner() {
        return l2SizeSpinner;
    }

    public Spinner getL2AssocSpinner() {
        return l2AssocSpinner;
    }

    public Spinner getL2LineSizeSpinner() {
        return l2LineSizeSpinner;
    }

    public Button getL2Button() {
        return l2Button;
    }
}

Back to the top