Skip to content

Commit 8ea3133

Browse files
committed
Sampler/CPU improvements and cleanup
1 parent d115eed commit 8ea3133

File tree

9 files changed

+113
-59
lines changed

9 files changed

+113
-59
lines changed

visualvm/profiling/src/com/sun/tools/visualvm/profiling/presets/Bundle.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ TOOLTIP_Inclusive_Filter=Profile only outgoing calls of the defined classes or p
6767

6868
TOOLTIP_Exclusive_Filter=Do not profile outgoing calls of the defined classes or packages
6969

70-
TOOLTIP_Inclusive_Filter_S=Only code of these packages will be profiled
70+
TOOLTIP_Inclusive_Filter_S=Profile only methods of the defined classes or packages
7171

72-
TOOLTIP_Exclusive_Filter_S=All code except these packages will be profiled
72+
TOOLTIP_Exclusive_Filter_S=Do not profile methods of the defined classes or packages
7373

7474
TOOLTIP_Instrumentation_Filter=<html>Include/exclude profiling outgoing calls from these classes or packages:<br><br><code>&nbsp;org.mypackage.**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>all classes in package and subpackages<br><code>&nbsp;org.mypackage.*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>all classes in package<br><code>&nbsp;org.mypackage.MyClass&nbsp;&nbsp;</code>single class<br><br>Special case:<br><br><code>&nbsp;&lt;empty&gt; or * or **</code>&nbsp;&nbsp;include all classes<br></html>
7575

76+
TOOLTIP_Instrumentation_Filter_S=<html>Profile/do not profile methods of these classes or packages:<br><br><code>&nbsp;org.mypackage.**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>all classes in package and subpackages<br><code>&nbsp;org.mypackage.*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>all classes in package<br><code>&nbsp;org.mypackage.MyClass&nbsp;&nbsp;</code>single class<br><br>Special case:<br><br><code>&nbsp;&lt;empty&gt; or * or **</code>&nbsp;&nbsp;include all classes<br></html>
77+
7678
TOOLTIP_Allocations=Only object allocations are recorded
7779

7880
TOOLTIP_Allocations_GC=Whole lifecycle of allocated objects is recorded

