How do I automate jprofiler to save snapshots of multiple target java programs with different arguments

huangapple go评论73阅读模式
英文:

How do I automate jprofiler to save snapshots of multiple target java programs with different arguments

问题

我想要分析我的Java程序,其中我正在打开一个文件并对其执行读写操作。要读取的文件是一个大型XML文件,我想要比较使用批处理/流阅读/标准XML解析等技术解析文件时的内存统计/快照。

假设我们有三个程序,我想保存快照:

BatchParsing.java

public class BatchParsing {

  public static void main(String[] args) throws Exception {
      File file = new File("path/to/file");
      // 使用批处理逻辑解析XML
  }
}

StreamReading.java

public class StreamReadingParsing {

  public static void main(String[] args) throws Exception {
      File file = new File("path/to/file");
      // 使用流阅读器解析XML
  }
}

NormalParsing.java

public class NormalParsing {

  public static void main(String[] args) throws Exception {
      File file = new File("path/to/file");
      // 通过加载整个文件解析XML
  }
}

此外,我想要分析不只一个,而是多个不同大小的文件,并且不想在不同文件上运行循环,而是要为每个文件单独运行上述提到的每个程序,以检查分析结果。

最后,我想要按照以下方式保存我的分析快照:

  • 快照结果
    • 批处理结果
      • small_file.jps
      • average_file.jps
      • large_file.jps
    • 流结果
      • small_file.jps
      • average_file.jps
      • large_file.jps
    • 普通解析结果
      • small_file.jps
      • average_file.jps
      • large_file.jps

我可以使用GUI来执行上述操作,但希望自动化所有这些。我目前在macOS上使用IntelliJ上的jprofiler。

英文:

I wanted to profile my java program where I was opening a file and performing read and write operations over it . The file to be read is a large XML file, and i wanted to compare memory stats/snapshots for parsing the file using techniques like batching / stream-reading / standard xml parsing etc.

So let's say we had three programs that I wanted to save the snapshots for :

BatchParsing.java

public class BatchParsing {

  public static void main(String[] args) throws Exception {
      File = new File("path/to/file")
      // parse XML using batch logic
  }
}

StreamReading.java

public class StreamReadingParsing {

  public static void main(String[] args) throws Exception {
      File = new File("path/to/file")
      // parse XML using stream reader
  }
}

NormalParsing.java

public class NormalParsing {

  public static void main(String[] args) throws Exception {
      File = new File("path/to/file")
      // parse XML by loading whole file
  }
}

Moreover , I wanted to analyse not one , but multiple files of different sizes, and instead of running a loop over different files, I wanted to check profiling results by running each of the above mentioned programs separately for each file.

In then end , I wanted to save my profiling snapshots as follows.

- snapshot_results
   - batch_results
      - small_file.jps
      - average_file.jps
      - large_file.jps
   - stream_results
      - small_file.jps
      - average_file.jps
      - large_file.jps
   - normal_parsing_results
      - small_file.jps
      - average_file.jps
      - large_file.jps

I could do the above using the GUI, but wanted to automate all of this . I am currently using jprofiler over intelliJ on macOS .

答案1

得分: 1

要在没有 JProfiler GUI 的情况下进行性能分析,您可以使用离线分析。在 JProfiler 主菜单中选择“Session->Integration Wizards->New Remote Integration”,然后在“Startup mode”步骤中选择“Profile offline”选项。然后,您将获得在离线模式下加载分析代理所需的虚拟机参数。

要记录数据并保存快照,您可以使用触发器或分析 API。在您的情况下,使用分析 API会更方便。

要记录 CPU 数据并保存整个应用程序运行的快照,请像这样包装您的代码:

Controller.startCPURecording(true);
// 在此处插入您的代码
Controller.stopCPURecording();
Controller.saveSnapshot(new File("<快照名称>.jps"));
英文:

To profile without the JProfiler GUI, you use offline profiling. Invoke

Session->Integration Wizards->New Remote Integration

in the JProfiler main menu and choose the "Profile offline" option on the "Startup mode" step. You will then get the VM parameter that is required to load the profiling agent in offline mode.

To record data and save snapshots, you can use triggers or the profiling API. In your case, the profiling API will be more convenient.

To record CPU date and save a snapshot of the entire application run, wrap your code like this:

Controller.startCPURecording(true);
// Your code here
Controller.stopCPURecording();
Controller.saveSnapshot(new File(&quot;&lt;snapshot name&gt;.jps&quot;));

huangapple
  • 本文由 发表于 2020年10月13日 10:19:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/64327560.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定