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>
This commit is contained in:
parent
803fb64f05
commit
13dae81bd2
2 changed files with 24 additions and 9 deletions
|
|
@ -122,7 +122,12 @@ class JavaTracer:
|
|||
|
||||
def build_jfr_env(self, jfr_file: Path) -> dict[str, str]:
|
||||
env = os.environ.copy()
|
||||
jfr_opts = f"-XX:StartFlightRecording=filename={jfr_file.resolve()},settings=profile,dumponexit=true"
|
||||
# Use profile settings with increased sampling frequency (1ms instead of default 10ms)
|
||||
# This captures more samples for short-running programs
|
||||
jfr_opts = (
|
||||
f"-XX:StartFlightRecording=filename={jfr_file.resolve()},settings=profile,dumponexit=true"
|
||||
",jdk.ExecutionSample#period=1ms"
|
||||
)
|
||||
existing = env.get("JAVA_TOOL_OPTIONS", "")
|
||||
env["JAVA_TOOL_OPTIONS"] = f"{existing} {jfr_opts}".strip()
|
||||
return env
|
||||
|
|
|
|||
|
|
@ -36,20 +36,30 @@ public class Workload {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Exercise the methods so the tracer can capture invocations
|
||||
// Run methods with large inputs so JFR can capture CPU samples.
|
||||
// Small inputs finish too fast (<1ms) for JFR's 10ms sampling interval.
|
||||
for (int round = 0; round < 1000; round++) {
|
||||
computeSum(100_000);
|
||||
repeatString("hello world ", 1000);
|
||||
|
||||
List<Integer> nums = new ArrayList<>();
|
||||
for (int i = 1; i <= 10_000; i++) nums.add(i);
|
||||
filterEvens(nums);
|
||||
|
||||
Workload w = new Workload();
|
||||
w.instanceMethod(100_000, 42);
|
||||
}
|
||||
|
||||
// Also call with small inputs for variety in traced args
|
||||
System.out.println("computeSum(100) = " + computeSum(100));
|
||||
System.out.println("computeSum(50) = " + computeSum(50));
|
||||
|
||||
System.out.println("repeatString(\"ab\", 3) = " + repeatString("ab", 3));
|
||||
System.out.println("repeatString(\"x\", 5) = " + repeatString("x", 5));
|
||||
|
||||
List<Integer> nums = new ArrayList<>();
|
||||
for (int i = 1; i <= 10; i++) nums.add(i);
|
||||
System.out.println("filterEvens(1..10) = " + filterEvens(nums));
|
||||
List<Integer> small = new ArrayList<>();
|
||||
for (int i = 1; i <= 10; i++) small.add(i);
|
||||
System.out.println("filterEvens(1..10) = " + filterEvens(small));
|
||||
|
||||
Workload w = new Workload();
|
||||
System.out.println("instanceMethod(5, 3) = " + w.instanceMethod(5, 3));
|
||||
System.out.println("instanceMethod(10, 2) = " + w.instanceMethod(10, 2));
|
||||
|
||||
System.out.println("Workload complete.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue