Skip to content

Commit 0e5bb60

Browse files
committed
Profiler settings changes
- fixed presets synchronization for JDBC settings - enabled saving invalid settings - refactored - updated to work with Startup Profiler
1 parent bff66dd commit 0e5bb60

File tree

17 files changed

+408
-219
lines changed

17 files changed

+408
-219
lines changed

plugins/startupprofiler/manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ Manifest-Version: 1.0
22
OpenIDE-Module: com.sun.tools.visualvm.profiler.startup
33
OpenIDE-Module-Localizing-Bundle: com/sun/tools/visualvm/profiler/startup/Bundle.properties
44
OpenIDE-Module-Layer: com/sun/tools/visualvm/profiler/startup/resources/layer.xml
5-
OpenIDE-Module-Specification-Version: 1.0
5+
OpenIDE-Module-Specification-Version: 1.1
66

plugins/startupprofiler/nbproject/project.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<compile-dependency/>
2222
<run-dependency>
2323
<release-version>0</release-version>
24-
<specification-version>1.3</specification-version>
24+
<specification-version>1.6</specification-version>
2525
</run-dependency>
2626
</dependency>
2727
<dependency>
@@ -30,7 +30,7 @@
3030
<compile-dependency/>
3131
<run-dependency>
3232
<release-version>0</release-version>
33-
<specification-version>1.2</specification-version>
33+
<specification-version>1.5</specification-version>
3434
</run-dependency>
3535
</dependency>
3636
<dependency>

