Skip to content

Commit cc3240d

Browse files
committed
Add an option for printing the progress information
1 parent 31f4cc8 commit cc3240d

2 files changed

Lines changed: 46 additions & 33 deletions

File tree

src/sqlancer/Main.java

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -297,39 +297,9 @@ public static void main(String[] args) {
297297
System.exit(-1);
298298
}
299299

300-
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
301-
scheduler.scheduleAtFixedRate(new Runnable() {
302-
303-
private long timeMillis = System.currentTimeMillis();
304-
private long lastNrQueries = 0;
305-
private long lastNrDbs;
306-
307-
{
308-
timeMillis = System.currentTimeMillis();
309-
}
310-
311-
@Override
312-
public void run() {
313-
long elapsedTimeMillis = System.currentTimeMillis() - timeMillis;
314-
long currentNrQueries = nrQueries.get();
315-
long nrCurrentQueries = currentNrQueries - lastNrQueries;
316-
double throughput = nrCurrentQueries / (elapsedTimeMillis / 1000d);
317-
long currentNrDbs = nrDatabases.get();
318-
long nrCurrentDbs = currentNrDbs - lastNrDbs;
319-
double throughputDbs = nrCurrentDbs / (elapsedTimeMillis / 1000d);
320-
long successfulStatementsRatio = (long) (100.0 * nrSuccessfulActions.get()
321-
/ (nrSuccessfulActions.get() + nrUnsuccessfulActions.get()));
322-
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
323-
Date date = new Date();
324-
System.out.println(String.format(
325-
"[%s] Executed %d queries (%d queries/s; %.2f/s dbs, successful statements: %2d%%). Threads shut down: %d.",
326-
dateFormat.format(date), currentNrQueries, (int) throughput, throughputDbs,
327-
successfulStatementsRatio, threadsShutdown));
328-
timeMillis = System.currentTimeMillis();
329-
lastNrQueries = currentNrQueries;
330-
lastNrDbs = currentNrDbs;
331-
}
332-
}, 5, 5, TimeUnit.SECONDS);
300+
if (options.printProgressInformation()) {
301+
startProgressMonitor();
302+
}
333303

334304
ExecutorService executor = Executors.newFixedThreadPool(options.getNumberConcurrentThreads());
335305

@@ -422,4 +392,40 @@ private void runThread(final String databaseName) {
422392

423393
}
424394

395+
private static void startProgressMonitor() {
396+
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
397+
scheduler.scheduleAtFixedRate(new Runnable() {
398+
399+
private long timeMillis = System.currentTimeMillis();
400+
private long lastNrQueries = 0;
401+
private long lastNrDbs;
402+
403+
{
404+
timeMillis = System.currentTimeMillis();
405+
}
406+
407+
@Override
408+
public void run() {
409+
long elapsedTimeMillis = System.currentTimeMillis() - timeMillis;
410+
long currentNrQueries = nrQueries.get();
411+
long nrCurrentQueries = currentNrQueries - lastNrQueries;
412+
double throughput = nrCurrentQueries / (elapsedTimeMillis / 1000d);
413+
long currentNrDbs = nrDatabases.get();
414+
long nrCurrentDbs = currentNrDbs - lastNrDbs;
415+
double throughputDbs = nrCurrentDbs / (elapsedTimeMillis / 1000d);
416+
long successfulStatementsRatio = (long) (100.0 * nrSuccessfulActions.get()
417+
/ (nrSuccessfulActions.get() + nrUnsuccessfulActions.get()));
418+
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
419+
Date date = new Date();
420+
System.out.println(String.format(
421+
"[%s] Executed %d queries (%d queries/s; %.2f/s dbs, successful statements: %2d%%). Threads shut down: %d.",
422+
dateFormat.format(date), currentNrQueries, (int) throughput, throughputDbs,
423+
successfulStatementsRatio, threadsShutdown));
424+
timeMillis = System.currentTimeMillis();
425+
lastNrQueries = currentNrQueries;
426+
lastNrDbs = currentNrDbs;
427+
}
428+
}, 5, 5, TimeUnit.SECONDS);
429+
}
430+
425431
}

src/sqlancer/MainOptions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public class MainOptions {
3838
@Parameter(names="--password", description = "The password used to log into the DBMS")
3939
private String password = "sqlancer";
4040

41+
@Parameter(names="--print-progress-information", description = "Whether to print progress information such as the number of databases generated or queries issued", arity = 1)
42+
private boolean printProgressInformation = true;
43+
4144
public int getMaxExpressionDepth() {
4245
return maxExpressionDepth;
4346
}
@@ -88,5 +91,9 @@ public DBMS convert(String value) {
8891
return DBMS.valueOf(value);
8992
}
9093
}
94+
95+
public boolean printProgressInformation() {
96+
return printProgressInformation;
97+
}
9198

9299
}

0 commit comments

Comments
 (0)