summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschinz <schinz@epfl.ch>2005-03-25 15:07:20 +0000
committerschinz <schinz@epfl.ch>2005-03-25 15:07:20 +0000
commit22d6d7b6529d25be5d0586eeb5efc1bd305e3ff7 (patch)
tree87386079764feefa0920f47f90285d39ab8c3dac
parent90b4dc0509d7e789619ec127056fb535865e1196 (diff)
downloadscala-22d6d7b6529d25be5d0586eeb5efc1bd305e3ff7.tar.gz
scala-22d6d7b6529d25be5d0586eeb5efc1bd305e3ff7.tar.bz2
scala-22d6d7b6529d25be5d0586eeb5efc1bd305e3ff7.zip
- use shutdown hooks to output statistics file
-rw-r--r--sources/scala/runtime/types/Statistics.java76
1 files changed, 48 insertions, 28 deletions
diff --git a/sources/scala/runtime/types/Statistics.java b/sources/scala/runtime/types/Statistics.java
index 3ea2005ded..67091cb6e8 100644
--- a/sources/scala/runtime/types/Statistics.java
+++ b/sources/scala/runtime/types/Statistics.java
@@ -39,6 +39,25 @@ public class Statistics {
private static HashMap instances = new HashMap();
+ static {
+ assert addWriteFileHook();
+ }
+
+ public static boolean addWriteFileHook() {
+ Thread writeFileHook = new Thread() {
+ public void run() {
+ try {
+ writeToFile();
+ } catch (Throwable t) {
+ throw new Error(t);
+ }
+ }
+ };
+
+ Runtime.getRuntime().addShutdownHook(writeFileHook);
+ return true;
+ }
+
public static synchronized boolean incInstantiations(boolean unique) {
++instantiationsCount;
if (unique) ++uniqueInstantiationsCount;
@@ -81,35 +100,36 @@ public class Statistics {
*/
public static boolean writeToFile() throws java.io.FileNotFoundException {
String fileName = System.getProperty("scala.runtime.types.statfile");
- if (fileName != null) {
- PrintStream stream =
- new PrintStream(new FileOutputStream(fileName));
- stream.println("(");
- stream.println("(instantiations . "
- + instantiationsCount + ")");
- stream.println("(unique-instantiations . "
- + uniqueInstantiationsCount + ")");
- stream.println("(instance-of . "
- + instanceOfCount + ")");
- stream.println("(type-cast . "
- + typeCastCount + ")");
- if (ancestorSearches > 0) {
- stream.println("(ancestor-searches . "
- + ancestorSearches + ")");
- stream.println("(ancestor-search-iterations . "
- + ancestorSearchIterations + ")");
- }
- stream.println("(instances . (");
- Iterator instIt = instances.entrySet().iterator();
- while (instIt.hasNext()) {
- Map.Entry entry = (Map.Entry)instIt.next();
- stream.println("(\"" + entry.getKey() + "\" . "
- + entry.getValue() + ")");
- }
- stream.print("))");
- stream.println(")");
- stream.close();
+ assert fileName != null;
+
+ System.out.println("Writing RTT statistics to file " + fileName);
+
+ PrintStream stream = new PrintStream(new FileOutputStream(fileName));
+ stream.println("(");
+ stream.println("(instantiations . "
+ + instantiationsCount + ")");
+ stream.println("(unique-instantiations . "
+ + uniqueInstantiationsCount + ")");
+ stream.println("(instance-of . "
+ + instanceOfCount + ")");
+ stream.println("(type-cast . "
+ + typeCastCount + ")");
+ if (ancestorSearches > 0) {
+ stream.println("(ancestor-searches . "
+ + ancestorSearches + ")");
+ stream.println("(ancestor-search-iterations . "
+ + ancestorSearchIterations + ")");
+ }
+ stream.println("(instances . (");
+ Iterator instIt = instances.entrySet().iterator();
+ while (instIt.hasNext()) {
+ Map.Entry entry = (Map.Entry)instIt.next();
+ stream.println("(\"" + entry.getKey() + "\" . "
+ + entry.getValue() + ")");
}
+ stream.print("))");
+ stream.println(")");
+ stream.close();
return true;
}
}