You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by er...@apache.org on 2022/07/06 09:52:07 UTC

[iotdb] 01/01: Add test stats in cluster IT for future use

This is an automated email from the ASF dual-hosted git repository.

ericpai pushed a commit to branch improve/time-stat
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 9a4714b1d3fd0c072a98658d8fd3ce1b6b95db09
Author: ericpai <er...@hotmail.com>
AuthorDate: Wed Jul 6 17:51:52 2022 +0800

    Add test stats in cluster IT for future use
---
 .../org/apache/iotdb/it/env/IoTDBTestRunner.java   | 45 ++++++++++++++++++++--
 1 file changed, 41 insertions(+), 4 deletions(-)

diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/IoTDBTestRunner.java b/integration-test/src/main/java/org/apache/iotdb/it/env/IoTDBTestRunner.java
index d865e736fc..88a272ea79 100644
--- a/integration-test/src/main/java/org/apache/iotdb/it/env/IoTDBTestRunner.java
+++ b/integration-test/src/main/java/org/apache/iotdb/it/env/IoTDBTestRunner.java
@@ -18,6 +18,7 @@
  */
 package org.apache.iotdb.it.env;
 
+import org.jetbrains.annotations.NotNull;
 import org.junit.runner.Description;
 import org.junit.runner.notification.RunNotifier;
 import org.junit.runners.BlockJUnit4ClassRunner;
@@ -26,14 +27,29 @@ import org.junit.runners.model.InitializationError;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 public class IoTDBTestRunner extends BlockJUnit4ClassRunner {
 
   private static final Logger logger = LoggerFactory.getLogger(IoTDBTestRunner.class);
+  private final List<TestStat> testStats = new ArrayList<>();
 
   public IoTDBTestRunner(Class<?> testClass) throws InitializationError {
     super(testClass);
   }
 
+  @Override
+  public void run(RunNotifier notifier) {
+    super.run(notifier);
+    Collections.sort(testStats);
+    System.out.println("==== Top 30 slowest cases ====");
+    for (int i = 0; i < Math.min(testStats.size(), 30); i++) {
+      System.out.println(testStats.get(i));
+    }
+  }
+
   @Override
   protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
     Description description = describeChild(method);
@@ -41,9 +57,30 @@ public class IoTDBTestRunner extends BlockJUnit4ClassRunner {
     long currentTime = System.currentTimeMillis();
     EnvFactory.getEnv().setTestMethodName(description.getMethodName());
     super.runChild(method, notifier);
-    logger.info(
-        "Done {}. Cost: {}s",
-        description.getMethodName(),
-        (System.currentTimeMillis() - currentTime) / 1000.0);
+    double timeCost = (System.currentTimeMillis() - currentTime) / 1000.0;
+    String testName = description.getClassName() + "." + description.getMethodName();
+    logger.info("Done {}. Cost: {}s", description.getMethodName(), timeCost);
+    testStats.add(new TestStat(testName, timeCost));
+  }
+
+  private static class TestStat implements Comparable<TestStat> {
+    private final String name;
+    private final double seconds;
+
+    public TestStat(String name, double seconds) {
+      this.name = name;
+      this.seconds = seconds;
+    }
+
+    @Override
+    public int compareTo(@NotNull TestStat o) {
+      // Compare in a reverse order
+      return Double.compare(o.seconds, seconds);
+    }
+
+    @Override
+    public String toString() {
+      return String.format("%.3f\t%s", seconds, name);
+    }
   }
 }