質問

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. I'm using yourkit in combination with Eclipse to profile. 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:

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?

If you run each test in own JVM then you need 1) Run JVM with profiler agent, i.e. use -agentpath option (the details is here 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).

Full list of options 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. You need to use com.yourkit.api.Controller class.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top