You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "iprithv (via GitHub)" <gi...@apache.org> on 2026/04/24 21:58:54 UTC

[PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

iprithv opened a new pull request, #15983:
URL: https://github.com/apache/lucene/pull/15983

   ### Description
   
   Java 25 added CPU-time profiling (JEP 509) which emits jdk.CPUTimeSample
   events. ProfileResults did not recognize this event type, causing empty
   profiling reports when the CPU-time profiler is active.
   
   Resolves #15926 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3155008680


##########
lucene/CHANGES.txt:
##########
@@ -185,6 +185,11 @@ Changes in Runtime Behavior
 
 Build
 ---------------------
+* GITHUB#15926: Support jdk.CPUTimeSample event (Java 25+, JEP 509) in ProfileResults.

Review Comment:
   sure, done. thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3150259017


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -101,10 +101,16 @@ public static void main(String[] args) throws IOException {
   }
 
   /** true if we care about this event */
-  static boolean isInteresting(String mode, RecordedEvent event) {
+  static boolean isInteresting(String mode, RecordedEvent event, boolean hasCPUTimeSamples) {
     String name = event.getEventType().getName();
     switch (mode) {
       case "cpu":
+        if (hasCPUTimeSamples) {
+          // Prefer jdk.CPUTimeSample (Java 25+, JEP 509): samples by CPU time, not wall-clock
+          // time, so idle threads (like gradle epoll) are inherently excluded — no filtering
+          // needed. When available, we skip legacy execution samples to avoid double-counting.
+          return name.equals("jdk.CPUTimeSample");
+        }
         return (name.equals("jdk.ExecutionSample") || name.equals("jdk.NativeMethodSample"))

Review Comment:
   Yes, I expanded the comment to say that explicitly so it matches the code. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3152047529


##########
gradle/testing/profiling.jfc:
##########
@@ -16,7 +16,9 @@
     limitations under the License.
 -->
 <!--
-Collects only execution and method samples at a low interval
+  Wall-clock execution samples for CPU profiling on platforms where JEP 509 CPU-time sampling
+  is unavailable (non-Linux). On Linux, CodeProfilingPlugin uses profiling.linux.jfc instead.

Review Comment:
   my bad, missed it in adding in previous commit. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3152092827


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -101,10 +101,17 @@ public static void main(String[] args) throws IOException {
   }
 
   /** true if we care about this event */
-  static boolean isInteresting(String mode, RecordedEvent event) {
+  static boolean isInteresting(String mode, RecordedEvent event, boolean hasCPUTimeSamples) {
     String name = event.getEventType().getName();
     switch (mode) {
       case "cpu":
+        if (hasCPUTimeSamples) {

Review Comment:
   sure, updated. thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3152091189


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -121,6 +128,37 @@ static boolean isGradlePollThread(RecordedThread thread) {
     return (thread != null && thread.getJavaName().startsWith("/127.0.0.1"));
   }
 
+  /**
+   * Pre-scan recording files for CPU sampling strategy. Returns whether any {@code
+   * jdk.CPUTimeSample} events appear in the inputs. Throws if recordings mix those with legacy
+   * wall-clock samples ({@code jdk.ExecutionSample} / {@code jdk.NativeMethodSample}); only one
+   * CPU sampler should be enabled in JFR settings.
+   */
+  static boolean resolveCpuTimeSampling(List<String> files) throws IOException {

Review Comment:
   sure, done. thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand merged PR #15983:
URL: https://github.com/apache/lucene/pull/15983


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3147024813


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -101,10 +101,16 @@ public static void main(String[] args) throws IOException {
   }
 
   /** true if we care about this event */
-  static boolean isInteresting(String mode, RecordedEvent event) {
+  static boolean isInteresting(String mode, RecordedEvent event, boolean hasCPUTimeSamples) {
     String name = event.getEventType().getName();
     switch (mode) {
       case "cpu":
+        if (hasCPUTimeSamples) {
+          // Prefer jdk.CPUTimeSample (Java 25+, JEP 509): samples by CPU time, not wall-clock
+          // time, so idle threads (like gradle epoll) are inherently excluded — no filtering
+          // needed. When available, we skip legacy execution samples to avoid double-counting.
+          return name.equals("jdk.CPUTimeSample");
+        }
         return (name.equals("jdk.ExecutionSample") || name.equals("jdk.NativeMethodSample"))

Review Comment:
   I think `NativeMethodSample` is also a dup, if CPUTime and wall-clock sampling are both enabled?



##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -173,6 +199,11 @@ public static void printReport(
     if (count < 1) {
       throw new IllegalArgumentException("tests.profile.count must be positive");
     }
+
+    // Pre-scan to detect if CPU-time samples (Java 25+, JEP 509) are available.
+    // If so, prefer them over legacy execution samples to avoid double-counting.
+    boolean hasCPUTimeSamples = "cpu".equals(mode) && detectCPUTimeSamples(files);

Review Comment:
   Could we make this stricter?  Throw an exception if we see a mix of `CPUTime` and legacy events?  Lucene (and in general anyone profiling, hmm except maybe profiler debuggers heh) should only have one sampler enabled at a time?



##########
gradle/testing/profiling.jfc:
##########
@@ -29,6 +29,11 @@ Collects only execution and method samples at a low interval
     <setting name="period">1 ms</setting>
   </event>
 
+  <event name="jdk.CPUTimeSample">

Review Comment:
   Could we turn off the old (wall-clock) sampling (`jdk.ExecutionSample`, `jdk.NativeMethodSample`) and just fully commit to `CPUTime`.  In nightly benchmarks we've found the 1 msec sampling to add non-trivial overhead (I think ~5-7% slower).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3154994732


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/CodeProfilingPlugin.java:
##########
@@ -254,4 +255,14 @@ private record ProfilingOptions(
       Provider<Integer> countOption,
       Provider<Boolean> lineNumbersOption,
       Provider<Boolean> frametypesOption) {}
+
+  /**
+   * JEP 509 CPU-time sampling ({@code jdk.CPUTimeSample}) is implemented on Linux. Use a Linux-only
+   * JFR template with CPU-time sampling only; other hosts keep wall-clock execution sampling for
+   * short tests.
+   */
+  private static String profilingSettingsPath() {
+    String os = System.getProperty("os.name", "").toLowerCase(Locale.ROOT);
+    return os.contains("linux") ? "testing/profiling.linux.jfc" : "testing/profiling.jfc";

Review Comment:
   Sure, makes sense. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3152084211


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -173,6 +199,11 @@ public static void printReport(
     if (count < 1) {
       throw new IllegalArgumentException("tests.profile.count must be positive");
     }
+
+    // Pre-scan to detect if CPU-time samples (Java 25+, JEP 509) are available.
+    // If so, prefer them over legacy execution samples to avoid double-counting.
+    boolean hasCPUTimeSamples = "cpu".equals(mode) && detectCPUTimeSamples(files);

Review Comment:
   I initially added the strict mixed-sampler check here, but removed it after @rmuir follow up review since the two Lucene JFC files are now mutually exclusive.
   
   So the exclusivity now lives in the selected JFC config instead of a pre-scan in `ProfileResults`. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "rmuir (via GitHub)" <gi...@apache.org>.
rmuir commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3149933180


##########
gradle/testing/profiling.jfc:
##########
@@ -29,6 +29,11 @@ Collects only execution and method samples at a low interval
     <setting name="period">1 ms</setting>
   </event>
 
+  <event name="jdk.CPUTimeSample">

Review Comment:
   The 1msec sampling was necessary for tests in order to find places wasting CPU. most tests just don't run that long.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3150294285


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -121,6 +127,24 @@ static boolean isGradlePollThread(RecordedThread thread) {
     return (thread != null && thread.getJavaName().startsWith("/127.0.0.1"));
   }
 
+  /**
+   * Pre-scan recording files to detect if any jdk.CPUTimeSample events are present. When they are,
+   * we prefer them over legacy jdk.ExecutionSample/jdk.NativeMethodSample to avoid double-counting.
+   */
+  static boolean detectCPUTimeSamples(List<String> files) throws IOException {

Review Comment:
   Yes, done. Linux uses gradle/testing/profiling.linux.jfc, everyone else gradle/testing/profiling.jfc, selected in CodeProfilingPlugin from the host OS. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3154984714


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/CodeProfilingPlugin.java:
##########
@@ -254,4 +255,14 @@ private record ProfilingOptions(
       Provider<Integer> countOption,
       Provider<Boolean> lineNumbersOption,
       Provider<Boolean> frametypesOption) {}
+
+  /**
+   * JEP 509 CPU-time sampling ({@code jdk.CPUTimeSample}) is implemented on Linux. Use a Linux-only
+   * JFR template with CPU-time sampling only; other hosts keep wall-clock execution sampling for
+   * short tests.

Review Comment:
   Sure, done. Updated. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on PR #15983:
URL: https://github.com/apache/lucene/pull/15983#issuecomment-4346167219

   @mikemccand `getDidWork()` was the wrong check here. It can be false for skipped/up-to-date/not-selected test tasks even when nothing failed. I changed this to check `task.getState().getFailure() == null` instead [here](https://github.com/apache/lucene/pull/15997)
   
   On the count mismatch, I think `ProfileResults` is counting CPUTime samples that have a non-null stack trace, while `jfr summary` counts all `jdk.CPUTimeSample` events. The JFR summary has no `ExecutionSample` / `NativeMethodSample`, so this output should be coming from CPUTime.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3150287896


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -173,6 +199,11 @@ public static void printReport(
     if (count < 1) {
       throw new IllegalArgumentException("tests.profile.count must be positive");
     }
+
+    // Pre-scan to detect if CPU-time samples (Java 25+, JEP 509) are available.
+    // If so, prefer them over legacy execution samples to avoid double-counting.
+    boolean hasCPUTimeSamples = "cpu".equals(mode) && detectCPUTimeSamples(files);

Review Comment:
   Sure, updated so now throws IllegalStateException if both CPU-time and legacy execution samples appear anywhere. ShowJfrProfileSummaryTask catches that and rethrows as GradleException so the failure message is obvious from Gradle. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand commented on PR #15983:
URL: https://github.com/apache/lucene/pull/15983#issuecomment-4345868221

   Hmm, there is some pre-existing issue that causes gradle not to print the JFR stack traces.  Instead it says this:
   
   ```
   > Task :showJfrProfileSummary
   One of the test tasks failed, skipping.
   ```
   
   Yet tests were successful, nothing seems to have failed.
   
   This is what I'm running:
   
   ```
   ./gradlew -p lucene/core test -Ptests.profile=true -Ptests.profile.stacksize=8 -Ptests.profile.linenumbers=true
   ```
   
   Somehow in [`CodeProfilingPlugin.java`](./build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/CodeProfilingPlugin.java) this part is false(?)-failing:
   
   ```
           if (getShouldRunConditions().get().stream().anyMatch(value -> value == false)) {
             getLogger().lifecycle("One of the test tasks failed, skipping.");
             return;
           }
   ```
   
   I haven't debugged any further yet ... if I disable that check then I get some profiler output but I don't think it's counting CPUTime events ... not sure:
   
   ```
   Aggregated summary of 1 jfr profile.
   PROFILE SUMMARY from 105485 events (total: 105485)
     tests.profile.mode=cpu
     tests.profile.count=10
     tests.profile.stacksize=8
     tests.profile.linenumbers=true
   PERCENT       CPU SAMPLES   STACK
   0.47%         498           sun.nio.ch.UnixFileDispatcherImpl#pread0() [Native code]
                                 at sun.nio.ch.UnixFileDispatcherImpl#pread():57 [JIT compiled code]
                                 at sun.nio.ch.IOUtil#readIntoNativeBuffer():339 [JIT compiled code]
                                 at sun.nio.ch.IOUtil#read():307 [JIT compiled code]
                                 at sun.nio.ch.IOUtil#read():284 [Inlined code]
                                 at sun.nio.ch.FileChannelImpl#readInternal():1198 [JIT compiled code]
                                 at sun.nio.ch.FileChannelImpl#implRead():1170 [JIT compiled code]
                                 at sun.nio.ch.FileChannelImpl#read():1152 [JIT compiled code]
   0.25%         265           org.apache.lucene.util.ByteBlockPool$DirectTrackingAllocator#getByteBlock():97 [JIT compiled cod\
   e]
                                 at org.apache.lucene.util.ByteBlockPool#nextBuffer():196 [JIT compiled code]
                                 at org.apache.lucene.index.TermsHashPerField#initStreamSlices():161 [JIT compiled code]
                                 at org.apache.lucene.index.TermsHashPerField#add():139 [Inlined code]
                                 at org.apache.lucene.index.TermsHashPerField#add():207 [JIT compiled code]
                                 at org.apache.lucene.index.IndexingChain$PerField#invertTokenStream():1365 [JIT compiled code]
                                 at org.apache.lucene.index.IndexingChain$PerField#invert():1256 [JIT compiled code]
                                 at org.apache.lucene.index.IndexingChain#processField():773 [JIT compiled code]
   ```
   
   I'm also baffled by the total event count (105485) ... it doesn't match what `jfr summary` says for `jdk.CPUTimeSample`:
   
   ```
   base) raptorlake:trunk[main]$ jfr summary ./lucene/core/build/tests-cwd/hotspot-pid-3877240-id-1-2026_04_29_12_55_47.jfr
   
    Version: 2.1
    Chunks: 7
    Start: 2026-04-29 16:53:42 (UTC)
    Duration: 125 s
   
    Event Type                              Count  Size (bytes)
   =============================================================
    jdk.ObjectAllocationInNewTLAB          164932       3167800
    jdk.CPUTimeSample                      111550       1964718
    jdk.ObjectAllocationOutsideTLAB         22485        386121
    org.junit.TestExecution                  8673        671942
    jdk.Checkpoint                           7698      81389727
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "rmuir (via GitHub)" <gi...@apache.org>.
rmuir commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3150342939


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -101,10 +101,17 @@ public static void main(String[] args) throws IOException {
   }
 
   /** true if we care about this event */
-  static boolean isInteresting(String mode, RecordedEvent event) {
+  static boolean isInteresting(String mode, RecordedEvent event, boolean hasCPUTimeSamples) {
     String name = event.getEventType().getName();
     switch (mode) {
       case "cpu":
+        if (hasCPUTimeSamples) {

Review Comment:
   I don't think we need this boolean parameter nor the if block.
   
   Just something like:
   ```java
   return name.equals("jdk.CPUTimeSample") || 
          name.equals("jdk.ExecutionSample") ||
          name.equals("jdk.NativeMethodSample");
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "rmuir (via GitHub)" <gi...@apache.org>.
rmuir commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3150351097


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -121,6 +128,37 @@ static boolean isGradlePollThread(RecordedThread thread) {
     return (thread != null && thread.getJavaName().startsWith("/127.0.0.1"));
   }
 
+  /**
+   * Pre-scan recording files for CPU sampling strategy. Returns whether any {@code
+   * jdk.CPUTimeSample} events appear in the inputs. Throws if recordings mix those with legacy
+   * wall-clock samples ({@code jdk.ExecutionSample} / {@code jdk.NativeMethodSample}); only one
+   * CPU sampler should be enabled in JFR settings.
+   */
+  static boolean resolveCpuTimeSampling(List<String> files) throws IOException {

Review Comment:
   Remove the whole function as the two files are mutually exclusive. This is very verbose and not needed.



##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -173,6 +213,10 @@ public static void printReport(
     if (count < 1) {
       throw new IllegalArgumentException("tests.profile.count must be positive");
     }
+
+    // Pre-scan recordings: decide CPU-time vs legacy sampling and reject mixed configurations.
+    boolean hasCPUTimeSamples = "cpu".equals(mode) && resolveCpuTimeSampling(files);

Review Comment:
   nuke this one too



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "rmuir (via GitHub)" <gi...@apache.org>.
rmuir commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3154844306


##########
gradle/testing/profiling.linux.jfc:
##########
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<!--
+  Linux: JEP 509 jdk.CPUTimeSample only (no jdk.ExecutionSample / jdk.NativeMethodSample).
+  Wall-clock sampling at 1 ms added measurable overhead in long runs; CPU-time sampling keeps
+  short tests useful via a 1 ms throttle while avoiding duplicate wall-clock + CPU samplers.
+-->
+<configuration version="2.0" label="TestProfilingLinux" description="CPU-time sampling for unit tests (Linux)" provider="Apache">
+  <event name="jdk.ExecutionSample">
+    <setting name="enabled">false</setting>

Review Comment:
   i think you are correct, I don't believe it is strictly necessary to have them in this file with enabled: false.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3154493070


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/CodeProfilingPlugin.java:
##########
@@ -254,4 +255,14 @@ private record ProfilingOptions(
       Provider<Integer> countOption,
       Provider<Boolean> lineNumbersOption,
       Provider<Boolean> frametypesOption) {}
+
+  /**
+   * JEP 509 CPU-time sampling ({@code jdk.CPUTimeSample}) is implemented on Linux. Use a Linux-only
+   * JFR template with CPU-time sampling only; other hosts keep wall-clock execution sampling for
+   * short tests.

Review Comment:
   Wait, it's for all tests, not just short tests right?  Maybe just remove ` for short tests`?



##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/CodeProfilingPlugin.java:
##########
@@ -254,4 +255,14 @@ private record ProfilingOptions(
       Provider<Integer> countOption,
       Provider<Boolean> lineNumbersOption,
       Provider<Boolean> frametypesOption) {}
+
+  /**
+   * JEP 509 CPU-time sampling ({@code jdk.CPUTimeSample}) is implemented on Linux. Use a Linux-only
+   * JFR template with CPU-time sampling only; other hosts keep wall-clock execution sampling for
+   * short tests.
+   */
+  private static String profilingSettingsPath() {
+    String os = System.getProperty("os.name", "").toLowerCase(Locale.ROOT);
+    return os.contains("linux") ? "testing/profiling.linux.jfc" : "testing/profiling.jfc";

Review Comment:
   Actually, instead of baking `linux` in the name, could we use `cputime`?  Maybe in the future other OS's can support CPU time sampling too...



##########
gradle/testing/profiling.linux.jfc:
##########
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<!--
+  Linux: JEP 509 jdk.CPUTimeSample only (no jdk.ExecutionSample / jdk.NativeMethodSample).
+  Wall-clock sampling at 1 ms added measurable overhead in long runs; CPU-time sampling keeps
+  short tests useful via a 1 ms throttle while avoiding duplicate wall-clock + CPU samplers.
+-->
+<configuration version="2.0" label="TestProfilingLinux" description="CPU-time sampling for unit tests (Linux)" provider="Apache">
+  <event name="jdk.ExecutionSample">
+    <setting name="enabled">false</setting>

Review Comment:
   Oh, are these events enabled by default, so we have to have these entries (`jdk.ExecutionSample` and `jdk.NativeMethodSample`) to explicitly then disable them?



##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/CodeProfilingPlugin.java:
##########
@@ -254,4 +255,14 @@ private record ProfilingOptions(
       Provider<Integer> countOption,
       Provider<Boolean> lineNumbersOption,
       Provider<Boolean> frametypesOption) {}
+
+  /**
+   * JEP 509 CPU-time sampling ({@code jdk.CPUTimeSample}) is implemented on Linux. Use a Linux-only

Review Comment:
   Maybe `is currently (Java 25) implemented only on Linux, so we use a Linux-only JFR template...`?



##########
lucene/CHANGES.txt:
##########
@@ -185,6 +185,11 @@ Changes in Runtime Behavior
 
 Build
 ---------------------
+* GITHUB#15926: Support jdk.CPUTimeSample event (Java 25+, JEP 509) in ProfileResults.

Review Comment:
   Can we word a bit more user-friendly-y?  Maybe `Use the new (Java 25+, JEP 509) CPU time sampling profiler when available (currently just on Linux), and fall back to the legacy wall-clock...`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "rmuir (via GitHub)" <gi...@apache.org>.
rmuir commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3149937885


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -121,6 +127,24 @@ static boolean isGradlePollThread(RecordedThread thread) {
     return (thread != null && thread.getJavaName().startsWith("/127.0.0.1"));
   }
 
+  /**
+   * Pre-scan recording files to detect if any jdk.CPUTimeSample events are present. When they are,
+   * we prefer them over legacy jdk.ExecutionSample/jdk.NativeMethodSample to avoid double-counting.
+   */
+  static boolean detectCPUTimeSamples(List<String> files) throws IOException {

Review Comment:
   Instead of this logic, should we just have profiling.linux.jfc that is loaded for linux, and profiling.jfc used for others?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3150287896


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -173,6 +199,11 @@ public static void printReport(
     if (count < 1) {
       throw new IllegalArgumentException("tests.profile.count must be positive");
     }
+
+    // Pre-scan to detect if CPU-time samples (Java 25+, JEP 509) are available.
+    // If so, prefer them over legacy execution samples to avoid double-counting.
+    boolean hasCPUTimeSamples = "cpu".equals(mode) && detectCPUTimeSamples(files);

Review Comment:
   Sure, updated so now throws IllegalStateException if both CPU-time and legacy execution samples appear anywhere. ShowJfrProfileSummaryTask catches that and rethrows as GradleException so the failure message is obvious from Gradle. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3150287896


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -173,6 +199,11 @@ public static void printReport(
     if (count < 1) {
       throw new IllegalArgumentException("tests.profile.count must be positive");
     }
+
+    // Pre-scan to detect if CPU-time samples (Java 25+, JEP 509) are available.
+    // If so, prefer them over legacy execution samples to avoid double-counting.
+    boolean hasCPUTimeSamples = "cpu".equals(mode) && detectCPUTimeSamples(files);

Review Comment:
   Sure, updated so now throws IllegalStateException if both CPU-time and legacy execution samples appear anywhere. ShowJfrProfileSummaryTask catches that and rethrows as GradleException so the failure message is obvious from Gradle.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3155052586


##########
gradle/testing/profiling.cputime.jfc:
##########
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<!--
+  Linux: JEP 509 jdk.CPUTimeSample only (no jdk.ExecutionSample / jdk.NativeMethodSample).
+  Wall-clock sampling at 1 ms added measurable overhead in long runs; CPU-time sampling keeps
+  short tests useful via a 1 ms throttle while avoiding duplicate wall-clock + CPU samplers.
+-->
+<configuration version="2.0" label="TestProfilingLinux" description="CPU-time sampling for unit tests (Linux)" provider="Apache">
+  <event name="jdk.ExecutionSample">
+    <setting name="enabled">false</setting>

Review Comment:
   removed the explicit disabled entries. The CPU time template now only enables jdk.CPUTimeSample plus the allocation events used by heap profiling. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3154999341


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/CodeProfilingPlugin.java:
##########
@@ -254,4 +255,14 @@ private record ProfilingOptions(
       Provider<Integer> countOption,
       Provider<Boolean> lineNumbersOption,
       Provider<Boolean> frametypesOption) {}
+
+  /**
+   * JEP 509 CPU-time sampling ({@code jdk.CPUTimeSample}) is implemented on Linux. Use a Linux-only

Review Comment:
   yes, updated. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3152111522


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ProfileResults.java:
##########
@@ -173,6 +213,10 @@ public static void printReport(
     if (count < 1) {
       throw new IllegalArgumentException("tests.profile.count must be positive");
     }
+
+    // Pre-scan recordings: decide CPU-time vs legacy sampling and reject mixed configurations.
+    boolean hasCPUTimeSamples = "cpu".equals(mode) && resolveCpuTimeSampling(files);

Review Comment:
   sure, removed this too. thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3150278259


##########
gradle/testing/profiling.jfc:
##########
@@ -29,6 +29,11 @@ Collects only execution and method samples at a low interval
     <setting name="period">1 ms</setting>
   </event>
 
+  <event name="jdk.CPUTimeSample">

Review Comment:
   Done, 
   
   1. Added gradle/testing/profiling.linux.jfc: legacy samplers off, jdk.CPUTimeSample on with a 1 ms throttle so short chunks still get dense enough samples.
   2. Left gradle/testing/profiling.jfc for non-Linux with 1 ms ExecutionSample / NativeMethodSample.
   3. CodeProfilingPlugin loads the Linux file when os.name contains linux, otherwise profiling.jfc.
   
   Thanks both!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Support jdk.CPUTimeSample event in ProfileResults for Java 25+ (JEP 509) [lucene]

Posted by "rmuir (via GitHub)" <gi...@apache.org>.
rmuir commented on code in PR #15983:
URL: https://github.com/apache/lucene/pull/15983#discussion_r3150347815


##########
gradle/testing/profiling.jfc:
##########
@@ -16,7 +16,9 @@
     limitations under the License.
 -->
 <!--
-Collects only execution and method samples at a low interval
+  Wall-clock execution samples for CPU profiling on platforms where JEP 509 CPU-time sampling
+  is unavailable (non-Linux). On Linux, CodeProfilingPlugin uses profiling.linux.jfc instead.

Review Comment:
   I don't see a `profiling.linux.jfc` in your PR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org