簡體   English   中英

為什么JProfiler在Maven測試配置文件中不顯示我的類/方法?

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

JProfiler會話設置是具有兩個修改的默認設置:

  • 啟動時自動啟動CPU分析
  • 執行完成后保持VM處於活動狀態(以啟用回溯信息)

我使用以下命令啟動配置文件生成:

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個熱點。 但是,他們仍然沒有給我有用的信息:

  1. 是對jucThreadPoolExecutor $ Worker.run的“過濾/直接調用”
  2. 是從Maven(叢)到jlrMethod.invoke的單個調用(+無關緊要的調用)
  3. 和4.被“過濾/直接調用”到oamaven.p.surefire.booterclient.o.ThreadStreamConsumer $ Pumper.run

經過的時間要好得多,但是我仍然看不到“我的”課程有任何東西。

為什么我的班級仍然被過濾? 有沒有辦法看他們?

另外,我不完全理解為什么在選擇“可運行”狀態時這些熱點沒有顯示。 而且這是默認選項...

出人意料的是,如果我將這前4個經過的時間加在一起,它會給我帶來~1h時間,但執行時間卻是19 ~19min 20s秒,好像有些熱點重疊了一樣。 我認為這是“所有狀態”選項的副作用。

訣竅是Maven 故障安全插件單獨的JVM中運行集成測試:

具有單元測試和集成測試的典型Maven構建可以輕松使用3個不同的JVM:

  • Maven主JVM( compilepackage ),由mvn命令啟動
    • 由Maven主JVM啟動的Surefire JVM( 單元測試
    • 由Maven主JVM啟動的故障安全JVM( 集成測試

對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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM