From c7ce11f0031c81311a359de03380860fa4e366a5 Mon Sep 17 00:00:00 2001 From: Yuki Morishita Date: Thu, 27 Sep 2012 16:57:37 -0500 Subject: [PATCH] display elapsed time in 2 fraction digits in cli; patch by Radim Kolar, reviewed by yukim for CASSANDRA-3460 --- CHANGES.txt | 1 + .../org/apache/cassandra/cli/CliClient.java | 28 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index e48fbfd338..f598aa2c8f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -11,6 +11,7 @@ * fix error when using ORDER BY with extended selections (CASSANDRA-4689) * (CQL3) Fix validation for IN queries for non-PK cols (CASSANDRA-4709) * fix re-created keyspace disappering after 1.1.5 upgrade (CASSANDRA-4698) + * (CLI) display elapsed time in 2 fraction digits (CASSANDRA-3460) Merged from 1.0: * Switch from NBHM to CHM in MessagingService's callback map, which prevents OOM in long-running instances (CASSANDRA-4708) diff --git a/src/java/org/apache/cassandra/cli/CliClient.java b/src/java/org/apache/cassandra/cli/CliClient.java index d0fb54310d..b32b0f7dc9 100644 --- a/src/java/org/apache/cassandra/cli/CliClient.java +++ b/src/java/org/apache/cassandra/cli/CliClient.java @@ -461,7 +461,7 @@ public class CliClient throws InvalidRequestException, UnavailableException, TimedOutException, TException, IllegalAccessException, NotFoundException, InstantiationException, NoSuchFieldException { - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); ColumnParent parent = new ColumnParent(columnFamily); if(superColumnName != null) parent.setSuper_column(superColumnName); @@ -565,7 +565,7 @@ public class CliClient { if (!CliMain.isConnected() || !hasKeySpace()) return; - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); Tree columnFamilySpec = statement.getChild(0); String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec, keyspacesMap.get(keySpace).cf_defs); ByteBuffer key = getKeyAsBytes(columnFamily, columnFamilySpec.getChild(1)); @@ -734,7 +734,7 @@ public class CliClient if (!CliMain.isConnected() || !hasKeySpace()) return; - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); IndexClause clause = new IndexClause(); String columnFamily = CliCompiler.getColumnFamily(statement, keyspacesMap.get(keySpace).cf_defs); @@ -828,7 +828,7 @@ public class CliClient if (!CliMain.isConnected() || !hasKeySpace()) return; - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); // ^(NODE_COLUMN_ACCESS ) Tree columnFamilySpec = statement.getChild(0); Tree keyTree = columnFamilySpec.getChild(1); // could be a function or regular text @@ -1323,7 +1323,7 @@ public class CliClient if (!CliMain.isConnected() || !hasKeySpace()) return; - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); // extract column family String columnFamily = CliCompiler.getColumnFamily(statement, keyspacesMap.get(keySpace).cf_defs); @@ -2968,9 +2968,25 @@ public class CliClient return false; } + /** + * Print elapsed time. Print 2 fraction digits if eta is under 10 ms. + * @param startTime starting time in nanoseconds + */ private void elapsedTime(long startTime) { - sessionState.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime) + " msec(s)."); + /** time elapsed in nanoseconds */ + long eta = System.nanoTime() - startTime; + + sessionState.out.print("Elapsed time: "); + if (eta < 10000000) + { + sessionState.out.print(Math.round(eta/10000.0)/100.0); + } + else + { + sessionState.out.print(Math.round(eta/1000000.0)); + } + sessionState.out.println(" msec(s)."); } class CfAssumptions