java 使用 VisualVM 在 Eclipse Indigo 中分析 JUnit

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11826680/
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-10-31 06:31:18  来源:igfitidea点击:

Profile JUnit in Eclipse Indigo using VisualVM

javajunitprofilingprofilervisualvm

提问by rnunes

How can I profile a JUnit Test, preferentially with Eclipse integrated support? I'm trying to do it using VisualVM but apparently it can't be done.

如何优先使用 Eclipse 集成支持来分析 JUnit 测试?我正在尝试使用 VisualVM 来做到这一点,但显然无法做到。

I'm using Windows 7 x64, Eclipse Indigo, jdk 1.6, jre-j9 and JUnit 3 (I could use v.4)

我使用的是 Windows 7 x64、Eclipse Indigo、jdk 1.6、jre-j9 和 JUnit 3(我可以使用 v.4)

回答by Matthew Farwell

You can use JVisualVM (%JAVA_HOME%/bin/jvisualvm.exe), but to use it with JUnit, you need to change the run configuration slightly.

您可以使用 JVisualVM ( %JAVA_HOME%/bin/jvisualvm.exe),但要将其与 JUnit 一起使用,您需要稍微更改运行配置。

  1. Run the JUnit tests once, to create the run configuration
  2. Edit the Run Configuration (Run->Run Configurations...)
  3. In the Testtab check the box 'Keep JUnit running after test when debugging'
  4. Rerun the test (with Debug). This will run the tests, but importantly, leave the JVM around, so that you can attach to it using JVisualVM.
  1. 运行一次 JUnit 测试,以创建运行配置
  2. 编辑运行配置 ( Run->Run Configurations...)
  3. Test选项卡中选中“调试时在测试后保持 JUnit 运行”框
  4. 重新运行测试(使用 Debug)。这将运行测试,但重要的是,将 JVM 留在周围,以便您可以使用 JVisualVM 附加到它。

If you wish to profile a specific section of the test, then setting a breakpoint before and after will enable you to start / stop profiling.

如果您希望分析测试的特定部分,则在前后设置断点将使您能够开始/停止分析。

回答by Ingo Kegel

JProfilerhas an eclipse plugin which supports JUnit run configurations. See herefor a screen cast on the eclipse IDE integration.

JProfiler有一个支持 JUnit 运行配置的 eclipse 插件。有关Eclipse IDE 集成的屏幕投射,请参见此处

To keep the JVM alive after the test finishes (so that you can analyzed the results), edit the profiling settings and select "Keep VM alive" on the "Miscellaneous" tab.

要在测试完成后保持 JVM 处于活动状态(以便您可以分析结果),请编辑分析设置并在“其他”选项卡上选择“保持 VM 处于活动状态”。

Disclaimer: My company develops JProfiler.

免责声明:我公司开发 JProfiler。

回答by Joe23

A neat option to profile application startup or short running processes (like tests) with VisualVM is the Startup Profiler Plugin.

使用 VisualVM 分析应用程序启动或短期运行进程(如测试)的一个巧妙选项是启动分析器插件

The command line argument provided by the plugin has to be copied to the launch configuration under VM arguments.

插件提供的命令行参数必须复制到 VM 参数下的启动配置。