asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Till Westmann (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: ASTERIXDB-1501: add units for timings
Date Sat, 25 Jun 2016 21:24:44 GMT
Till Westmann has submitted this change and it was merged.

Change subject: ASTERIXDB-1501: add units for timings
......................................................................


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>
---
M asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
A asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/QueryServiceServletTest.java
2 files changed, 75 insertions(+), 2 deletions(-)

Approvals:
  Yingyi Bu: Looks good to me, approved
  Jenkins: Looks good to me, but someone else must approve; Verified



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 @@
         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 @@
         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");
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));
+    }
+}

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/960
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If95a717b3f6ffceb8235409519ed602180c124dc
Gerrit-PatchSet: 5
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <tillw@apache.org>
Gerrit-Reviewer: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Michael Blow <michael.blow@couchbase.com>
Gerrit-Reviewer: Till Westmann <tillw@apache.org>
Gerrit-Reviewer: Yingyi Bu <buyingyi@gmail.com>
Gerrit-Reviewer: abdullah alamoudi <bamousaa@gmail.com>

Mime
View raw message