【问题标题】:How to connect a JProfiler session with the designed ID?如何将 JProfiler 会话与设计的 ID 连接起来?
【发布时间】:2014-05-12 09:22:13
【问题描述】:

我已经使用 args 启动了一个 Java 应用程序:

"-agentpath:C:\Program Files\jprofiler7\bin\windows-x64\jprofilerti.dll=port=8849,id=134,nowait"

然后控制台显示:

JProfiler> Protocol version 37
JProfiler> Using JVMTI
JProfiler> JVMTI version 1.1 detected.
JProfiler> 64-bit library
JProfiler> Don't wait for frontend to connect.
JProfiler> Using config file C:\Users\user\.jprofiler7\config.xml (id: 134)
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> Using dynamic instrumentation
JProfiler> Time measurement: elapsed time
JProfiler> CPU profiling enabled
JProfiler> Hotspot compiler enabled

然后我现在可以通过 JProfiler GUI 进行连接。

但我需要通过另一个带有 JProfiler API 的 Java 应用程序来连接它我怎么能把它连接起来?通过任何 VM 参数?

我只知道也许我必须先创建一个连接,但我不知道如何选择会话 ID。

Connection connection = ConnectionFactory.createRemoteConnection("localhost", 8849, 30);

如果我运行代理应用程序然后首先通过 JProfiler GUI 连接,我可以通过我的 Java 应用程序获取 cpu 信息,包括然后运行我的 JProfiler API 应用程序。

Profiling data :
Hot spots:
Top 5 hot spots:
Hot spot 1: ProfilerTest.main(java.lang.String[ ]): 34 ms (100 %)
Backtraces: 
ProfilerTest.main(java.lang.String[ ]): 34722 (0)
   ***: 34722 (0)
Cpu tree:
***: 34722 (0)
   ProfilerTest.main(java.lang.String[ ]): 34722 (0)
      java.util.Scanner.next(): 34722 (0)

但如果我先运行代理应用程序然后通过我的 JProfiler API 应用程序连接,我将一无所获。

Profiling data :
Hot spots:
Top 5 hot spots:
Cpu tree:
***: 0 (0)

【问题讨论】:

    标签: jprofiler


    【解决方案1】:

    在 ",nowait" 之后,添加 ",config=[path to config file],id=nnn" 其中 "[path to config file]" 是 %USERPROFILE%.jprofiler8\config.xml 而 "nnn" 是在会话设置对话框的应用程序设置选项卡的右上角可见的会话 ID。

    【讨论】:

    • 感谢您的回答。我可以在 JProfiler 中看到会话。但是我想通过我的 Java 应用程序通过 JProfiler API 连接一个会话。如何通过设计的会话 ID 连接?或者如果我可以在没有会话ID的情况下显示设计程序的信息,例如CPU和内存,也更好。
    • 会话 ID 仅用于分析设置。使用 API,您只需连接到已分析的应用程序,无法在 JProfiler 中启动会话。
    • 哦!我有一个问题?我使用参数 "-agentpath:C:\Program Files\jprofiler7\bin\windows-x64\jprofilerti.dll=port=8849,id=134,nowait" 运行 Java 应用程序,但我可以通过 JProfiler 使用“151”会话 ID ?那么 JProfiler 如何知道哪个应用程序是正确的呢?我是否有机会通过 JProfiler API 连接设计的应用程序?
    • 一开始我以为我只需要像8849这样设计的端口创建一个连接,然后分析程序会自动找到应用程序。但实际上,如果没有设计的会话ID,只是从agentpath开始,通过JProfiler GUI连接后,我可以通过JProfiler API得到正确的结果,但如果我直接通过JProfiler API连接,则得到无结果。如果我首先设计了一个会话 ID,JProfiler GUI 也可以工作,但 JProfiler API 只是得到一个无结果。我只想找到一种方法,通过我的代码直接通过 JProfiler API 分析任何 Java 应用程序。
    • 会话确定分析设置。如果您从 GUI 连接到不同的会话,则可能需要重新检测某些类。这只是效率和较低开销的问题。只有在-agentpath参数中添加“,offline”参数才能使用平台API。
    猜你喜欢
    • 2018-02-01
    • 2014-03-19
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-02
    • 2018-04-06
    相关资源
    最近更新 更多