|
31 | 31 | import java.net.InetSocketAddress; |
32 | 32 | import java.net.ServerSocket; |
33 | 33 | import java.nio.charset.Charset; |
| 34 | +import java.nio.file.Files; |
| 35 | +import java.nio.file.Paths; |
34 | 36 | import java.util.ArrayList; |
35 | 37 | import java.util.Arrays; |
36 | 38 | import java.util.HashMap; |
|
39 | 41 | import java.util.Set; |
40 | 42 | import java.util.concurrent.TimeoutException; |
41 | 43 |
|
| 44 | +import org.apache.commons.collections.ArrayStack; |
42 | 45 | import org.apache.commons.io.FileUtils; |
43 | 46 | import org.apache.commons.io.IOUtils; |
44 | 47 | import org.apache.commons.lang3.ArrayUtils; |
|
91 | 94 | import org.junit.After; |
92 | 95 | import org.junit.Assert; |
93 | 96 | import org.junit.Before; |
| 97 | +import scala.Tuple4; |
94 | 98 |
|
95 | 99 | /** |
96 | 100 | * <p> |
|
106 | 110 | * |
107 | 111 | */ |
108 | 112 | public abstract class AutomatedTestBase { |
| 113 | + protected static final boolean BENCHMARK = true; |
| 114 | + protected static final int BENCHMARK_WARMUP_RUNS = 1; |
| 115 | + protected static final int BENCHMARK_REPETITIONS = 1; |
| 116 | + protected static final boolean ALLOW_GENERATED_REWRITES = true; |
| 117 | + protected static final String BASE_DATA_DIR = "/Users/janniklindemann/Dev/MScThesis/NGramAnalysis/"; |
| 118 | + private static String currentTestName = ""; |
| 119 | + private static int currentTestRun = -1; |
| 120 | + private static boolean benchmark_run = false; |
| 121 | + |
109 | 122 |
|
110 | 123 | static { |
111 | 124 | RewriterRuntimeUtils.setupIfNecessary(); |
| 125 | + |
| 126 | + if (BENCHMARK) { |
| 127 | + final List<Tuple4<String, Integer, Long, Long>> runTimes = new ArrayList<>(); |
| 128 | + |
| 129 | + DMLScript.runtimeMetricsInterceptor = (runTime, executionTime) -> { |
| 130 | + if (benchmark_run) |
| 131 | + runTimes.add(new Tuple4<>(currentTestName, currentTestRun, runTime, executionTime)); |
| 132 | + }; |
| 133 | + |
| 134 | + Runtime.getRuntime().addShutdownHook(new Thread(() -> { |
| 135 | + StringBuilder csvBuilder = new StringBuilder(); |
| 136 | + csvBuilder.append("TestName,TestRun,RunTimeMS,ExecTimeMS\n"); |
| 137 | + |
| 138 | + for (Tuple4<String, Integer, Long, Long> entry : runTimes) { |
| 139 | + csvBuilder.append(entry._1()); |
| 140 | + csvBuilder.append(','); |
| 141 | + csvBuilder.append(entry._2()); |
| 142 | + csvBuilder.append(','); |
| 143 | + csvBuilder.append(entry._3()); |
| 144 | + csvBuilder.append(','); |
| 145 | + csvBuilder.append(entry._4()); |
| 146 | + csvBuilder.append('\n'); |
| 147 | + } |
| 148 | + |
| 149 | + try { |
| 150 | + Files.writeString(Paths.get(BASE_DATA_DIR + "runtimes.csv"), csvBuilder.toString()); |
| 151 | + } catch (IOException e) { |
| 152 | + e.printStackTrace(); |
| 153 | + } |
| 154 | + })); |
| 155 | + } |
112 | 156 | } |
113 | 157 |
|
114 | 158 | private static final Log LOG = LogFactory.getLog(AutomatedTestBase.class.getName()); |
@@ -196,7 +240,6 @@ public String getCodgenConfig() { |
196 | 240 | protected static ExecMode rtplatform = ExecMode.HYBRID; |
197 | 241 |
|
198 | 242 | protected static final boolean DEBUG = false; |
199 | | - protected static final boolean ALLOW_GENERATED_REWRITES = true; |
200 | 243 |
|
201 | 244 | public static boolean VERBOSE_STATS = false; |
202 | 245 |
|
@@ -1397,23 +1440,40 @@ protected ByteArrayOutputStream runTest(boolean newWay, boolean exceptionExpecte |
1397 | 1440 | String errMessage, int maxSparkInst) { |
1398 | 1441 | try{ |
1399 | 1442 | final List<ByteArrayOutputStream> out = new ArrayList<>(); |
1400 | | - Thread t = new Thread( |
1401 | | - () -> out.add(runTestWithTimeout(newWay, exceptionExpected, expectedException, errMessage, maxSparkInst)), |
1402 | | - "TestRunner_main"); |
1403 | | - Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() { |
1404 | | - @Override |
1405 | | - public void uncaughtException(Thread th, Throwable ex) { |
1406 | | - fail("Thread Failed test with message: " +ex.getMessage()); |
1407 | | - } |
1408 | | - }; |
1409 | | - t.setUncaughtExceptionHandler(h); |
1410 | | - t.start(); |
1411 | 1443 |
|
1412 | | - t.join(TEST_TIMEOUT * 1000); |
1413 | | - if(t.isAlive()) |
1414 | | - throw new TimeoutException("Test failed to finish in time"); |
1415 | | - if(out.size() <= 0) // hack in case the test failed return empty string. |
1416 | | - fail("test failed"); |
| 1444 | + if (currentTestName == null || !currentTestName.equals(this.getClass().getSimpleName())) { |
| 1445 | + currentTestRun = 1; |
| 1446 | + currentTestName = this.getClass().getSimpleName(); |
| 1447 | + } else { |
| 1448 | + currentTestRun++; |
| 1449 | + } |
| 1450 | + |
| 1451 | + int totalReps = BENCHMARK_WARMUP_RUNS + BENCHMARK_REPETITIONS; |
| 1452 | + |
| 1453 | + for (int i = 0; i < totalReps; i++) { |
| 1454 | + out.clear(); |
| 1455 | + Statistics.reset(); |
| 1456 | + |
| 1457 | + benchmark_run = BENCHMARK && i >= BENCHMARK_WARMUP_RUNS; |
| 1458 | + |
| 1459 | + Thread t = new Thread( |
| 1460 | + () -> out.add(runTestWithTimeout(newWay, exceptionExpected, expectedException, errMessage, maxSparkInst)), |
| 1461 | + "TestRunner_main"); |
| 1462 | + Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() { |
| 1463 | + @Override |
| 1464 | + public void uncaughtException(Thread th, Throwable ex) { |
| 1465 | + fail("Thread Failed test with message: " + ex.getMessage()); |
| 1466 | + } |
| 1467 | + }; |
| 1468 | + t.setUncaughtExceptionHandler(h); |
| 1469 | + t.start(); |
| 1470 | + |
| 1471 | + t.join(TEST_TIMEOUT * 1000); |
| 1472 | + if (t.isAlive()) |
| 1473 | + throw new TimeoutException("Test failed to finish in time"); |
| 1474 | + if (out.size() <= 0) // hack in case the test failed return empty string. |
| 1475 | + fail("test failed"); |
| 1476 | + } |
1417 | 1477 |
|
1418 | 1478 | return out.get(0); |
1419 | 1479 | } |
|
0 commit comments