Skip to content

Commit eb73352

Browse files
committed
Profiler stabilization and cleanup
1 parent b66bca3 commit eb73352

File tree

6 files changed

+107
-243
lines changed

6 files changed

+107
-243
lines changed

visualvm/profiler/src/com/sun/tools/visualvm/profiler/ApplicationProfilerView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public void run() {
376376
}
377377

378378

379-
public void profilingStateChanged(ProfilingStateEvent e) { refreshStatus(); }
379+
public void profilingStateChanged(ProfilingStateEvent e) { refreshStatus(); if (results != null) results.sessionStateChanged(e.getNewState()); }
380380
public void threadsMonitoringChanged() { refreshStatus(); }
381381
public void instrumentationChanged(int oldInstrType, int currentInstrType) { refreshStatus(); }
382382
public void serverStateChanged(int serverState, int serverProgress) {}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ MSG_calibration=<html><br><b>Profiler calibration will be performed.</b><br><br>
4545

4646
MSG_profiling_running_methods=profiling running ({0} methods instrumented)
4747

48-
MSG_profiling_running_classes_1=profiling running ({0} classes instrumented, tracking each object)
48+
#MSG_profiling_running_classes_1=profiling running ({0} classes instrumented, tracking each object)
49+
MSG_profiling_running_classes_1=profiling running ({0} classes instrumented)
4950

5051
MSG_profiling_running_classes_2=profiling running ({0} classes instrumented, tracking each 2nd object)
5152

visualvm/profiler/src/com/sun/tools/visualvm/profiler/CPULivePanel.java

Lines changed: 37 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.netbeans.modules.profiler.api.icons.GeneralIcons;
4848
import org.netbeans.modules.profiler.api.icons.Icons;
4949
import org.netbeans.modules.profiler.api.icons.ProfilerIcons;
50-
import org.openide.util.Exceptions;
5150
import org.openide.util.Lookup;
5251
import org.openide.util.NbBundle;
5352

