gpt4 book ai didi

java - 分离 Yourkit session

转载 作者:行者123 更新时间:2023-12-01 13:13:33 31 4
gpt4 key购买 nike

我有一些代码段想要在许多不同的输入(~1000)上进行分析,因此手动运行每个测试并保存结果是没有意义的。我将 yourkit 与 Eclipse 结合使用来进行分析。有没有办法创建“新 session ”进行分析?我希望能够将每次运行分开,这样才最有意义。

最佳答案

您实际上不需要为每个测试创建“ session ”。相反,您必须在每次测试结束时捕获分析数据的快照,并在运行下一个测试之前清除分析数据。

使用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
}
}

我认为您不需要停止采集、捕获快照、清除数据、重新开始采集,您可以只捕获并清除数据,但请仔细检查。运行测试后,您可以打开套件中的快照并分析分析数据。

关于java - 分离 Yourkit session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22645140/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com