[译] 07-Profiling Applications
分析应用程序
VisualVM 在特定于该应用程序的选项卡中显示本地和远程应用程序的数据。可以打开多个应用程序选项卡。每个应用程序选项卡都包含显示有关应用程序的不同类型信息的子选项卡。
Profiling applications
应用程序的 "探查器" 选项卡使您可以启动和停止本地应用程序的性能分析会话。分析结果显示在 "探查器" 选项卡中。可以使用工具栏刷新分析结果, 调用垃圾回收并保存分析数据。
- CPU Profiling. Choose this to profile the performance of the application.
- Memory Profiling. Choose this to analyze the memory usage of the application. The results display the objects allocated by the application and the class allocating those objects.
启动分析会话时, VisualVM 会附加到本地应用程序, 并开始收集分析数据。当分析结果可用时, 它们会自动显示在 "探查器" 选项卡中。
Using the toolbar
You can use the following buttons in the Profiling Results toolbar to work with profiling results:
- Update Result Automatically. When active, the displayed profiling results are automatically updated at short intervals (about 2 seconds).
- Update Result Now. Click to update results immediately.
- Run Garbage Collection. Click to run garbage collection.
- Reset Collected Results. Click to discard the already accumulated profiling results.
- Take Snapshot. Click to take a snapshot of the current profile data. When you take a snapshot, the snapshot is opened in a new sub-tab.
- Save Current View. Click to save the current view of the profiling results as a .png image file. When you click the button you are prompted to choose the location where you want to save the image.
Filtering profiling results
The filter box below the profiling results enables you to filter the displayed results according to the name of the method. To filter the results, enter a term in the method name filter box, select which filtering method to use and press Return. You can see and select previous filter terms by clicking the arrow to the right of the method name filter box.
Modifying profiling settings
The VisualVM profiling tool supplies default settings for profiling applications. You can view the default settings by selecting the Settings checkbox in the Profiler tab. You can modify the profiling settings when no profiling session is in progress.
CPU Profiling
This profile command returns detailed data on method-level CPU performance (execution time), showing the total execution time and number of invocations for each method. When analyzing application performance, VisualVM instruments all of the methods of the profiled application. Threads emit the "method entry" event when entering a method and generate the corresponding "method exit" event when exiting the method. Both of these events contain timestamps. This data is processed in real time.
Screenshot of Profiler tab showing CPU profiling results
Screenshot of Profiler tab showing CPU profiling settings
Memory Profiling
显示内存分析设置的探查器选项卡截图
Taking Profiler Snapshots
CPU 分析快照截图
有关探查器快照的详细信息, 请参阅以下文档: