asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject asterixdb git commit: ASTERIXDB-1501: add units for timings
Date Sat, 25 Jun 2016 21:25:44 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master 6eaf27787 -> cb66e12f7


ASTERIXDB-1501: add units for timings

Change-Id: If95a717b3f6ffceb8235409519ed602180c124dc
Reviewed-on: https://asterix-gerrit.ics.uci.edu/960
Reviewed-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/cb66e12f
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/cb66e12f
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/cb66e12f

Branch: refs/heads/master
Commit: cb66e12f745b998c73c42b15c9e1b9722d6d454e
Parents: 6eaf277
Author: Till Westmann <tillw@apache.org>
Authored: Sat Jun 25 12:46:51 2016 +0200
Committer: Till Westmann <tillw@apache.org>
Committed: Sat Jun 25 14:24:43 2016 -0700

----------------------------------------------------------------------
 .../api/http/servlet/QueryServiceServlet.java   | 32 +++++++++++++-
 .../http/servlet/QueryServiceServletTest.java   | 45 ++++++++++++++++++++
 2 files changed, 75 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/cb66e12f/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
index 35a780b..a080c83 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
@@ -125,6 +125,34 @@ public class QueryServiceServlet extends HttpServlet {
         resultSize
     }
 
+    public enum TimeUnit {
+        SEC("s", 9),
+        MILLI("ms", 6),
+        MICRO("µs", 3),
+        NANO("ns", 0);
+
+        String unit;
+        int nanoDigits;
+
+        TimeUnit(String unit, int nanoDigits) {
+            this.unit = unit;
+            this.nanoDigits = nanoDigits;
+        }
+
+        static String formatNanos(long nanoTime) {
+            final String strTime = String.valueOf(nanoTime);
+            final int len = strTime.length();
+            for (TimeUnit tu : TimeUnit.values()) {
+                if (len > tu.nanoDigits) {
+                    final String integer = strTime.substring(0, len - tu.nanoDigits);
+                    final String fractional = strTime.substring(len - tu.nanoDigits);
+                    return integer + (fractional.length() > 0 ? "." + fractional : "")
+ tu.unit;
+                }
+            }
+            return "illegal string value: " + strTime;
+        }
+    }
+
     private final ILangCompilationProvider compilationProvider = new SqlppCompilationProvider();
 
     static SessionConfig.OutputFormat getFormat(HttpServletRequest request) {
@@ -246,9 +274,9 @@ public class QueryServiceServlet extends HttpServlet {
         pw.print(ResultFields.metrics.name());
         pw.print("\": {\n");
         pw.print("\t");
-        printField(pw, Metrics.elapsedTime.name(), String.valueOf(elapsedTime));
+        printField(pw, Metrics.elapsedTime.name(), TimeUnit.formatNanos(elapsedTime));
         pw.print("\t");
-        printField(pw, Metrics.executionTime.name(), String.valueOf(executionTime));
+        printField(pw, Metrics.executionTime.name(), TimeUnit.formatNanos(executionTime));
         pw.print("\t");
         printField(pw, Metrics.resultCount.name(), String.valueOf(resultCount));
         pw.print("\t");

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/cb66e12f/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/QueryServiceServletTest.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/QueryServiceServletTest.java
b/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/QueryServiceServletTest.java
new file mode 100644
index 0000000..f4889a0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/QueryServiceServletTest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.api.http.servlet;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class QueryServiceServletTest {
+
+    @Test
+    public void testTimeUnitFormatNanos() throws Exception {
+        Assert.assertEquals("123.456789012s", QueryServiceServlet.TimeUnit.formatNanos(123456789012l));
+        Assert.assertEquals("12.345678901s", QueryServiceServlet.TimeUnit.formatNanos(12345678901l));
+        Assert.assertEquals("1.234567890s", QueryServiceServlet.TimeUnit.formatNanos(1234567890l));
+        Assert.assertEquals("123.456789ms", QueryServiceServlet.TimeUnit.formatNanos(123456789l));
+        Assert.assertEquals("12.345678ms", QueryServiceServlet.TimeUnit.formatNanos(12345678l));
+        Assert.assertEquals("1.234567ms", QueryServiceServlet.TimeUnit.formatNanos(1234567l));
+        Assert.assertEquals("123.456µs", QueryServiceServlet.TimeUnit.formatNanos(123456l));
+        Assert.assertEquals("12.345µs", QueryServiceServlet.TimeUnit.formatNanos(12345l));
+        Assert.assertEquals("1.234µs", QueryServiceServlet.TimeUnit.formatNanos(1234l));
+        Assert.assertEquals("123ns", QueryServiceServlet.TimeUnit.formatNanos(123l));
+        Assert.assertEquals("12ns", QueryServiceServlet.TimeUnit.formatNanos(12l));
+        Assert.assertEquals("1ns", QueryServiceServlet.TimeUnit.formatNanos(1l));
+        Assert.assertEquals("-123.456789012s", QueryServiceServlet.TimeUnit.formatNanos(-123456789012l));
+        Assert.assertEquals("120.000000000s", QueryServiceServlet.TimeUnit.formatNanos(120000000000l));
+        Assert.assertEquals("-12ns", QueryServiceServlet.TimeUnit.formatNanos(-12l));
+    }
+}


Mime
View raw message