[英]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.