summaryrefslogtreecommitdiff
path: root/test/files/presentation/memory-leaks/MemoryLeaksTest.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/presentation/memory-leaks/MemoryLeaksTest.scala')
-rw-r--r--test/files/presentation/memory-leaks/MemoryLeaksTest.scala40
1 files changed, 20 insertions, 20 deletions
diff --git a/test/files/presentation/memory-leaks/MemoryLeaksTest.scala b/test/files/presentation/memory-leaks/MemoryLeaksTest.scala
index 45b38da85b..6e2c0a6c43 100644
--- a/test/files/presentation/memory-leaks/MemoryLeaksTest.scala
+++ b/test/files/presentation/memory-leaks/MemoryLeaksTest.scala
@@ -7,16 +7,16 @@ import scala.tools.nsc.util._
import scala.tools.nsc.io._
/** This test runs the presentation compiler on the Scala compiler project itself and records memory consumption.
- *
+ *
* The test scenario is to open Typers, Trees and Types, then repeatedly add and remove one character
* in Typers.scala. Each step causes the parser, namer, and type checker to run.
- *
- * At each step we record the memory usage after the GC has run. At the end of the test,
+ *
+ * At each step we record the memory usage after the GC has run. At the end of the test,
* simple linear regression is used to compute the straight line that best fits the
* curve, and if the slope is higher than 1 (meaning a leak of 1MB/run), we fail the test.
- *
+ *
* The Scala compiler sources are assumed to be under 'basedir/src/compiler'.
- *
+ *
* The individual data points are saved under 'usedMem-<date>.txt', under the test project
* directory. Use the cool graph-it.R (https://github.com/scala-ide/scala-ide/blob/master/org.scala-ide.sdt.core.tests/graph-it.R)
* script to see the memory curve for the given test run.
@@ -40,7 +40,7 @@ object Test extends InteractiveTest {
val typesUnit = AbstractFile.getFile(baseDir.parent.parent.parent.parent / "src/compiler/scala/reflect/internal/Types.scala")
val treesUnit = AbstractFile.getFile(baseDir.parent.parent.parent.parent / "src/compiler/scala/reflect/internal/Trees.scala")
- askReload(Seq(new BatchSourceFile(typerUnit), new BatchSourceFile(typesUnit), new BatchSourceFile(treesUnit)))
+ askReload(Seq(new BatchSourceFile(typerUnit), new BatchSourceFile(typesUnit), new BatchSourceFile(treesUnit)))
typeCheckWith(treesUnit, new String(treesUnit.toCharArray))
typeCheckWith(typesUnit, new String(typesUnit.toCharArray))
@@ -58,12 +58,12 @@ object Test extends InteractiveTest {
usedMem / mega // report size in MB
}
-
+
//dumpDataToFile(filename, usedMem)
// drop the first two measurements, since the compiler needs some memory when initializing
val (a, b) = linearModel((3L to N).toSeq, usedMem.drop(2))
//println("LinearModel: constant: %.4f\tslope:%.4f".format(a, b))
-
+
if (b > 1.0)
println("Rate of memory consumption is alarming! %.4f MB/run".format(b))
else
@@ -84,33 +84,33 @@ object Test extends InteractiveTest {
}
outputFile.close()
}
-
-
- /** Return the linear model of these values, (a, b). First value is the constant factor,
+
+
+ /** Return the linear model of these values, (a, b). First value is the constant factor,
* second value is the slope, i.e. `y = a + bx`
- *
- * The linear model of a set of points is a straight line that minimizes the square distance
+ *
+ * The linear model of a set of points is a straight line that minimizes the square distance
* between the each point and the line.
- *
+ *
* See: http://en.wikipedia.org/wiki/Simple_linear_regression
*/
def linearModel(xs: Seq[Long], ys: Seq[Long]): (Double, Double) = {
require(xs.length == ys.length)
-
+
def mean(v: Seq[Long]): Double = v.sum.toDouble / v.length
-
+
val meanXs = mean(xs)
val meanYs = mean(ys)
-
+
val beta = (mean((xs, ys).zipped.map(_ * _)) - meanXs * meanYs) / (mean(xs.map(x => x * x)) - meanXs * meanXs)
val alfa = meanYs - beta * meanXs
-
+
(alfa, beta)
}
/** Run the given closure and return the amount of used memory at the end of its execution.
- *
- * Runs the GC before and after the execution of `f'.
+ *
+ * Runs the GC before and after the execution of `f'.
*/
def withGC(f: => Unit): Long = {
val r = Runtime.getRuntime