Skip to content

Commit 13dae81

Browse files
misrasaurabh1claude
andcommitted
fix: increase JFR sampling frequency and make Workload exercise functions harder
- Set jdk.ExecutionSample#period=1ms (default was 10ms) so JFR captures samples from shorter-running programs - Workload.main now runs 1000 rounds with larger inputs so JFR can capture method-level CPU samples (repeatString with O(n²) concat dominates ~75% of samples) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 803fb64 commit 13dae81

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

  • codeflash/languages/java
  • tests/test_languages/fixtures/java_tracer_e2e/src/main/java/com/example

codeflash/languages/java/tracer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ def create_tracer_config(
122122

123123
def build_jfr_env(self, jfr_file: Path) -> dict[str, str]:
124124
env = os.environ.copy()
125-
jfr_opts = f"-XX:StartFlightRecording=filename={jfr_file.resolve()},settings=profile,dumponexit=true"
125+
# Use profile settings with increased sampling frequency (1ms instead of default 10ms)
126+
# This captures more samples for short-running programs
127+
jfr_opts = (
128+
f"-XX:StartFlightRecording=filename={jfr_file.resolve()},settings=profile,dumponexit=true"
129+
",jdk.ExecutionSample#period=1ms"
130+
)
126131
existing = env.get("JAVA_TOOL_OPTIONS", "")
127132
env["JAVA_TOOL_OPTIONS"] = f"{existing} {jfr_opts}".strip()
128133
return env

tests/test_languages/fixtures/java_tracer_e2e/src/main/java/com/example/Workload.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,30 @@ public int instanceMethod(int x, int y) {
3636
}
3737

3838
public static void main(String[] args) {
39-
// Exercise the methods so the tracer can capture invocations
40-
System.out.println("computeSum(100) = " + computeSum(100));
41-
System.out.println("computeSum(50) = " + computeSum(50));
39+
// Run methods with large inputs so JFR can capture CPU samples.
40+
// Small inputs finish too fast (<1ms) for JFR's 10ms sampling interval.
41+
for (int round = 0; round < 1000; round++) {
42+
computeSum(100_000);
43+
repeatString("hello world ", 1000);
44+
45+
List<Integer> nums = new ArrayList<>();
46+
for (int i = 1; i <= 10_000; i++) nums.add(i);
47+
filterEvens(nums);
4248

49+
Workload w = new Workload();
50+
w.instanceMethod(100_000, 42);
51+
}
52+
53+
// Also call with small inputs for variety in traced args
54+
System.out.println("computeSum(100) = " + computeSum(100));
4355
System.out.println("repeatString(\"ab\", 3) = " + repeatString("ab", 3));
44-
System.out.println("repeatString(\"x\", 5) = " + repeatString("x", 5));
4556

46-
List<Integer> nums = new ArrayList<>();
47-
for (int i = 1; i <= 10; i++) nums.add(i);
48-
System.out.println("filterEvens(1..10) = " + filterEvens(nums));
57+
List<Integer> small = new ArrayList<>();
58+
for (int i = 1; i <= 10; i++) small.add(i);
59+
System.out.println("filterEvens(1..10) = " + filterEvens(small));
4960

5061
Workload w = new Workload();
5162
System.out.println("instanceMethod(5, 3) = " + w.instanceMethod(5, 3));
52-
System.out.println("instanceMethod(10, 2) = " + w.instanceMethod(10, 2));
5363

5464
System.out.println("Workload complete.");
5565
}

0 commit comments

Comments
 (0)