Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8335529

JDK JFR 2nd RecordingStream object does not record

XMLWordPrintable

    • jfr
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      JDK: Oracle OpenJDK 21.0.3
      OS: Mac OS M1

      A DESCRIPTION OF THE PROBLEM :
      In the same JVM session, RecordingStream records only for the first time. If we create a new RecordingStream object and try starting the recording, it does not work and also there is no error thrown.

      If we use clients like JMC, jcmd etc. We can start and stop multiple Recordings for the same JVM session. However, we cannot do the same using programmatically using the jdk.jfr APIs. IF we try doing that neither is any result printed nor is any error thrown.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a new jdk jfr RecordingStream object and start it for the first time.
      2. Recording happens, events are consumed and acted open as defiend by the handler.
      3. Stop and close the RecordingStream as and when required.

      4. Create another RecordingStreming object and start recording.
      5. Recording DOES NOT happen and neither there is any error reported.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      If we use clients like JMC, jcmd etc. We can start and stop multiple Recordings for the same JVM session. However, we cannot do the same using programmatically using the jdk.jfr APIs. IF we try doing that neither is any result printed nor is any error thrown.
      ACTUAL -
      Starting a recording on the 2nd RecordingStream object does not record and does not throw any error.

      ---------- BEGIN SOURCE ----------
      import jdk.jfr.EventSettings;
      import jdk.jfr.EventType;
      import jdk.jfr.consumer.RecordedEvent;
      import jdk.jfr.consumer.RecordedFrame;
      import jdk.jfr.consumer.RecordedStackTrace;
      import jdk.jfr.consumer.RecordingStream;

      import java.time.Duration;
      import java.util.Date;
      import java.util.List;

      public class Main {
          public static void main(String[] args) throws Exception {
              System.out.println("Hello world!");

              jfrRecord();
              System.out.println("Waiting for 30s, before starting new recording........");
              Thread.sleep(30*1000);
              jfrRecord();
          }

          static void jfrRecord() throws Exception {
              RecordingStream rs = new RecordingStream();
              try {

                  EventSettings es = rs.enable("jdk.CPULoad");
                  es.withPeriod(Duration.ofSeconds(2));
                  rs.onEvent("jdk.CPULoad", Main::actOnCPULoad);

                  System.out.println("Starting recording stream in async thread, sleeping main for 1min---------------------------------");
                  rs.startAsync();
                  Thread.sleep(60*1000);
                  System.out.println("Closing the Recording Stream---------------------------------");
                  rs.stop();
                  rs.close();
              }
              catch (Exception e){
                  System.out.println("error occurred: "+e);
              }
          }

          static void actOnCPULoad(RecordedEvent recordedEvent) {
              System.out.println(String.format("Overall CPU %%, StartTime:\t%s,\tUser:\t%.4f,\tSystem:\t%.4f,\tMachineTotal:\t%.4f",
                      Date.from(recordedEvent.getStartTime()),
                      recordedEvent.getDouble("jvmUser")*100,
                      recordedEvent.getDouble("jvmSystem")*100,
                      recordedEvent.getDouble("machineTotal")*100));
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: