Skip to content

Commit

Permalink
feat: Allow repeating analysis in CLI (#2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Sep 11, 2024
1 parent b15376e commit e5255b0
Showing 1 changed file with 28 additions and 11 deletions.
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(
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

0 comments on commit e5255b0

Please sign in to comment.