[英]Why does JProfiler not show my classes/methods in maven tests profiling?
我的Maven版本中运行的测试非常长。 这些测试是使用故障安全插件 ( mvn verify
)运行的集成测试。
我尝试使用JProfiler剖析这些测试。
这些测试可以正常运行,但是我在JProfiler中看不到任何有用的东西,就好像JProfiler正在将它们过滤掉一样。
我在openSUSE 13.1 x64上 ,使用Maven 3.2.1和JProfiler 8.0.5
JProfiler会话设置是具有两个修改的默认设置:
我使用以下命令启动配置文件生成:
MAVEN_OPTS="-agentpath:/opt/jprofiler8/bin/linux-x64/libjprofilerti.so=port=8849" mvn verify
Maven和JProfiler在同一台计算机上运行(本地配置文件)。
构建正常开始:
$ MAVEN_OPTS="-agentpath:/opt/jprofiler8/bin/linux-x64/libjprofilerti.so=port=8849" mvn verify
JProfiler> Protocol version 39
JProfiler> Using JVMTI
JProfiler> JVMTI version 1.1 detected.
JProfiler> 64-bit library
JProfiler> Listening on port: 8849.
JProfiler> Instrumenting native methods.
JProfiler> Can retransform classes.
JProfiler> Can retransform any class.
JProfiler> Native library initialized
JProfiler> VM initialized
JProfiler> Waiting for a connection from the JProfiler GUI ...
JProfiler> Using dynamic instrumentation
JProfiler> Time measurement: elapsed time
JProfiler> CPU profiling enabled
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building...
[...]
并且也正常结束:
[...]
Results :
Tests run: 2766, Failures: 0, Errors: 0, Skipped: 0
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19:31 min
[INFO] Finished at: 2014-06-18T11:38:49+01:00
[INFO] Final Memory: 21M/107M
[INFO] ------------------------------------------------------------------------
JProfiler> Keeping VM alive until frontend disconnects.
JProfiler热点CPU视图向我展示了这一点:
对我来说,这是没有用的东西,只有与Maven相关的方法(压缩,类加载)。
当我尝试通过(打开热点回溯)时,没有发现与运行的测试有关的任何内容。
而且,和测定方法经过时间(如果我添加的前10热点固有时间)在很大程度上是微不足道( ~10s
相比,实际的总时间() ~19 mins 30s
)。
编辑:
最初,我使用IDE(IntelliJ IDEA)和JProfiler插件运行测试配置文件,但是由于异常行为,我停止了测试。 似乎测试无休止地在不断运行。 我认为这是来自IDE(或插件)的,因为通过maven可以正常运行测试。
编辑2:
感谢@IngoKegel的建议,如果我选择“所有状态”,我将获得更多信息:
我再看到4个热点。 但是,他们仍然没有给我有用的信息:
经过的时间要好得多,但是我仍然看不到“我的”课程有任何东西。
为什么我的班级仍然被过滤? 有没有办法看他们?
另外,我不完全理解为什么在选择“可运行”状态时这些热点没有显示。 而且这是默认选项...
出人意料的是,如果我将这前4个经过的时间加在一起,它会给我带来~1h
时间,但执行时间却是19 ~19min 20s
秒,好像有些热点重叠了一样。 我认为这是“所有状态”选项的副作用。
诀窍是Maven 故障安全插件在单独的JVM中运行集成测试:
具有单元测试和集成测试的典型Maven构建可以轻松使用3个不同的JVM:
mvn
命令启动
对Maven主JVM进行性能分析将永远不会显示有关故障安全JVM内部已完成工作的信息。 而且,MAVEN_OPTS中指定的选项仅传递给Maven主JVM。
要分析其他JVM之一,您必须使用pom.xml
文件中的插件配置单独配置它。
要回答这个问题,它需要以下插件配置:
<plugins>
[...]
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
<!-- to exclude IT from main build, comment the 'verify' goal -->
</goals>
</execution>
</executions>
<configuration>
<argLine>${failsafeArgLine}</argLine>
</configuration>
</plugin>
[...]
</plugin>
这里的重要部分是<argLine>${failsafeArgLine}</argLine>
然后,可以通过failsafeArgLine
参数指定JProfiler代理选项:
mvn verify -DfailsafeArgLine="-agentpath:/opt/jprofiler8/bin/linux-x64/libjprofilerti.so=port=8849"
运行此命令将正常启动Maven构建(不进行概要分析),然后在集成测试阶段开始时,它要求建立JProfiler连接:
[...]
[INFO]
[INFO] --- maven-failsafe-plugin:2.17:integration-test (default) @ project ---
[INFO] Failsafe report directory: /home/user/Repositories/project/target/failsafe-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
JProfiler> Protocol version 39
JProfiler> Using JVMTI
JProfiler> JVMTI version 1.1 detected.
JProfiler> 64-bit library
JProfiler> Listening on port: 8849.
JProfiler> Instrumenting native methods.
JProfiler> Can retransform classes.
JProfiler> Can retransform any class.
JProfiler> Native library initialized
JProfiler> VM initialized
JProfiler> Waiting for a connection from the JProfiler GUI ...
JProfiler> Using dynamic instrumentation
JProfiler> Time measurement: elapsed time
JProfiler> CPU profiling enabled
[...]
故障安全VM参数也可以直接在pom.xml文件中指定(而不是使用failsafeArgLine
属性),但是我更喜欢这样使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.