Skip to content

Commit 4154563

Browse files
author
Vlad Ganzha
authored
Show the number of answers printed and the duration of a query (#110)
## What is the goal of this PR? We added statistic information to the UI about how many answers were printed and how long did the query take. ## What are the changes implemented in this PR? We added some statistic data at the end of the `printCancellableResult `: - answers count ; - duration of the query.
1 parent 8b56f49 commit 4154563

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

GraknConsole.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import java.nio.charset.StandardCharsets;
4646
import java.nio.file.Files;
4747
import java.nio.file.Paths;
48+
import java.time.Duration;
49+
import java.time.Instant;
4850
import java.util.Iterator;
4951
import java.util.List;
5052
import java.util.function.Consumer;
@@ -231,16 +233,22 @@ private void runQuery(Grakn.Transaction tx, String queryString) {
231233
}
232234

233235
private <T> void printCancellableResult(Stream<T> results, Consumer<T> printFn) {
236+
long counter = 0;
237+
Instant start = Instant.now();
238+
234239
try {
235240
boolean[] isCancelled = new boolean[1];
236241
terminal.handle(Terminal.Signal.INT, s -> isCancelled[0] = true);
237242
Iterator<T> iterator = results.iterator();
238243
while (!isCancelled[0] && iterator.hasNext()) {
244+
counter++;
239245
printFn.accept(iterator.next());
240246
}
241247
} finally {
242248
terminal.handle(Terminal.Signal.INT, Terminal.SignalHandler.SIG_IGN);
243249
}
250+
Instant end = Instant.now();
251+
printer.info("answers: " + counter + ", duration: " + Duration.between(start, end).toMillis() +" ms");
244252
}
245253

246254
public static void main(String[] args) {

0 commit comments

Comments
 (0)