Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6d52e8902fd385b2878ccd332e6f46feda6188f1 (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
/*******************************************************************************
 * Copyright (c) 2013 Xilinx, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Xilinx - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.internal.debug.ui.profiler;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
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.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.tcf.internal.debug.ui.ImageCache;
import org.eclipse.tcf.internal.debug.ui.model.TCFModel;
import org.eclipse.tcf.services.IProfiler;

class ProfilerSettingsDlg extends Dialog {

    static final String PARAM_VIEW_UPDATE_PERIOD = "ViewUpdatePeriod";
    static final String PARAM_AGGREGATE = "Aggregate";

    Map<String,Object> conf;
    Map<String,Object> data;

    private Button aggregate_button;
    private Button stack_trace_button;
    private Text frame_cnt_text;
    private Text view_update_text;

    protected ProfilerSettingsDlg(Shell shell, Map<String,Object> conf) {
        super(shell);
        this.conf = conf;
    }

    @Override
    protected void configureShell(Shell shell) {
        super.configureShell(shell);
        shell.setText("Profiler Configuration");
        shell.setImage(ImageCache.getImage(ImageCache.IMG_PROFILER));
    }

    @Override
    protected void createButtonsForButtonBar(Composite parent) {
        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
        createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
        updateButtons();
    }

    @Override
    protected Control createDialogArea(Composite parent) {
        Composite composite = (Composite)super.createDialogArea(parent);
        createFields(composite);
        setData();
        composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        return composite;
    }

    private void createFields(Composite parent) {
        Font font = parent.getFont();
        Composite composite = new Composite(parent, SWT.NONE);
        GridLayout layout = new GridLayout(2, false);
        composite.setFont(font);
        composite.setLayout(layout);
        composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        aggregate_button = new Button(composite, SWT.CHECK);
        aggregate_button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL, 0, true, false, 2, 1));
        aggregate_button.setFont(font);
        aggregate_button.setText("Aggregate per function");

        stack_trace_button = new Button(composite, SWT.CHECK);
        stack_trace_button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL, 0, true, false, 2, 1));
        stack_trace_button.setFont(font);
        stack_trace_button.setText("Enable stack tracing");

        stack_trace_button.addSelectionListener(new SelectionListener() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                updateButtons();
            }
            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                updateButtons();
            }
        });

        Label frame_cnt_label = new Label(composite, SWT.WRAP);
        frame_cnt_label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        frame_cnt_label.setFont(font);
        frame_cnt_label.setText("Max stack frames count:");

        frame_cnt_text = new Text(composite, SWT.SINGLE | SWT.BORDER);
        frame_cnt_text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        frame_cnt_text.setFont(font);

        frame_cnt_text.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                updateButtons();
            }
        });

        Label view_update_label = new Label(composite, SWT.WRAP);
        view_update_label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        view_update_label.setFont(font);
        view_update_label.setText("View update interval (msec):");

        view_update_text = new Text(composite, SWT.SINGLE | SWT.BORDER);
        view_update_text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        view_update_text.setFont(font);

        view_update_text.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                updateButtons();
            }
        });
    }

    private void updateButtons() {
        Button btn = getButton(IDialogConstants.OK_ID);
        if (btn != null) btn.setEnabled(true);
        frame_cnt_text.setEnabled(stack_trace_button.getSelection());
    }

    private void setData() {
        Boolean b = (Boolean)conf.get(PARAM_AGGREGATE);
        aggregate_button.setSelection(b != null && b.booleanValue());
        Number n = (Number)conf.get(IProfiler.PARAM_FRAME_CNT);
        if (n == null || n.intValue() <= 1) {
            stack_trace_button.setSelection(false);
            frame_cnt_text.setText("5");
        }
        else {
            stack_trace_button.setSelection(true);
            frame_cnt_text.setText(conf.get(IProfiler.PARAM_FRAME_CNT).toString());
        }
        view_update_text.setText(conf.get(PARAM_VIEW_UPDATE_PERIOD).toString());
    }

    private void getData() {
        data = new HashMap<String,Object>();
        data.put(PARAM_AGGREGATE, aggregate_button.getSelection());
        if (stack_trace_button.getSelection()) {
            data.put(IProfiler.PARAM_FRAME_CNT, new Integer(frame_cnt_text.getText()));
        }
        else {
            data.put(IProfiler.PARAM_FRAME_CNT, 1);
        }
        data.put(PARAM_VIEW_UPDATE_PERIOD, new Integer(view_update_text.getText()));
    }

    @Override
    protected void okPressed() {
        try {
            getData();
        }
        catch (Throwable x) {
            MessageBox mb = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.OK);
            mb.setText("Invalid data");
            mb.setMessage(TCFModel.getErrorMessage(x, true));
            mb.open();
            return;
        }
        super.okPressed();
    }
}

Back to the top