plugins/startupprofiler/src/com/sun/tools/visualvm/profiler/startup/StartupConfigurator.java

Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
import com.sun.tools.visualvm.core.ui.DesktopUtils;
2828
import com.sun.tools.visualvm.core.ui.components.SectionSeparator;
2929
import com.sun.tools.visualvm.profiler.CPUSettingsSupport;
30+
import com.sun.tools.visualvm.profiler.JDBCSettingsSupport;
3031
import com.sun.tools.visualvm.profiler.MemorySettingsSupport;
32+
import com.sun.tools.visualvm.profiler.ProfilerSettingsSupport;
3133
import com.sun.tools.visualvm.profiler.ProfilerSupport;
3234
import com.sun.tools.visualvm.profiling.presets.PresetSelector;
35+
import com.sun.tools.visualvm.profiling.presets.ProfilerPreset;
3336
import com.sun.tools.visualvm.profiling.presets.ProfilerPresets;
3437
import com.sun.tools.visualvm.uisupport.HorizontalLayout;
3538
import com.sun.tools.visualvm.uisupport.SeparatorLine;
@@ -50,6 +53,8 @@
5053
import java.awt.event.ActionEvent;
5154
import java.awt.event.ItemEvent;
5255
import java.net.URI;
56+
import java.util.ArrayList;
57+
import java.util.List;
5358
import javax.swing.BorderFactory;
5459
import javax.swing.ButtonGroup;
5560
import javax.swing.DefaultComboBoxModel;
@@ -94,6 +99,7 @@
9499
"LBL_Profile=Profile:",
95100
"LBL_CPU=CPU",
96101
"LBL_Memory=Memory",
102+
"LBL_JDBC=JDBC",
97103
"BTN_Clipboard=Copy to clipboard",
98104
"CAP_Clipboard=Copy to Clipboard",
99105
"MSG_Clipboard=Profiler parameter copied to clipboard",
@@ -111,14 +117,19 @@ final class StartupConfigurator {
111117

112118
private static final String CPU_ICON_PATH = "com/sun/tools/visualvm/profiler/startup/resources/cpu.png"; // NOI18N
113119
private static final String MEM_ICON_PATH = "com/sun/tools/visualvm/profiler/startup/resources/memory.png"; // NOI18N
120+
private static final String JDBC_ICON_PATH = "com/sun/tools/visualvm/profiler/startup/resources/jdbc.png"; // NOI18N
114121
private static final String HELP_ICON_PATH = "com/sun/tools/visualvm/profiler/startup/resources/help.png"; // NOI18N
115122
private static final Icon CPU_ICON = ImageUtilities.loadImageIcon(CPU_ICON_PATH, false);
116123
private static final Icon MEM_ICON = ImageUtilities.loadImageIcon(MEM_ICON_PATH, false);
124+
private static final Icon JDBC_ICON = ImageUtilities.loadImageIcon(JDBC_ICON_PATH, false);
117125
private static final Icon HELP_ICON = ImageUtilities.loadImageIcon(HELP_ICON_PATH, false);
118126

119127
private CPUSettingsSupport cpuSettings;
120128
private MemorySettingsSupport memorySettings;
121-
private PresetSelector refSelector;
129+
private JDBCSettingsSupport jdbcSettings;
130+
131+
private DefaultComboBoxModel selectorModel;
132+
private List<PresetSelector> allSelectors;
122133

123134
private JComponent ui;
124135
private boolean accepted;
@@ -131,9 +142,11 @@ final class StartupConfigurator {
131142
private JPanel panel;
132143
private Dimension cpuSize;
133144
private Dimension memorySize;
145+
private Dimension jdbcSize;
134146

135147
private JRadioButton cpuSelector;
136148
private JRadioButton memorySelector;
149+
private JRadioButton jdbcSelector;
137150
private JComboBox java;
138151
private JComboBox arch;
139152
private JSpinner port;
@@ -146,7 +159,8 @@ final class StartupConfigurator {
146159
cpuSettings = new CPUSettingsSupport() {
147160
public boolean presetValid() {
148161
return cpuSettings.settingsValid() &&
149-
memorySettings.settingsValid();
162+
memorySettings.settingsValid() &&
163+
jdbcSettings.settingsValid();
150164
}
151165
public PresetSelector createSelector(Runnable presetSynchronizer) {
152166
return StartupConfigurator.this.createSelector(presetSynchronizer);
@@ -155,7 +169,18 @@ public PresetSelector createSelector(Runnable presetSynchronizer) {
155169
memorySettings = new MemorySettingsSupport() {
156170
public boolean presetValid() {
157171
return cpuSettings.settingsValid() &&
158-
memorySettings.settingsValid();
172+
memorySettings.settingsValid() &&
173+
jdbcSettings.settingsValid();
174+
}
175+
public PresetSelector createSelector(Runnable presetSynchronizer) {
176+
return StartupConfigurator.this.createSelector(presetSynchronizer);
177+
}
178+
};
179+
jdbcSettings = new JDBCSettingsSupport() {
180+
public boolean presetValid() {
181+
return cpuSettings.settingsValid() &&
182+
memorySettings.settingsValid() &&
183+
jdbcSettings.settingsValid();
159184
}
160185
public PresetSelector createSelector(Runnable presetSynchronizer) {
161186
return StartupConfigurator.this.createSelector(presetSynchronizer);
@@ -165,12 +190,15 @@ public PresetSelector createSelector(Runnable presetSynchronizer) {
165190
// Warmup, the implementation expects both panels to be created
166191
cpuSettings.getComponent();
167192
memorySettings.getComponent();
193+
jdbcSettings.getComponent();
168194
}
169195

170196
private PresetSelector createSelector(Runnable presetSynchronizer) {
197+
if (selectorModel == null) selectorModel = new DefaultComboBoxModel();
198+
if (allSelectors == null) allSelectors = new ArrayList();
171199
PresetSelector selector = ProfilerPresets.getInstance().createSelector(
172-
refSelector, presetSynchronizer);
173-
if (refSelector == null) refSelector = selector; else refSelector = null;
200+
selectorModel, allSelectors, presetSynchronizer);
201+
allSelectors.add(selector);
174202
return selector;
175203
}
176204

@@ -187,16 +215,15 @@ boolean accepted() {
187215
return accepted;
188216
}
189217

190-
CPUSettingsSupport getCPUSettings() {
191-
return cpuSettings;
192-
}
193-
194-
MemorySettingsSupport getMemorySettings() {
195-
return memorySettings;
218+
ProfilerSettingsSupport getSettings() {
219+
if (cpuSelector.isSelected()) return cpuSettings;
220+
else if (memorySelector.isSelected()) return memorySettings;
221+
else if (jdbcSelector.isSelected()) return jdbcSettings;
222+
return null;
196223
}
197224

198-
boolean isCPUProfiling() {
199-
return cpuSelector.isSelected();
225+
ProfilerPreset getPreset() {
226+
return (ProfilerPreset)selectorModel.getSelectedItem();
200227
}
201228

202229
String getJavaPlatform() {
@@ -280,13 +307,17 @@ public Dimension getPreferredSize() {
280307
JPanel buttonsR = new JPanel(new HorizontalLayout(false));
281308
submit = new JButton(Bundle.BTN_Profile(), new ImageIcon(StartupProfilerAction.ICON)) {
282309
protected void fireActionPerformed(ActionEvent e) {
283-
boolean isCPU = isCPUProfiling();
284-
boolean valid = isCPU ? cpuSettings.settingsValid() :
285-
memorySettings.settingsValid();
286-
if (!valid) {
287-
String msg = isCPU ? Bundle.MSG_InvalidCPUSettings() :
288-
Bundle.MSG_InvalidMemorySettings();
289-
Dialogs.show(Dialogs.error(Bundle.CAP_InvalidSettings(), msg));
310+
String err = null;
311+
if (cpuSelector.isSelected()) {
312+
if (!cpuSettings.settingsValid())
313+
err = Bundle.MSG_InvalidCPUSettings();
314+
} else if (memorySelector.isSelected()) {
315+
if (!memorySettings.settingsValid())
316+
err = Bundle.MSG_InvalidMemorySettings();
317+
}
318+
319+
if (err != null) {
320+
Dialogs.show(Dialogs.error(Bundle.CAP_InvalidSettings(), err));
290321
} else {
291322
accepted = true;
292323
Window w = SwingUtilities.getWindowAncestor(this);
@@ -327,6 +358,8 @@ protected void fireActionPerformed(ActionEvent e) {
327358
cpuSize = panel.getPreferredSize();
328359
memorySize = new Dimension(cpuSize);
329360
memorySize.height -= cpuSettings.getComponent().getPreferredSize().height - memorySettings.getComponent().getPreferredSize().height;
361+
jdbcSize = new Dimension(cpuSize);
362+
jdbcSize.height -= cpuSettings.getComponent().getPreferredSize().height - jdbcSettings.getComponent().getPreferredSize().height;
330363
panel.setPreferredSize(cpuSize);
331364

332365
separator2.setVisible(false);
@@ -484,6 +517,11 @@ private JPanel createProfilePanel() {
484517
((JComponent)memory.getComponent(1)).setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
485518
memory.setVisible(false);
486519

520+
final JComponent jdbc = jdbcSettings.getComponent();
521+
((JComponent)jdbc.getComponent(0)).setBorder(BorderFactory.createEmptyBorder(-3, -10, 0, -10));
522+
((JComponent)jdbc.getComponent(1)).setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
523+
jdbc.setVisible(false);
524+
487525
final JPanel profile = new JPanel(new VerticalLayout(false));
488526
profile.setBorder(BorderFactory.createEmptyBorder(5, 13, 15, 5));
489527
profile.setOpaque(false);
@@ -500,6 +538,7 @@ protected void fireItemStateChanged(ItemEvent e) {
500538
if (e.getStateChange() == ItemEvent.SELECTED) {
501539
cpu.setVisible(true);
502540
memory.setVisible(false);
541+
jdbc.setVisible(false);
503542
if (panel != null) {
504543
panel.setPreferredSize(cpuSize);
505544
SwingUtilities.getWindowAncestor(profile).pack();
@@ -515,6 +554,7 @@ protected void fireItemStateChanged(ItemEvent e) {
515554
if (e.getStateChange() == ItemEvent.SELECTED) {
516555
cpu.setVisible(false);
517556
memory.setVisible(true);
557+
jdbc.setVisible(false);
518558
if (panel != null) {
519559
panel.setPreferredSize(memorySize);
520560
SwingUtilities.getWindowAncestor(profile).pack();
@@ -523,10 +563,27 @@ protected void fireItemStateChanged(ItemEvent e) {
523563
}
524564
};
525565
mode.add(memorySelector);
566+
jdbcSelector = new IconRadioButton(Bundle.LBL_JDBC(), JDBC_ICON, false) {
567+
{ bg.add(this); }
568+
protected void fireItemStateChanged(ItemEvent e) {
569+
super.fireItemStateChanged(e);
570+
if (e.getStateChange() == ItemEvent.SELECTED) {
571+
cpu.setVisible(false);
572+
memory.setVisible(false);
573+
jdbc.setVisible(true);
574+
if (panel != null) {
575+
panel.setPreferredSize(jdbcSize);
576+
SwingUtilities.getWindowAncestor(profile).pack();
577+
}
578+
}
579+
}
580+
};
581+
mode.add(jdbcSelector);
526582
profile.add(mode);
527583

528584
profile.add(cpu);
529585
profile.add(memory);
586+
profile.add(jdbc);
530587

531588
return profile;
532589
}

plugins/startupprofiler/src/com/sun/tools/visualvm/profiler/startup/StartupProfiler.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
package com.sun.tools.visualvm.profiler.startup;
2727

28-
import com.sun.tools.visualvm.profiler.CPUSettingsSupport;
29-
import com.sun.tools.visualvm.profiler.MemorySettingsSupport;
28+
import com.sun.tools.visualvm.profiler.ProfilerSettingsSupport;
3029
import com.sun.tools.visualvm.profiler.ProfilerSupport;
30+
import com.sun.tools.visualvm.profiling.presets.ProfilerPreset;
3131
import java.awt.Dialog;
3232
import javax.swing.SwingUtilities;
3333
import org.openide.util.NbBundle;
@@ -76,18 +76,17 @@ public void run() {
7676

7777

7878
private void attachToProcess() {
79-
final CPUSettingsSupport cpuSettings = configurator.getCPUSettings();
80-
final MemorySettingsSupport memorySettings = configurator.getMemorySettings();
81-
final boolean isCPUProfiling = configurator.isCPUProfiling();
8279
final int port = configurator.getPort();
8380
final String java = configurator.getJavaPlatform();
8481
final int architecture = configurator.getArchitecture();
8582

83+
final ProfilerSettingsSupport settings = configurator.getSettings();
84+
final ProfilerPreset preset = configurator.getPreset();
85+
8686
RequestProcessor.getDefault().post(new Runnable() {
8787
public void run() {
8888
ProfilerSupport.getInstance().profileProcessStartup(java, architecture, port,
89-
cpuSettings, memorySettings,
90-
isCPUProfiling);
89+
settings, preset);
9190
}
9291
});
9392
}
1.53 KB
Loading

0 commit comments

Comments
 (0)