javajfr

How to select a JFR timeframe


If I have a JFR recording, is there any tool that allows me to extract only a specific time frame from it as a separate file? Or better yet, is there a VM-style visualizer allowing me to inspect custom time frames?


Solution

  • There is the jfr disassemble [--max-size size] file command that can split a file into smaller ones. It can't extract a time frame, but you can easily write one with JDK 19, or later:

    import jdk.jfr.consumer.RecordingFile;
    
    ...
    
    public static void main(String... args) throws IOException {
      Instant start = Instant.parse(args[0]);
      Instant end = Instant.parse(args[1]);
      Path input = Path.of(args[2]);
      Path output = Path.of(args[3]);
      try (var r = new RecordingFile(input)) {
        r.write(output, e -> e.getStartTime().isAfter(start) &&
                             e.getEndTime().isBefore(end));
      }
    }