@@ -56,9 +55,6 @@
5655
* @author Jiri Sedlacek
5756
*/
5857
@NbBundle.Messages({
59-
// "MethodsFeatureUI_viewHotSpots=Hot spots",
60-
// "MethodsFeatureUI_viewCallTree=Call tree",
61-
// "MethodsFeatureUI_viewCombined=Combined",
6258
"MethodsFeatureUI_selectedMethods=Selected methods",
6359
"MethodsFeatureUI_liveResults=Results:",
6460
"MethodsFeatureUI_pauseResults=Pause live results",
@@ -92,28 +88,10 @@ class CPULivePanel extends ProfilingResultsSupport.ResultsView {
9288
}
9389

9490

91+
// -------------------------------------------------------------------------
9592

96-
// --- API implementation --------------------------------------------------
97-
98-
boolean hasResultsUI() {
99-
return cpuView != null;
100-
}
101-
102-
void sessionStateChanged(int sessionState) {
103-
refreshToolbar(sessionState);
104-
}
105-
106-
107-
void resetPause() {
108-
if (lrPauseButton != null) lrPauseButton.setSelected(false);
109-
}
110-
111-
void setForceRefresh() {
112-
if (updater != null) updater.setForceRefresh(true);
113-
}
114-
115-
void refreshData() throws ClientUtils.TargetAppOrVMTerminated {
116-
if (updater != null) updater.update();
93+
void refreshResults() {
94+
refreshResults(false);
11795
}
11896

11997
void resetResults() {
@@ -127,25 +105,44 @@ void resetResults() {
127105
}
128106
}
129107

130-
131-
void cleanup() {
132-
if (updater != null) updater.cleanup();
133-
134-
if (resetter != null) {
135-
resetter.unregisterView(this);
136-
resetter = null;
137-
}
108+
void sessionStateChanged(int sessionState) {
109+
refreshToolbar(sessionState);
138110
}
139111

112+
140113
// -------------------------------------------------------------------------
141114

115+
private void refreshResults(final boolean forceRefresh) {
116+
RESULTS_PROCESSOR.post(new Runnable() {
117+
public void run() {
118+
try {
119+
if (updater != null) {
120+
if (forceRefresh) updater.setForceRefresh(true);
121+
updater.update();
122+
}
123+
// } catch (ClientUtils.TargetAppOrVMTerminated ex) {
124+
} catch (Throwable t) {
125+
if (updater != null) {
126+
updater.cleanup();
127+
updater = null;
128+
}
129+
130+
if (resetter != null) {
131+
resetter.unregisterView(CPULivePanel.this);
132+
resetter = null;
133+
}
134+
}
135+
}
136+
});
137+
}
142138

143139

140+
// -------------------------------------------------------------------------
141+
144142
private JLabel lrLabel;
145143
private JToggleButton lrPauseButton;
146144
private JButton lrRefreshButton;
147145
private JToggleButton lrDeltasButton;
148-
// private ActionPopupButton lrView;
149146

150147
private JLabel pdLabel;
151148
private JButton pdSnapshotButton;
@@ -221,27 +218,16 @@ protected void foundInReverseCalls() {
221218
lrPauseButton = new JToggleButton(Icons.getIcon(GeneralIcons.PAUSE)) {
222219
protected void fireItemStateChanged(ItemEvent event) {
223220
boolean paused = isSelected();
224-
updater.setPaused(paused);
221+
if (updater != null) updater.setPaused(paused);
225222
lrRefreshButton.setEnabled(paused);
226-
if (!paused) try {
227-
updater.setForceRefresh(true);
228-
updater.update();
229-
} catch (ClientUtils.TargetAppOrVMTerminated ex) {
230-
cleanup();
231-
}
232-
////// refreshToolbar(getSessionState());
223+
if (!paused) refreshResults(true);
233224
}
234225
};
235226
lrPauseButton.setToolTipText(Bundle.MethodsFeatureUI_pauseResults());
236227

237228
lrRefreshButton = new JButton(Icons.getIcon(GeneralIcons.UPDATE_NOW)) {
238229
protected void fireActionPerformed(ActionEvent e) {
239-
try {
240-
updater.setForceRefresh(true);
241-
updater.update();
242-
} catch (ClientUtils.TargetAppOrVMTerminated ex) {
243-
cleanup();
244-
}
230+
refreshResults(true);
245231
}
246232
};
247233
lrRefreshButton.setToolTipText(Bundle.MethodsFeatureUI_updateResults());
@@ -264,79 +250,43 @@ protected void fireActionPerformed(ActionEvent e) {
264250
protected void fireActionPerformed(ActionEvent e) {
265251
super.fireActionPerformed(e);
266252
cpuView.setView(isSelected(), toggles[1].isSelected(), toggles[2].isSelected());
267-
try {
268-
updater.setForceRefresh(true);
269-
updater.update();
270-
} catch (ClientUtils.TargetAppOrVMTerminated ex) {
271-
cleanup();
272-
}
253+
refreshResults(true);
273254
}
274255
};
275256
forwardCalls.putClientProperty("JButton.buttonType", "segmented"); // NOI18N
276257
forwardCalls.putClientProperty("JButton.segmentPosition", "first"); // NOI18N
277258
forwardCalls.setToolTipText(Bundle.MethodsFeatureUI_viewForward());
278259
group.add(forwardCalls);
279260
toggles[0] = forwardCalls;
280-
// toolbar.add(forwardCalls);
281261
forwardCalls.setSelected(true);
282262

283263
JToggleButton hotSpots = new JToggleButton(Icons.getIcon(ProfilerIcons.TAB_HOTSPOTS)) {
284264
protected void fireActionPerformed(ActionEvent e) {
285265
super.fireActionPerformed(e);
286266
cpuView.setView(toggles[0].isSelected(), isSelected(), toggles[2].isSelected());
287-
try {
288-
updater.setForceRefresh(true);
289-
updater.update();
290-
} catch (ClientUtils.TargetAppOrVMTerminated ex) {
291-
cleanup();
292-
}
267+
refreshResults(true);
293268
}
294269
};
295270
hotSpots.putClientProperty("JButton.buttonType", "segmented"); // NOI18N
296271
hotSpots.putClientProperty("JButton.segmentPosition", "middle"); // NOI18N
297272
hotSpots.setToolTipText(Bundle.MethodsFeatureUI_viewHotSpots());
298273
group.add(hotSpots);
299274
toggles[1] = hotSpots;
300-
// toolbar.add(hotSpots);
301275
hotSpots.setSelected(false);
302276

303277
JToggleButton reverseCalls = new JToggleButton(Icons.getIcon(ProfilerIcons.NODE_REVERSE)) {
304278
protected void fireActionPerformed(ActionEvent e) {
305279
super.fireActionPerformed(e);
306280
cpuView.setView(toggles[0].isSelected(), toggles[1].isSelected(), isSelected());
307-
try {
308-
updater.setForceRefresh(true);
309-
updater.update();
310-
} catch (ClientUtils.TargetAppOrVMTerminated ex) {
311-
cleanup();
312-
}
281+
refreshResults(true);
313282
}
314283
};
315284
reverseCalls.putClientProperty("JButton.buttonType", "segmented"); // NOI18N
316285
reverseCalls.putClientProperty("JButton.segmentPosition", "last"); // NOI18N
317286
reverseCalls.setToolTipText(Bundle.MethodsFeatureUI_viewReverse());
318287
group.add(reverseCalls);
319288
toggles[2] = reverseCalls;
320-
// toolbar.add(reverseCalls);
321289
reverseCalls.setSelected(false);
322-
323-
// Action aCallTree = new AbstractAction() {
324-
// { putValue(NAME, Bundle.MethodsFeatureUI_viewCallTree()); }
325-
// public void actionPerformed(ActionEvent e) { setView(View.CALL_TREE); }
326-
//
327-
// };
328-
// Action aHotSpots = new AbstractAction() {
329-
// { putValue(NAME, Bundle.MethodsFeatureUI_viewHotSpots()); }
330-
// public void actionPerformed(ActionEvent e) { setView(View.HOT_SPOTS); }
331-
//
332-
// };
333-
// Action aCombined = new AbstractAction() {
334-
// { putValue(NAME, Bundle.MethodsFeatureUI_viewCombined()); }
335-
// public void actionPerformed(ActionEvent e) { setView(View.COMBINED); }
336-
//
337-
// };
338-
// lrView = new ActionPopupButton(aCallTree, aHotSpots, aCombined);
339-
// lrView.setToolTipText(Bundle.MethodsFeatureUI_resultsMode());
340290

341291
pdLabel = new GrayLabel(Bundle.MethodsFeatureUI_profilingData());
342292

@@ -385,18 +335,13 @@ protected void fireActionPerformed(ActionEvent e) {
385335
toolbar.add(pdResetResultsButton);
386336

387337

388-
// --- Sync UI ---------------------------------------------------------
389-
390-
// setView(View.HOT_SPOTS);
391338
cpuView.setView(true, false, false);
392-
////// sessionStateChanged(getSessionState());
393339

394340
}
395341

396342
private void refreshToolbar(final int state) {
397343
if (toolbar != null) SwingUtilities.invokeLater(new Runnable() {
398344
public void run() {
399-
// boolean running = isRunning(state);
400345
boolean running = state == Profiler.PROFILING_RUNNING;
401346
lrPauseButton.setEnabled(running);
402347
lrRefreshButton.setEnabled(!popupPause && running && lrPauseButton.isSelected());
@@ -405,20 +350,4 @@ public void run() {
405350
});
406351
}
407352

408-
409-
void refreshResults() {
410-
RESULTS_PROCESSOR.post(new Runnable() {
411-
public void run() {
412-
try {
413-
refreshData();
414-
} catch (ClientUtils.TargetAppOrVMTerminated ex) {
415-
cleanup();
416-
} catch (Throwable t) {
417-
Exceptions.printStackTrace(t);
418-
cleanup();
419-
}
420-
}
421-
});
422-
}
423-
424353
}

0 commit comments

Comments
 (0)