我想在许多不同的输入(~1000)上分析一些代码段,所以手动运行每个测试并保存结果是没有意义的。我正在结合Eclipse使用您的工具包来进行配置。有没有办法创建用于分析的“新会话”?我希望能够将每一次运行分开,这样才最有意义。
发布于 2014-03-28 08:03:19
您不需要为每个测试创建“会话”。相反,您必须在每个测试结束时捕获分析数据的快照,并在运行下一个测试之前清除分析数据。
使用yourkit API,您可以以类似于以下方式这样做:
public void profile(String host, int port, List<InputData> inputDataSet) {
Map<InputData, String> pathMap = new HashMap<InputData, String>(); //If you want to save the location of each file
//Init profiling data collection
com.yourkit.api.Controller controller = new Controller(host, port);
controller.startCPUSampling(/*with your settings*/);
controller.startAllocationRecording(/*With your settings*/);
//controller.startXXX with whatever data you want to collect
for (InputData input: inputDataSet) {
//Run your test
runTest(inputData);
//Save profiling data
String path = controller.captureSnapshot(/*With or without memory dump*/);
pathMap.put(input, path);
//Clear yourkit profiling data
controller.clearAllocationData();
controller.clearCPUData();
//controller.clearXXX with whatever data you are collecting
}
}我不认为您需要停止收集,捕获快照,清除数据,重新开始收集,您可以只是捕获和清除数据,但请再次检查。一旦测试运行,您就可以在您的工具包中打开快照并分析分析数据。
发布于 2014-03-27 10:52:17
总之,还不清楚如何运行您的测试。每个测试是在自己的JVM进程中运行,还是在单个JVM中循环运行所有测试?
如果您在自己的JVM中运行每个测试,那么您需要使用分析器代理运行JVM,即使用-agentpath选项(详细信息在这里http://www.yourkit.com/docs/java/help/agent.jsp )。2)指定在JVM启动时所分析的内容(代理选项“取样”、“跟踪”等) 3)捕获JVM出口上的快照文件("onexit“代理选项)。
选项的完整列表options.jsp
如果在单个JVM中运行所有测试,则可以在测试启动之前使用profiler http://www.yourkit.com/docs/java/help/api.jsp启动profiler,并在测试完成后捕获快照。您需要使用com.yourkit.api.Controller类。
https://stackoverflow.com/questions/22645140
复制相似问题