我已经用 Java 构建了一个命令行工具,现在我想用 YourKit 对其进行分析。我使用以下命令启动命令行工具:
$ java -classpath .:foo.bar.jar com.foobar.tools.TheTool arg1 arg2 arg3
它在不到 2 秒的时间内完成。
阅读http://www.yourkit.com/docs/80/help/agent.jsp后,我尝试了以下操作:
$ java -agentpath:/home/dspitzer/yjp-8.0.24/bin/linux-x86-32/libyjpagent.so -classpath .:foo.bar.jar com.foobar.tools.TheTool arg1 arg2 arg3
...我得到:
[YourKit Java Profiler 8.0.24] JVMTI version 3001016d; 14.3-b01; Sun Microsystems Inc.; mixed mode, sharing; Linux; 32-bit JVM
[YourKit Java Profiler 8.0.24] Profiler agent is listening on port 10001...
[YourKit Java Profiler 8.0.24] *** HINT ***: To get profiling results, connect to the application from the profiler UI
...
(然后该工具运行完成并退出。)
我猜(至少默认情况下)YourKit 旨在仅连接到正在运行的应用程序。
我应该如何修改我的命令行工具以允许来自 YourKit 的连接?
- 我可以添加一个命令行选项,让它暂停输入,在我从 YourKit 连接到它之前,我不会按回车键继续它。
- 是否有一个 YourKit API 可以添加到我的工具中,这会导致它在我与 YourKit 连接之前阻塞?
- 是否有 YourKit API 或 java 命令行选项可以创建一个我可以稍后(在命令行工具完成后)使用 YourKit 加载和分析的分析“快照”?