Skip to content

Commit 2610e1f

Browse files
committed
Print an execution summary before exiting SQLancer
1 parent 3adbd60 commit 2610e1f

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/sqlancer/Main.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,30 @@ public static int executeMain(String... args) throws AssertionError {
415415

416416
if (options.printProgressInformation()) {
417417
startProgressMonitor();
418+
if (options.printProgressSummary()) {
419+
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
420+
421+
@Override
422+
public void run() {
423+
System.out.println("Overall execution statistics");
424+
System.out.println("============================");
425+
System.out.println(formatInteger(nrQueries.get()) + " queries");
426+
System.out.println(formatInteger(nrDatabases.get()) + " databases");
427+
System.out.println(
428+
formatInteger(nrSuccessfulActions.get()) + " successfully-executed statements");
429+
System.out.println(
430+
formatInteger(nrUnsuccessfulActions.get()) + " unsuccessfuly-executed statements");
431+
}
432+
433+
private String formatInteger(long intValue) {
434+
if (intValue > 1000) {
435+
return String.format("%,9dk", intValue / 1000);
436+
} else {
437+
return String.format("%,10d", intValue);
438+
}
439+
}
440+
}));
441+
}
418442
}
419443

420444
ExecutorService execService = Executors.newFixedThreadPool(options.getNumberConcurrentThreads());
@@ -499,6 +523,7 @@ private boolean run(MainOptions options, ExecutorService execService,
499523
} catch (InterruptedException e) {
500524
e.printStackTrace();
501525
}
526+
502527
return threadsShutdown == 0 ? 0 : options.getErrorExitCode();
503528
}
504529

src/sqlancer/MainOptions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public class MainOptions {
4848
@Parameter(names = "--print-progress-information", description = "Whether to print progress information such as the number of databases generated or queries issued", arity = 1)
4949
private boolean printProgressInformation = true; // NOPMD
5050

51+
@Parameter(names = "--print-progress-summary", description = "Whether to print an execution summary when exiting SQLancer", arity = 1)
52+
private boolean printProgressSummary; // NOPMD
53+
5154
@Parameter(names = "--timeout-seconds", description = "The timeout in seconds")
5255
private int timeoutSeconds = -1; // NOPMD
5356

@@ -135,6 +138,10 @@ public boolean printProgressInformation() {
135138
return printProgressInformation;
136139
}
137140

141+
public boolean printProgressSummary() {
142+
return printProgressSummary;
143+
}
144+
138145
public int getTimeoutSeconds() {
139146
return timeoutSeconds;
140147
}

0 commit comments

Comments
 (0)