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

JFR: Remember result of shouldCommit().

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • None
    • hotspot
    • None
    • jfr

      Users can create their own settings, for example, a setting for probabilistic sampling, by annotating a boolean-returning method in their event with @SettingDefinition.

          public class FooEvent extends Event {
              String domain;
              @SettingDefinition
              public boolean sample(ProbalisticSetting ps) {
                  return ps,shouldSample();
              }
          }

      The method is executed when the commit() method is invoked, and if it returns true, and the duration exceeds the threshold and other user-defined settings also return true, the event is written to a thread-local JFR buffer.

      The problem arises when shouldCommit() is used to avoid an expensive operation, for example:

          FooEvent foo = new FooEvent();
          foo.begin();
          ...
          foo.end();
          if (foo.shouldCommit()) {
              int index = email.indexOf("@");
              foo.domain = index == -1 ? null : email.substring(index + 1);
              foo.commit();
          }

      When commit() is called, the shouldCommit() method is called internally, but it may not return the same result as the first time, which means probabilistic sampling will not work as expected.

      One way to avoid this issue is to store the result of shouldCommit() so it can be reused by commit().

            Unassigned Unassigned
            egahlin Erik Gahlin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: