[译] 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

[译] 07-Profiling Applications

Screenshot of Profiler tab showing CPU profiling settings

[译] 07-Profiling Applications

Memory Profiling

分析内存使用情况时, VisualVM 开始检测已加载的类, 并显示表中每个类 (包括数组类) 分配的对象总数。对于 Java 虚拟机 (JVM) 中当前加载的类, 分析结果显示自分析会话启动以来分配的对象的大小和数量。当新对象被分配并加载新类时, 结果将自动更新。
VisualVM 以绝对数字和百分比显示对象的数量。分配的字节也显示为表示字节百分比的图表, 以及每个类分配的字节总数。
显示内存分析结果探查器选项卡截图
[译] 07-Profiling Applications

显示内存分析设置探查器选项卡截图

[译] 07-Profiling Applications

Taking Profiler Snapshots

VisualVM 使您可以利用探查器快照来捕获性能分析会话的结果。探查器快照在拍摄快照时捕获结果。要拍摄快照, 请在分析会话正在进行时, 单击工具栏中的 "收集结果" 按钮快照。当您拍摄快照时, 快照将以 "应用程序" 选项卡中的选项卡打开。快照的节点也会出现在应用程序窗口的应用程序节点下。
内存分析快照截图
[译] 07-Profiling Applications

CPU 分析快照截图

[译] 07-Profiling Applications

有关探查器快照详细信息, 请参阅以下文档:


Return to the VisualVM Documentation index