100
100
final class SamplerImpl {
101
101
102
102
private static final Logger LOGGER = Logger .getLogger (SamplerImpl .class .getName ());
103
+
104
+ private static final boolean MEMORY_INITIALLY_AVAILABLE = Boolean .getBoolean ("visualvm.graalsampler.memory.alwaysEnabled" ); // NOI18N
103
105
104
106
private static enum State { TERMINATED , INACTIVE , CPU , MEMORY , TRANSITION };
105
107
@@ -108,13 +110,16 @@ private static enum State { TERMINATED, INACTIVE, CPU, MEMORY, TRANSITION };
108
110
109
111
private HTMLTextArea summaryArea ;
110
112
private String cpuStatus = NbBundle .getMessage (SamplerImpl .class , "MSG_Checking_Availability" ); // NOI18N
111
- private String memoryStatus = NbBundle .getMessage (SamplerImpl .class , "MSG_Checking_Availability" ); // NOI18N
113
+ private String memoryStatus = NbBundle .getMessage (SamplerImpl .class , MEMORY_INITIALLY_AVAILABLE ? "MSG_Memory_experimental2" : "MSG_Memory_experimental1" ); // NOI18N
114
+ // private String memoryStatus = NbBundle.getMessage(SamplerImpl.class, "MSG_Checking_Availability"); // NOI18N
112
115
113
116
private boolean cpuProfilingSupported ;
114
117
private AbstractSamplerSupport cpuSampler ;
115
118
private CPUSettingsSupport cpuSettings ;
116
119
117
- private boolean memoryProfilingSupported ;
120
+ private boolean memoryProfilingSupported = MEMORY_INITIALLY_AVAILABLE ;
121
+ private boolean memoryInitializationPending ;
122
+ // private boolean memoryProfilingSupported;
118
123
private AbstractSamplerSupport memorySampler ;
119
124
private MemorySettingsSupport memorySettings ;
120
125
@@ -170,7 +175,7 @@ public void hierarchyChanged(HierarchyEvent e) {
170
175
if ((e .getChangeFlags () & HierarchyEvent .SHOWING_CHANGED ) != 0 ) {
171
176
if (view .isShowing ()) {
172
177
initializeCpuSampling ();
173
- initializeMemorySampling ();
178
+ // initializeMemorySampling();
174
179
view .removeHierarchyListener (this );
175
180
}
176
181
}
@@ -333,7 +338,7 @@ private void updateButtons() {
333
338
cpuButton .setEnabled (cpuProfilingSupported );
334
339
335
340
memoryButton .setSelected (false );
336
- memoryButton .setEnabled (memoryProfilingSupported );
341
+ memoryButton .setEnabled (memoryProfilingSupported || memoryInitializationPending );
337
342
338
343
stopButton .setEnabled (false );
339
344
@@ -344,7 +349,7 @@ private void updateButtons() {
344
349
cpuButton .setEnabled (true );
345
350
346
351
memoryButton .setSelected (false );
347
- memoryButton .setEnabled (memoryProfilingSupported );
352
+ memoryButton .setEnabled (memoryProfilingSupported || memoryInitializationPending );
348
353
349
354
stopButton .setEnabled (true );
350
355
@@ -422,50 +427,57 @@ public void run() {
422
427
}
423
428
424
429
private void handleMemoryProfiling () {
425
- if (!memorySettings .settingsValid ()) {
426
- memoryButton .setSelected (false );
427
- if (dvc != null ) memorySettings .showSettings (dvc );
428
- ProfilerDialogs .displayError (NbBundle .getMessage (SamplerImpl .class , "MSG_Incorrect_Memory_settings" )); // NOI18N
429
- return ;
430
- }
431
-
432
- State currentState = getState ();
433
- if (currentState .equals (State .MEMORY ) ||
434
- currentState .equals (State .TERMINATED ) ||
435
- currentState .equals (State .TRANSITION )) return ;
436
- setState (State .TRANSITION );
437
-
438
- final Runnable sessionStarter = new Runnable () {
430
+ Runnable memoryProfilingHandler = new Runnable () {
439
431
public void run () {
440
- SwingUtilities .invokeLater (new Runnable () {
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
+
439
+ State currentState = getState ();
440
+ if (currentState .equals (State .MEMORY ) ||
441
+ currentState .equals (State .TERMINATED ) ||
442
+ currentState .equals (State .TRANSITION )) return ;
443
+ setState (State .TRANSITION );
444
+
445
+ final Runnable sessionStarter = new Runnable () {
441
446
public void run () {
442
- setCurrentViews (NbBundle .getMessage (SamplerImpl .class ,
443
- "LBL_Memory_samples" ), memorySampler .getDetailsView ()); // NOI18N
444
- RequestProcessor .getDefault ().post (new Runnable () {
447
+ SwingUtilities .invokeLater (new Runnable () {
445
448
public void run () {
446
- memorySettings .saveSettings ();
447
- setState (memorySampler .startSampling (
448
- memorySettings .getSettings (),
449
- memorySettings .getSamplingRate (),
450
- memorySettings .getRefreshRate ()) ?
451
- State .MEMORY : State .INACTIVE );
449
+ setCurrentViews (NbBundle .getMessage (SamplerImpl .class ,
450
+ "LBL_Memory_samples" ), memorySampler .getDetailsView ()); // NOI18N
451
+ RequestProcessor .getDefault ().post (new Runnable () {
452
+ public void run () {
453
+ memorySettings .saveSettings ();
454
+ setState (memorySampler .startSampling (
455
+ memorySettings .getSettings (),
456
+ memorySettings .getSamplingRate (),
457
+ memorySettings .getRefreshRate ()) ?
458
+ State .MEMORY : State .INACTIVE );
459
+ }
460
+ });
452
461
}
453
462
});
454
463
}
455
- });
456
- }
457
- };
464
+ };
458
465
459
- if (currentState .equals (State .CPU )) {
460
- RequestProcessor .getDefault ().post (new Runnable () {
461
- public void run () {
462
- cpuSampler .stopSampling ();
466
+ if (currentState .equals (State .CPU )) {
467
+ RequestProcessor .getDefault ().post (new Runnable () {
468
+ public void run () {
469
+ cpuSampler .stopSampling ();
470
+ sessionStarter .run ();
471
+ }
472
+ });
473
+ } else {
463
474
sessionStarter .run ();
464
475
}
465
- });
466
- } else {
467
- sessionStarter .run ();
468
- }
476
+ }
477
+ };
478
+
479
+ if (memorySampler == null ) initializeMemorySampling (memoryProfilingHandler );
480
+ else if (memoryProfilingSupported ) memoryProfilingHandler .run ();
469
481
}
470
482
471
483
private void handleStopProfiling () {
@@ -579,7 +591,7 @@ public void run() {
579
591
});
580
592
}
581
593
582
- private void initializeMemorySampling () {
594
+ private void initializeMemorySampling (Runnable onSuccess ) {
583
595
RequestProcessor .getDefault ().post (new Runnable () {
584
596
public void run () {
585
597
MemoryHistogramProvider histogramProvider = new MemoryHistogramProvider (application );
@@ -588,8 +600,17 @@ public void run() {
588
600
if (status != null ) {
589
601
SwingUtilities .invokeLater (new Runnable () {
590
602
public void run () {
591
- memoryStatus = status ;
592
- refreshSummary ();
603
+ memoryProfilingSupported = false ; // may be initially true (visualvm.graalsampler.memory.alwaysEnabled)
604
+ memoryInitializationPending = false ;
605
+
606
+ handleStopProfiling ();
607
+
608
+ // memoryStatus = status;
609
+ // refreshSummary();
610
+ updateButtons ();
611
+ updateSettings ();
612
+
613
+ ProfilerDialogs .displayError (status , NbBundle .getMessage (SamplerImpl .class , "CAP_Memory_error" ), null ); // NOI18N
593
614
}
594
615
});
595
616
return ;
@@ -671,11 +692,13 @@ public void takeHeapDump(boolean openView) {
671
692
};
672
693
SwingUtilities .invokeLater (new Runnable () {
673
694
public void run () {
695
+ int i = 0 ;
696
+
674
697
String avail = NbBundle .getMessage (SamplerImpl .class ,
675
698
"MSG_Available" ); // NOI18N
676
699
if (noPerformGC != null || noHeapDump != null ) {
677
700
String [] msgs = new String [3 ];
678
- int i = 0 ;
701
+ // int i = 0;
679
702
if (noHeapDump != null ) {
680
703
msgs [i ++] = noHeapDump ;
681
704
}
@@ -688,17 +711,22 @@ public void run() {
688
711
} else if (i == 2 ) {
689
712
avail = NbBundle .getMessage (SamplerImpl .class ,
690
713
"MSG_Available_details2" , msgs [0 ], msgs [1 ]); // NOI18N
691
- } else {
692
- avail = NbBundle .getMessage (SamplerImpl .class ,
693
- "MSG_Available_details3" , msgs [0 ], msgs [1 ], msgs [2 ]); // NOI18N
714
+ // } else {
715
+ // avail = NbBundle.getMessage(SamplerImpl.class,
716
+ // "MSG_Available_details3", msgs[0], msgs[1], msgs[2]); // NOI18N
694
717
}
695
718
}
696
- memoryStatus = avail + " " + NbBundle .getMessage ( // NOI18N
697
- SamplerImpl .class , "MSG_Press_mem" ); // NOI18N
719
+ // memoryStatus = avail + " " + NbBundle.getMessage( // NOI18N
720
+ // SamplerImpl.class, "MSG_Press_mem"); // NOI18N
698
721
memoryProfilingSupported = true ;
699
- refreshSummary ();
722
+ memoryInitializationPending = false ;
723
+ // refreshSummary();
700
724
updateButtons ();
701
725
updateSettings ();
726
+
727
+ if (i > 0 ) ProfilerDialogs .displayWarningDNSA (avail , NbBundle .getMessage (SamplerImpl .class , "CAP_Memory_warning" ), null , SamplerImpl .class .getName (), false ); // NOI18N
728
+
729
+ onSuccess .run ();
702
730
}
703
731
});
704
732
}
@@ -713,7 +741,18 @@ private synchronized Timer getTimer() {
713
741
}
714
742
715
743
private DataViewComponent .DetailsView [] createSummaryView () {
716
- summaryArea = new HTMLTextArea ();
744
+ summaryArea = new HTMLTextArea () {
745
+ protected void showURL (URL url ) {
746
+ SwingUtilities .invokeLater (new Runnable () {
747
+ public void run () {
748
+ memoryButton .setEnabled (true );
749
+ memoryInitializationPending = true ;
750
+ memoryStatus = NbBundle .getMessage (SamplerImpl .class , "MSG_Memory_experimental2" ); // NOI18N
751
+ refreshSummary ();
752
+ }
753
+ });
754
+ }
755
+ };
717
756
summaryArea .setBorder (BorderFactory .createEmptyBorder (10 , 10 , 10 , 10 ));
718
757
719
758
refreshSummary ();
0 commit comments