Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now allows the benchmark to go into profiling mode #3485

Merged
merged 1 commit into from Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 35 additions & 5 deletions src/test/java/benchmark/ComplexQueryBenchmark.java
Expand Up @@ -29,6 +29,9 @@
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -102,21 +105,47 @@ public static void main(String[] args) throws Exception {
@SuppressWarnings({"ConstantValue", "LoopConditionNotUpdatedInsideLoop"})
private static void runAtStartup() {
// set this to true if you want to hook in profiler say to a forever running JVM
boolean forever = Boolean.getBoolean("forever");
int runForMillis = getRunForMillis();

long then = System.currentTimeMillis();
System.out.printf("Running initial code before starting the benchmark in forever=%b mode \n", forever);
if (runForMillis <= 0) {
return;
}
long now, then = System.currentTimeMillis();
System.out.printf("Running initial code before starting the benchmark - runForMillis=%d \n", runForMillis);
System.out.print("Get your profiler in order and press enter... \n");
readLine();
System.out.print("Lets go...\n");
ComplexQueryBenchmark complexQueryBenchmark = new ComplexQueryBenchmark();
complexQueryBenchmark.setUp();
do {
System.out.print("Running queries....\n");
System.out.printf("Running queries for %d millis....\n", System.currentTimeMillis() - then);
complexQueryBenchmark.howManyItems = 100;
complexQueryBenchmark.runManyQueriesToCompletion();
} while (forever);
now = System.currentTimeMillis();
} while ((now - then) < runForMillis);
complexQueryBenchmark.tearDown();

System.out.printf("This took %d millis\n", System.currentTimeMillis() - then);
System.exit(0);

}

private static void readLine() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private static int getRunForMillis() {
String runFor = System.getenv("runForMillis");
try {
return Integer.parseInt(runFor);
} catch (NumberFormatException e) {
return -1;
}
}

@SuppressWarnings("UnnecessaryLocalVariable")
Expand Down Expand Up @@ -200,6 +229,7 @@ private void sleep(Integer howLong) {
}

AtomicInteger logCount = new AtomicInteger();

private void logEvery(int every, String s) {
int count = logCount.getAndIncrement();
if (count == 0 || count % every == 0) {
Expand Down