Till Westmann has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/960

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

ASTERIXDB-1501: add units for timings

Change-Id: If95a717b3f6ffceb8235409519ed602180c124dc
---
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, 63 insertions(+), 2 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/60/960/1

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..08ff165 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
@@ -246,9 +246,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(), formatTime(elapsedTime));
         pw.print("\t");
-        printField(pw, Metrics.executionTime.name(), 
String.valueOf(executionTime));
+        printField(pw, Metrics.executionTime.name(), 
formatTime(executionTime));
         pw.print("\t");
         printField(pw, Metrics.resultCount.name(), 
String.valueOf(resultCount));
         pw.print("\t");
@@ -256,6 +256,25 @@
         pw.print("\t}\n");
     }
 
+    static String formatTime(long nanoTime) {
+        final String strTime = String.valueOf(nanoTime);
+        final int len = strTime.length();
+        if (len > 9) {
+            return toUnit(strTime, len - 9, "s");
+        }
+        if (len > 6) {
+            return toUnit(strTime, len - 6, "ms");
+        }
+        if (len > 3) {
+            return toUnit(strTime, len - 3, "µs");
+        }
+        return strTime + "ns";
+    }
+
+    static String toUnit(String strTime, int split, String unit) {
+        return strTime.substring(0, split) + "." + strTime.substring(split) + 
unit;
+    }
+
     @Override
     protected void doPost(HttpServletRequest request, HttpServletResponse 
response)
             throws ServletException, IOException {
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..0b4ae62
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/QueryServiceServletTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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 testFormatTime() throws Exception {
+        Assert.assertEquals(QueryServiceServlet.formatTime(123456789012l), 
"123.456789012s");
+        Assert.assertEquals(QueryServiceServlet.formatTime(12345678901l), 
"12.345678901s");
+        Assert.assertEquals(QueryServiceServlet.formatTime(1234567890l), 
"1.234567890s");
+        Assert.assertEquals(QueryServiceServlet.formatTime(123456789l), 
"123.456789ms");
+        Assert.assertEquals(QueryServiceServlet.formatTime(12345678l), 
"12.345678ms");
+        Assert.assertEquals(QueryServiceServlet.formatTime(1234567l), 
"1.234567ms");
+        Assert.assertEquals(QueryServiceServlet.formatTime(123456l), 
"123.456µs");
+        Assert.assertEquals(QueryServiceServlet.formatTime(12345l), 
"12.345µs");
+        Assert.assertEquals(QueryServiceServlet.formatTime(1234l), "1.234µs");
+        Assert.assertEquals(QueryServiceServlet.formatTime(123l), "123ns");
+        Assert.assertEquals(QueryServiceServlet.formatTime(12l), "12ns");
+        Assert.assertEquals(QueryServiceServlet.formatTime(1l), "1ns");
+    }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If95a717b3f6ffceb8235409519ed602180c124dc
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <ti...@apache.org>

Reply via email to