Java 如何在 VisualVM 中显示调用树?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18561467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 09:03:26  来源:igfitidea点击:

How to display the call tree in VisualVM?

javavisualvm

提问by John Threepwood

When profiling the CPU time of an application with VisualVM, one can see a "Call Tree" tab after taking a snapshot. But in my case, the call tree only shows some RMI TCP classes and methods, but no single class of my application.

使用 VisualVM 分析应用程序的 CPU 时间时,可以在拍摄快照后看到“调用树”选项卡。但在我的例子中,调用树只显示了一些 RMI TCP 类和方法,但没有显示我的应用程序的单个类。

How can I display the correct call tree?

如何显示正确的调用树?

enter image description here

在此处输入图片说明

采纳答案by Ryan

Possibilities

可能性

  1. The Profiler settings are excluding your classes. Change the excludes in the Profiler settings.
  2. Your application was idle while the profiler was running. Attach the profiler then cause the program to execute the code you want to profile.
  3. You might be profiling the wrong JVM. RMI makes it pretty easy to call into another JVM. Maybe you need to be profiling the other side of that RMI connection.
  1. Profiler 设置不包括您的类。更改 Profiler 设置中的排除项。
  2. 您的应用程序在分析器运行时处于空闲状态。附加分析器然后使程序执行您要分析的代码。
  3. 您可能正在分析错误的 JVM。RMI 使调用另一个 JVM 变得非常容易。也许您需要分析该 RMI 连接的另一端。

There is a "Settings" checkbox on the Profiler tab. If you check the Settings box another panel will show up that lets you configure what classes the profiler collects data about.

Profiler 选项卡上有一个“设置”复选框。如果您选中“设置”框,则会出现另一个面板,让您可以配置探查器收集有关哪些类的数据。

Here is a screenshot. screeshot of jvisualvm with Profiler "Settings" box checked.

这是一个屏幕截图。 选中 Profiler“设置”框的 jvisualvm 截图。

回答by Holger

The call tree only shows threads which really ran during the sampling/profiling (were not sleeping all the time) and whose stack traces got not filtered out entirely. The filter is set up before starting a sampling or profiling. When enabling the “settings” checkbox in the upper right corner you can set up the filter. In case of the sampler you can also set up the sampling frequency which is a trade-off between performance and the risk to oversee a running state of a thread. But it could be that your application was really idle during the profiling. Then the only threads you see are the RMI threads maintaining the connection to VisualVM.

调用树仅显示在采样/分析期间真正运行的线程(并非一直处于休眠状态)并且其堆栈跟踪未被完全过滤掉。在开始采样或分析之前设置过滤器。当启用右上角的“设置”复选框时,您可以设置过滤器。在采样器的情况下,您还可以设置采样频率,这是性能和监督线程运行状态的风险之间的权衡。但可能是您的应用程序在分析期间真的处于空闲状态。然后,您看到的唯一线程是维护与 VisualVM 的连接的 RMI 线程。

回答by Aritz Lopez

As @Holger said, the profiler's/sampler's snapshotsare supposed to only show running threads. However, I found by personal experience that sampling snapshots sometimes show more threads that profiling ones.

正如@Holger 所说,分析器/采样器的快照应该只显示正在运行的线程。但是,根据个人经验,我发现采样快照有时会显示比分析快照更多的线程。

Moreover, VisualVM's sampler enables you to see each thread's CPU Time in real-time (without taking a snapshot), no matter if it's running, sleeping, waiting or monitoring.

此外,VisualVM 的采样器使您能够实时查看每个线程的 CPU 时间(无需拍摄快照),无论它是在运行、睡眠、等待还是监控。

I do not understand why this happens, since profiling should be more accurate than sampling (see here the difference), but it does.

我不明白为什么会发生这种情况,因为分析应该比采样更准确(请参阅此处的差异),但确实如此。

All in all, I'd recommend that you try the sampler, and see if it works.

总而言之,我建议您尝试使用采样器,看看它是否有效。