visualvm/profiling/src/com/sun/tools/visualvm/profiling/presets/ProfilerPresets.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ private static String getMainClass(Application application) {
299299

300300
private static String getDefaultFiltersS() {
301301
return Utilities.isMac() ?
302-
"java.*, javax.*,\nsun.*, sunw.*, com.sun.*,\ncom.apple.*, apple.awt.*, apple.laf.*" : // NOI18N
303-
"java.*, javax.*,\nsun.*, sunw.*, com.sun.*"; // NOI18N
302+
"java.**, javax.**,\nsun.**, sunw.**, com.sun.**,\ncom.apple.**, apple.awt.**, apple.laf.**" : // NOI18N
303+
"java.**, javax.**,\nsun.**, sunw.**, com.sun.**"; // NOI18N
304304
}
305305

306306
private static String getDefaultRootsP(Application application) {

visualvm/profiling/src/com/sun/tools/visualvm/profiling/presets/SamplerCPUPanel.java

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@
5151
import javax.swing.event.DocumentEvent;
5252
import javax.swing.event.DocumentListener;
5353
import org.netbeans.lib.profiler.common.ProfilingSettings;
54-
import org.netbeans.lib.profiler.common.ProfilingSettingsPresets;
55-
import org.netbeans.lib.profiler.filters.GenericFilter;
5654
import org.netbeans.lib.profiler.filters.JavaTypeFilter;
5755
import org.netbeans.lib.profiler.global.CommonConstants;
56+
import org.netbeans.modules.profiler.api.ProfilerIDESettings;
5857
import org.openide.awt.Mnemonics;
5958
import org.openide.util.NbBundle;
6059

@@ -90,15 +89,19 @@ public SamplerCPUPanel() {
9089

9190

9291
public ProfilingSettings getSettings() {
93-
ProfilingSettings settings = ProfilingSettingsPresets.createCPUPreset();
94-
settings.setInstrScheme(CommonConstants.INSTRSCHEME_LAZY);
92+
ProfilingSettings settings = ProfilerIDESettings.getInstance().createDefaultProfilingSettings();
93+
settings.setProfilingType(ProfilingSettings.PROFILE_CPU_SAMPLING);
94+
settings.setCPUProfilingType(CommonConstants.CPU_SAMPLED);
9595

96-
String instrFilterString = getFilterValue();
97-
GenericFilter instrFilter = (instrFilterString.length() == 0 ||
98-
"*".equals(instrFilterString)) ? new GenericFilter() : // NOI18N
99-
new JavaTypeFilter(instrFilterString, inclFilterRadioButton.isSelected() ?
100-
GenericFilter.TYPE_INCLUSIVE : GenericFilter.TYPE_EXCLUSIVE);
101-
settings.setInstrumentationFilter(instrFilter);
96+
String filter = getFilterValue();
97+
if (filter.isEmpty() || "*".equals(filter) || "**".equals(filter)) { // NOI18N
98+
settings.setInstrumentationFilter(new JavaTypeFilter());
99+
} else {
100+
int filterType = inclFilterRadioButton.isSelected() ?
101+
JavaTypeFilter.TYPE_INCLUSIVE : JavaTypeFilter.TYPE_EXCLUSIVE;
102+
String filterValue = PresetsUtils.normalizeValue(filter);
103+
settings.setInstrumentationFilter(new JavaTypeFilter(filterValue, filterType));
104+
}
102105

103106
return settings;
104107
}
@@ -124,6 +127,8 @@ public void loadFromPreset(ProfilerPreset preset) {
124127
sampleRateCombo.setSelectedItem(preset.getSamplingRateS());
125128
refreshRateCombo.setSelectedItem(preset.getRefreshRateS());
126129
internalChange = false;
130+
131+
checkFilterValidity();
127132
}
128133

129134
public void saveToPreset(ProfilerPreset preset) {
@@ -151,35 +156,12 @@ private void checkFilterValidity() {
151156
}
152157

153158
public boolean isFilterValueValid() {
154-
// TODO
155-
// String[] filterParts = FilterUtils.getSeparateFilters(getFilterValue());
156-
//
157-
// for (int i = 0; i < filterParts.length; i++)
158-
// if (!FilterUtils.isValidProfilerFilter(filterParts[i])) return false;
159-
160-
return true;
159+
String filterValue = PresetsUtils.normalizeValue(getFilterValue());
160+
return PresetsUtils.isValidJavaValue(filterValue, true, false);
161161
}
162162

163163
private String getFilterValue() {
164-
StringBuilder convertedValue = new StringBuilder();
165-
166-
String[] filterValues = getFilterValues();
167-
168-
for (int i = 0; i < filterValues.length; i++) {
169-
String filterValue = filterValues[i].trim();
170-
171-
if ((i != (filterValues.length - 1)) && !filterValue.endsWith(",")) { // NOI18N
172-
filterValue = filterValue + ", "; // NOI18N
173-
}
174-
175-
convertedValue.append(filterValue);
176-
}
177-
178-
return convertedValue.toString();
179-
}
180-
181-
private String[] getFilterValues() {
182-
return filtersArea.getTextArea().getText().split("\\n"); // NOI18N
164+
return filtersArea.getTextArea().getText().trim();
183165
}
184166

185167

@@ -271,7 +253,7 @@ public void setEnabled(boolean enabled) {
271253

272254
filtersArea = createTextArea(2);
273255
filtersArea.getTextArea().setToolTipText(NbBundle.getMessage(
274-
SamplerCPUPanel.class, "TOOLTIP_Instrumentation_Filter")); // NOI18N
256+
SamplerCPUPanel.class, "TOOLTIP_Instrumentation_Filter_S")); // NOI18N
275257
filtersArea.getTextArea().getDocument().addDocumentListener(new DocumentListener() {
276258
public void insertUpdate(DocumentEvent e) { checkFilterValidity(); syncUI(); }
277259
public void removeUpdate(DocumentEvent e) { checkFilterValidity(); syncUI(); }

visualvm/sampler/src/com/sun/tools/visualvm/sampler/Bundle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,7 @@ MSG_Gc_unsupported=perform GC not supported
114114
MSG_HeapDump_unsupported=heap dump not supported
115115

116116
MSG_ThreadMemory_unsupported=thread memory allocation not supported
117+
118+
MSG_Incorrect_CPU_settings=Provided CPU settings are invalid.
119+
120+
MSG_Incorrect_Memory_settings=Provided Memory settings are invalid.

visualvm/sampler/src/com/sun/tools/visualvm/sampler/SamplerImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import org.netbeans.lib.profiler.results.memory.SampledMemoryResultsSnapshot;
9393
import org.netbeans.modules.profiler.LoadedSnapshot;
9494
import org.netbeans.modules.profiler.ResultsManager;
95+
import org.netbeans.modules.profiler.api.ProfilerDialogs;
9596
import org.openide.DialogDisplayer;
9697
import org.openide.NotifyDescriptor;
9798
import org.openide.util.ImageUtilities;
@@ -381,6 +382,13 @@ private void updateButtons() {
381382

382383

383384
private void handleCPUProfiling() {
385+
if (!cpuSettings.settingsValid()) {
386+
cpuButton.setSelected(false);
387+
if (dvc != null) cpuSettings.showSettings(dvc);
388+
ProfilerDialogs.displayError(NbBundle.getMessage(SamplerImpl.class, "MSG_Incorrect_CPU_settings")); // NOI18N
389+
return;
390+
}
391+
384392
State currentState = getState();
385393
if (currentState.equals(State.CPU) ||
386394
currentState.equals(State.TERMINATED) ||
@@ -421,6 +429,13 @@ public void run() {
421429
}
422430

423431
private void handleMemoryProfiling() {
432+
if (!memorySettings.settingsValid()) {
433+
memoryButton.setSelected(false);
434+
if (dvc != null) memorySettings.showSettings(dvc);
435+
ProfilerDialogs.displayError(NbBundle.getMessage(SamplerImpl.class, "MSG_Incorrect_Memory_settings")); // NOI18N
436+
return;
437+
}
438+
424439
State currentState = getState();
425440
if (currentState.equals(State.MEMORY) ||
426441
currentState.equals(State.TERMINATED) ||

visualvm/sampler/src/com/sun/tools/visualvm/sampler/cpu/CPUSamplerSupport.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ public boolean startSampling(ProfilingSettings settings, int samplingRate, int r
162162
refresher.setRefreshRate(refreshRate);
163163

164164
final StackTraceSnapshotBuilder _builder = builder;
165-
SwingUtilities.invokeLater(new Runnable() {
165+
if (cpuView != null) SwingUtilities.invokeLater(new Runnable() {
166166
public void run() {
167167
cpuView.setBuilder(_builder);
168+
cpuView.starting();
168169
// cpuView.setResultsPanel(new SampledLivePanel2(builder));
169170
}
170171
});
@@ -186,6 +187,12 @@ public void actionPerformed(ActionEvent e) {
186187
}
187188

188189
public synchronized void stopSampling() {
190+
if (cpuView != null) SwingUtilities.invokeLater(new Runnable() {
191+
public void run() {
192+
cpuView.stopping();
193+
}
194+
});
195+
189196
if (samplerTask != null) {
190197
samplerTask.cancel();
191198
samplerTask = null;
@@ -197,11 +204,16 @@ public synchronized void stopSampling() {
197204
}
198205

199206
public synchronized void terminate() {
207+
if (cpuView != null) SwingUtilities.invokeLater(new Runnable() {
208+
public void run() {
209+
cpuView.terminated();
210+
}
211+
});
212+
200213
if (timer != null) {
201214
timer.cancel();
202215
timer = null;
203216
}
204-
if (cpuView != null) cpuView.terminate();
205217
if (threadCPUView != null) threadCPUView.terminate();
206218
builder = null; // release data
207219
}

visualvm/sampler/src/com/sun/tools/visualvm/sampler/cpu/CPUSettingsSupport.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ public abstract class CPUSettingsSupport {
4646
private SamplerCPUPanel panel;
4747
private PresetSelector selector;
4848

49+
private DataViewComponent.DetailsView detailsView;
50+
4951

5052
public DataViewComponent.DetailsView getDetailsView() {
51-
return new DataViewComponent.DetailsView(NbBundle.getMessage(
52-
CPUSettingsSupport.class, "LBL_Cpu_settings"), null, 10, // NOI18N
53-
new ScrollableContainer(createPanel()), null);
53+
if (detailsView == null) {
54+
detailsView = new DataViewComponent.DetailsView(NbBundle.getMessage(
55+
CPUSettingsSupport.class, "LBL_Cpu_settings"), null, 10, // NOI18N
56+
new ScrollableContainer(createPanel()), null);
57+
}
58+
return detailsView;
5459
}
5560

5661

@@ -68,6 +73,10 @@ public void saveSettings() {
6873

6974
public boolean settingsValid() { return panel.settingsValid(); }
7075

76+
public void showSettings(DataViewComponent dvc) {
77+
dvc.selectDetailsView(getDetailsView());
78+
}
79+
7180
public abstract PresetSelector createSelector(Runnable presetSynchronizer);
7281

7382

visualvm/sampler/src/com/sun/tools/visualvm/sampler/cpu/CPUView.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,11 @@
4848
import org.netbeans.lib.profiler.ui.cpu.LiveCPUView;
4949
import org.netbeans.lib.profiler.ui.swing.GrayLabel;
5050
import org.netbeans.lib.profiler.ui.swing.MultiButtonGroup;
51-
import org.netbeans.modules.profiler.actions.ResetResultsAction;
5251
import org.netbeans.modules.profiler.actions.TakeSnapshotAction;
5352
import org.netbeans.modules.profiler.api.GoToSource;
5453
import org.netbeans.modules.profiler.api.icons.GeneralIcons;
5554
import org.netbeans.modules.profiler.api.icons.Icons;
5655
import org.netbeans.modules.profiler.api.icons.ProfilerIcons;
57-
import org.openide.util.Exceptions;
5856
import org.openide.util.Lookup;
5957
import org.openide.util.NbBundle;
6058

@@ -118,6 +116,7 @@ void setBuilder(StackTraceSnapshotBuilder builder) {
118116

119117
void initSession() {
120118
pdSnapshotButton.setEnabled(false);
119+
// pdResetResultsButton.setEnabled(false);
121120
}
122121

123122
void refresh() {
@@ -129,18 +128,39 @@ void refresh() {
129128
CPUResultsSnapshot snapshot = builder.createSnapshot(System.currentTimeMillis());
130129
cpuView.setData(snapshot, true);
131130
} catch (CPUResultsSnapshot.NoDataAvailableException ex) {
132-
Exceptions.printStackTrace(ex);
131+
// no problem, just no data matching the provided filter yet
132+
// Exceptions.printStackTrace(ex);
133133
}
134134

135135
pdSnapshotButton.setEnabled(snapshotDumper != null);
136+
// pdResetResultsButton.setEnabled(pdSnapshotButton.isEnabled());
136137
}
137-
138-
void terminate() {
138+
139+
void starting() {
140+
lrPauseButton.setEnabled(true);
141+
lrRefreshButton.setEnabled(false);
142+
lrDeltasButton.setEnabled(true);
143+
}
144+
145+
void stopping() {
139146
lrPauseButton.setEnabled(false);
140147
lrRefreshButton.setEnabled(false);
148+
lrDeltasButton.setEnabled(false);
149+
}
150+
151+
void terminated() {
152+
lrPauseButton.setEnabled(false);
153+
lrRefreshButton.setEnabled(false);
154+
lrDeltasButton.setEnabled(false);
141155
threaddumpButton.setEnabled(false);
142156
}
143157

158+
// void terminate() {
159+
// lrPauseButton.setEnabled(false);
160+
// lrRefreshButton.setEnabled(false);
161+
// threaddumpButton.setEnabled(false);
162+
// }
163+
144164

145165
private JLabel lrLabel;
146166
private JToggleButton lrPauseButton;
@@ -149,7 +169,7 @@ void terminate() {
149169

150170
private JLabel pdLabel;
151171
private JButton pdSnapshotButton;
152-
private JButton pdResetResultsButton;
172+
// private JButton pdResetResultsButton;
153173

154174
private boolean popupPause;
155175
private JToggleButton[] toggles;
@@ -297,8 +317,8 @@ protected void fireActionPerformed(ActionEvent event) {
297317
// pdSnapshotButton.setHideActionText(true);
298318
pdSnapshotButton.setText(Bundle.MethodsFeatureUI_snapshot());
299319

300-
pdResetResultsButton = new JButton(ResetResultsAction.getInstance());
301-
pdResetResultsButton.setHideActionText(true);
320+
// pdResetResultsButton = new JButton(ResetResultsAction.getInstance());
321+
// pdResetResultsButton.setHideActionText(true);
302322

303323
toolbar = ProfilerToolbar.create(true);
304324

@@ -334,8 +354,8 @@ protected void fireActionPerformed(ActionEvent event) {
334354
toolbar.add(pdLabel);
335355
toolbar.addSpace(2);
336356
toolbar.add(pdSnapshotButton);
337-
toolbar.addSpace(3);
338-
toolbar.add(pdResetResultsButton);
357+
// toolbar.addSpace(3);
358+
// toolbar.add(pdResetResultsButton);
339359

340360
toolbar.addFiller();
341361

visualvm/sampler/src/com/sun/tools/visualvm/sampler/memory/MemorySettingsSupport.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package com.sun.tools.visualvm.sampler.memory;
2727

2828
import com.sun.tools.visualvm.core.ui.components.DataViewComponent;
29+
import com.sun.tools.visualvm.core.ui.components.ScrollableContainer;
2930
import com.sun.tools.visualvm.profiling.presets.PresetSelector;
3031
import com.sun.tools.visualvm.profiling.presets.SamplerMemoryPanel;
3132
import java.awt.BorderLayout;
@@ -45,11 +46,16 @@ public abstract class MemorySettingsSupport {
4546
private SamplerMemoryPanel panel;
4647
private PresetSelector selector;
4748

49+
private DataViewComponent.DetailsView detailsView;
50+
4851

4952
public DataViewComponent.DetailsView getDetailsView() {
50-
return new DataViewComponent.DetailsView(NbBundle.getMessage(
51-
MemorySettingsSupport.class, "LBL_Memory_settings"), null, 20, // NOI18N
52-
createPanel(), null);
53+
if (detailsView == null) {
54+
detailsView = new DataViewComponent.DetailsView(NbBundle.getMessage(
55+
MemorySettingsSupport.class, "LBL_Memory_settings"), null, 20, // NOI18N
56+
new ScrollableContainer(createPanel()), null);
57+
}
58+
return detailsView;
5359
}
5460

5561

@@ -67,6 +73,10 @@ public void saveSettings() {
6773

6874
public boolean settingsValid() { return panel.settingsValid(); }
6975

76+
public void showSettings(DataViewComponent dvc) {
77+
dvc.selectDetailsView(getDetailsView());
78+
}
79+
7080
public abstract PresetSelector createSelector(Runnable presetSynchronizer);
7181

7282

0 commit comments

Comments
 (0)