package cz.cuni.mff.d3s.spl.example.newton.checker;

import cz.cuni.mff.d3s.spl.core.data.SerieDataSource;
import cz.cuni.mff.d3s.spl.core.data.instrumentation.InstrumentingDataSource;
import cz.cuni.mff.d3s.spl.core.formula.Formula;
import cz.cuni.mff.d3s.spl.core.formula.Result;
import cz.cuni.mff.d3s.spl.core.formula.SlaFormula;

public class SlaChecker implements Runnable {

	private final static String METHOD = "org.apache.commons.math.analysis.solvers.NewtonSolver#solve";
			//"org.apache.commons.math.analysis.polynomials.PolynomialFunction#value";
	private final static long SEC_TO_NANOS = 1000 * 1000 * 1000;

	SerieDataSource source;
	Formula sla;
	
	public SlaChecker() {
		source = InstrumentingDataSource.create(METHOD);
		sla = SlaFormula.createSimple(source, 1 * SEC_TO_NANOS);
	}

	@Override
	public void run() {
		Result result = sla.evaluate();
		
		System.err.printf("Contract of NewtonSolver.solve(): %s.\n", result);
	}
}

@@ -92,32 +92,81 @@
 erieDataSource;%0A
+import cz.cuni.mff.d3s.spl.core.data.Statistics;%0A
 import cz.cuni.m
@@ -529,86 +529,8 @@
 e%22;%0A
-%09%09%09//%22org.apache.commons.math.analysis.polynomials.PolynomialFunction#value%22;%0A
 %09pri
@@ -832,16 +832,166 @@
 uate();%0A
+%09%09Statistics stats = source.get();%0A%0A%09%09/* Explicitly flush all previous output to prevent interleaving. */%0A%09%09System.out.flush();%0A%09%09System.err.flush();%0A
 %09%09%0A%09%09Sys
@@ -1009,21 +1009,14 @@
 ntf(
-%22Contract of 
+%0A%09%09%09%09%22
 Newt
@@ -1037,14 +1037,98 @@
 (): 
-%25s.%5Cn%22
+mean is %252.1fns, %25d samples: %25s.%5Cn%22,%0A%09%09%09%09stats.getArithmeticMean(), stats.getSampleCount()
 , re

Print more statistics on exit