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

feat: Allow repeating analysis in CLI #2476

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public class CliAnalysis implements Callable<Integer> {
@CommandLine.ArgGroup(exclusive = false)
private ExtendedSourceConfig extendedSourceConfig = new ExtendedSourceConfig();

@CommandLine.Option(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it make more sense to name it warm JIT or something? Or is there other use case for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's one of the possible usecases, but I prefer to just call it repeat as it is exactly what it does.

description = "Repeat analysis",
names = {"--repeat"},
defaultValue = "1")
private int repeat = 1;


@Override
public Integer call() throws Exception {
Expand All @@ -92,27 +98,38 @@ public Integer call() throws Exception {

cliClientProvider.setCpyPaths(createCopybooksPaths());
cliClientProvider.setCpyExt(createCopybooksExtensions());
JsonObject result = new JsonObject();
result.addProperty("uri", (inputConfig.useStdin) ? "N/A (User Input)" : inputConfig.src.toURI().toString());
result.addProperty("language", dialect.getId());
try {
Cli.Result analysisResult = parent.runAnalysis(inputConfig.src, dialect, diCtx, true);
parent.addTiming(result, analysisResult.ctx.getBenchmarkSession());
if (!hideDiagnostics) {
generateDiagnostics(analysisResult, result);
}
collectGcAndMemoryStats(result);
System.out.println(CliUtils.GSON.toJson(result));
for (int i = 0; i < repeat; ++i) {
JsonObject result = createResultJson();

Cli.Result analysisResult = parent.runAnalysis(inputConfig.src, dialect, diCtx, true);
parent.addTiming(result, analysisResult.ctx.getBenchmarkSession());
if (!hideDiagnostics) {
generateDiagnostics(analysisResult, result);
}
collectGcAndMemoryStats(result);
System.out.println(CliUtils.GSON.toJson(result));

handleExtendedSource(analysisResult);
handleExtendedSource(analysisResult);
}
return Cli.SUCCESS;
} catch (Exception e) {
JsonObject result = createResultJson();
result.addProperty("crash", e.getMessage() != null && e.getMessage().isEmpty() ? "error" : e.getMessage());
System.out.println(CliUtils.GSON.toJson(result));
return Cli.FAILURE;
}
}

private JsonObject createResultJson() {
JsonObject result = new JsonObject();

result.addProperty("uri", (inputConfig.useStdin) ? "N/A (User Input)" : inputConfig.src.toURI().toString());
result.addProperty("language", dialect.getId());

return result;
}

private void generateDiagnostics(Cli.Result analysisResult, JsonObject result) {
JsonArray diagnostics = new JsonArray();
analysisResult
Expand Down
Loading