简体   繁体   English

分离Yourkit会话

[英]Separating Yourkit sessions

I have some segment of code I want to profile on many different inputs (~1000) so it doesn't make sense to manually run each test and save the results. 我有一段代码想在许多不同的输入(〜1000)上进行分析,因此手动运行每个测试并保存结果没有任何意义。 I'm using yourkit in combination with Eclipse to profile. 我将yourkit与Eclipse结合使用来进行概要分析。 Is there any way to create "new sessions" for profiling? 有什么方法可以创建用于分析的“新会话”吗? I want to be able to separate each run so that would make the most sense. 我希望能够将每次运行分开,这样才最有意义。

You don't really need to create "sessions" for each test. 您实际上并不需要为每个测试创建“会话”。 Instead, you have to capture a snapshot of the profiling data at the end of each test, and clear the profiling data before running the next test. 相反,您必须在每个测试结束时捕获性能分析数据的快照,并在运行下一个测试之前清除性能分析数据。

Using the yourkit API , you can do so in a manner similar to: 使用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
  }
}

I don't think you need to stop collecting, capture snapshot, clear data, restart collecting, you can just capture and clear data, but please double-check. 我认为您不需要停止收集,捕获快照,清除数据,重新开始收集,您只需捕获并清除数据,但请仔细检查。 Once the tests are run, you can open the snapshots in yourkit and analyze the profiling data. 运行测试后,您可以在工具箱中打开快照并分析配置文件数据。

Unfotunately it's not clear how to run your tests. 不幸的是,目前尚不清楚如何运行测试。 Does each test run in own JVM process or you run all tests in loop inside single JVM? 是每个测试都在自己的JVM进程中运行,还是在单个JVM中循环运行所有测试?

If you run each test in own JVM then you need 1) Run JVM with profiler agent, ie use -agentpath option (the details is here http://www.yourkit.com/docs/java/help/agent.jsp ). 如果您在自己的JVM中运行每个测试,则需要1)使用Profiler Agent运行JVM,即使用-agentpath选项(详细信息在此处http://www.yourkit.com/docs/java/help/agent.jsp )。 2) Specify what you are profiling on JVM startup (agent option "sampling", "tracing", etc) 3) Capture snapshot file on JVM exit ("onexit" agent option). 2)指定在JVM启动时要进行概要分析的内容(代理选项“采样”,“跟踪”等)3)在JVM出口捕获快照文件(“ onexit”代理选项)。

Full list of options http://www.yourkit.com/docs/java/help/startup_options.jsp 选项的完整列表http://www.yourkit.com/docs/java/help/startup_options.jsp

If you run all tests inside single JVM you can use profiler API http://www.yourkit.com/docs/java/help/api.jsp to start profling before test starts and capture snapshot after test finishes. 如果您在单个JVM中运行所有测试,则可以使用探查器API http://www.yourkit.com/docs/java/help/api.jsp在测试开始之前启动配置文件,并在测试完成之后捕获快照。 You need to use com.yourkit.api.Controller class. 您需要使用com.yourkit.api.Controller类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM