changeset 386:825888394706

Runner: compress binary results file, make it properly named.
author shade
date Mon, 06 Mar 2017 19:13:00 +0100
parents 6d05ba34c4e9
children edcb47cdb99b
files jcstress-core/src/main/java/org/openjdk/jcstress/Options.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/collectors/DiskReadCollector.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/collectors/DiskWriteCollector.java
diffstat 3 files changed, 36 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/Options.java	Mon Mar 06 18:15:37 2017 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/Options.java	Mon Mar 06 19:13:00 2017 +0100
@@ -36,8 +36,11 @@
 
 import java.io.IOException;
 import java.io.PrintStream;
+import java.text.SimpleDateFormat;
 import java.util.Collection;
+import java.util.Date;
 import java.util.List;
+import java.util.Locale;
 
 /**
  * Options.
@@ -167,7 +170,8 @@
         if (this.parse) {
             this.resultFile = set.valueOf(parse);
         } else {
-            this.resultFile = "jcstress." + System.currentTimeMillis();
+            String timestamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.ROOT).format(new Date());
+            this.resultFile = "jcstress-results-" + timestamp + ".bin.gz";
         }
         this.list = orDefault(set.has(list), false);
         this.verbose = orDefault(set.has("v"), false);
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/collectors/DiskReadCollector.java	Mon Mar 06 18:15:37 2017 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/collectors/DiskReadCollector.java	Mon Mar 06 19:13:00 2017 +0100
@@ -29,6 +29,7 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
+import java.util.zip.GZIPInputStream;
 
 /**
  * Reads test state from the file.
@@ -40,12 +41,14 @@
     private final ObjectInputStream ois;
     private final TestResultCollector collector;
     private final FileInputStream fis;
+    private final GZIPInputStream gis;
 
     public DiskReadCollector(String fileName, TestResultCollector collector) throws IOException {
         this.collector = collector;
         File file = new File(fileName);
         fis = new FileInputStream(file);
-        ois = new ObjectInputStream(fis);
+        gis = new GZIPInputStream(fis);
+        ois = new ObjectInputStream(gis);
     }
 
     public void dump() throws IOException, ClassNotFoundException {
@@ -69,6 +72,12 @@
         }
 
         try {
+            gis.close();
+        } catch (IOException e) {
+            // expected
+        }
+
+        try {
             fis.close();
         } catch (IOException e) {
             // expected
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/collectors/DiskWriteCollector.java	Mon Mar 06 18:15:37 2017 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/collectors/DiskWriteCollector.java	Mon Mar 06 19:13:00 2017 +0100
@@ -26,10 +26,8 @@
 
 import org.openjdk.jcstress.util.Environment;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
+import java.io.*;
+import java.util.zip.GZIPOutputStream;
 
 /**
  * Dumps the test results to the disk.
@@ -39,13 +37,15 @@
 public class DiskWriteCollector implements TestResultCollector {
 
     private final FileOutputStream fos;
+    private final GZIPOutputStream gos;
     private final ObjectOutputStream oos;
     private int frames;
 
     public DiskWriteCollector(String fileName) throws IOException {
         File file = new File(fileName);
         fos = new FileOutputStream(file);
-        oos = new ObjectOutputStream(fos);
+        gos = new GZIPOutputStream(fos);
+        oos = new ObjectOutputStream(gos);
     }
 
     @Override
@@ -62,6 +62,7 @@
 
                 oos.writeObject(result);
                 oos.flush();
+                gos.flush();
                 fos.flush();
             } catch (IOException e) {
                 // expect
@@ -71,23 +72,23 @@
 
     public void close() {
         synchronized (this) {
-            try {
-                oos.flush();
-            } catch (IOException e) {
-                // expect
-            }
+            flushAndClose(oos);
+            flushAndClose(gos);
+            flushAndClose(fos);
+        }
+    }
 
-            try {
-                oos.close();
-            } catch (IOException e) {
-                // expect
-            }
+    private static void flushAndClose(OutputStream stream) {
+        try {
+            stream.flush();
+        } catch (IOException e) {
+            // expect
+        }
 
-            try {
-                fos.flush();
-            } catch (IOException e) {
-                // expect
-            }
+        try {
+            stream.close();
+        } catch (IOException e) {
+            // expect
         }
     }
 }