Search in sources :

Example 11 with DescriptiveStatistics

use of org.apache.commons.math.stat.descriptive.DescriptiveStatistics in project ACS by ACS-Community.

the class ManagerStdoutParserTest method testParseManagerOutput.

@Test
public void testParseManagerOutput() throws Exception, ParseException {
    String fileName = "sampleOutput/acsManager_2012-03-20_16.48.20.642";
    ManagerStdoutParser parser = new ManagerStdoutParser(logger);
    List<ComponentRequest> requests = parser.parse(new File(fileName));
    // to select only logs between these two timestamps
    long t0 = IsoDateFormat.parseIsoTimestamp("2011-11-13T20:47:17.328").getTime();
    long t1 = IsoDateFormat.parseIsoTimestamp("2011-11-13T21:29:48.314").getTime();
    List<TimeValue<ComponentRequest>> data = new ArrayList<TimeValue<ComponentRequest>>();
    for (ComponentRequest r : requests) {
        //			if (r.timeRequested >= t0 && r.timeRequested <= t1) {
        data.add(new TimeValue<ComponentRequest>(r.timeRequested, r));
        System.out.println(toISO(r.timeRequested) + ", " + (r.timeProvided - r.timeRequested) + ", " + r.key.curl.substring(8) + ", " + r.key.clientName);
    //			}
    }
    Collections.sort(data);
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);
    int binIntervalSec = 5;
    DataBinner binner = new DataBinner();
    List<BinnedTimeValues<ComponentRequest>> binned = binner.binTimedData(data, binIntervalSec * 1000);
    //		System.out.println("Time interval\t#Requests by 'Python Client'/" + binIntervalSec + 
    //				"s\t#Requests by other clients/" + binIntervalSec + "s" + "\t" + "Average response time/ms");
    System.out.println("Time interval\t#Requests/" + binIntervalSec + "s interval\tAverage response time/ms");
    for (BinnedTimeValues<ComponentRequest> binnedTimeValues : binned) {
        long timeCurrentBin = binnedTimeValues.timeMillis;
        List<TimeValue<ComponentRequest>> valuesCurrentBin = binnedTimeValues.binnedData;
        int numCallsPythonClient = 0;
        int numCallsOtherClients = 0;
        DescriptiveStatistics callTimeStats = new DescriptiveStatistics();
        for (TimeValue<ComponentRequest> timeValue : valuesCurrentBin) {
            ComponentRequest r = timeValue.value;
            if (r.key.clientName.equals("Python Client")) {
                numCallsPythonClient++;
            } else {
                numCallsOtherClients++;
            }
            // duration in ms
            callTimeStats.addValue(r.timeProvided - r.timeRequested);
        }
        System.out.println(toISO(timeCurrentBin) + "\t" + (numCallsPythonClient + numCallsOtherClients) + "\t" + df.format(callTimeStats.getMean()));
    }
}
Also used : DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) DataBinner(alma.acs.algorithms.DataBinner) ComponentRequest(alma.acs.manager.logparser.ManagerStdoutParser.ComponentRequest) BinnedTimeValues(alma.acs.algorithms.DataBinner.BinnedTimeValues) File(java.io.File) TimeValue(alma.acs.algorithms.DataBinner.TimeValue) Test(org.junit.Test)

Example 12 with DescriptiveStatistics

use of org.apache.commons.math.stat.descriptive.DescriptiveStatistics in project sling by apache.

the class FrameworkPerformanceMethod method invokeExplosively.

@Override
public Object invokeExplosively(Object target, Object... params) throws Throwable {
    // and run the BeforeSuite methods
    if ((performanceSuiteState != null) && (performanceSuiteState.getBeforeSuiteMethod() != null) && (performanceSuiteState.getTargetObjectSuite() != null) && (performanceSuiteState.getNumberOfExecutedMethods() == 0) && !performanceSuiteState.testSuiteName.equals(ParameterizedTestList.TEST_CASE_ONLY)) {
        performanceSuiteState.getBeforeSuiteMethod().invoke(performanceSuiteState.getTargetObjectSuite());
    }
    // as JUnit will run the methods itself
    if ((performanceSuiteState != null) && !performanceSuiteState.testSuiteName.equals(ParameterizedTestList.TEST_CASE_ONLY)) {
        recursiveCallSpecificMethod(this.target.getClass(), this.target, Before.class);
    }
    // Need to count the number of tests run from the PerformanceSuite
    // so that we can call the AfterSuite method after the last test from
    // the suite
    // has run and the AfterSuite needs to run
    performanceSuiteState.incrementNumberOfExecutedTestMethods();
    Object response = null;
    Method testMethodToInvoke = this.getMethod();
    PerformanceTest performanceAnnotation = testMethodToInvoke.getAnnotation(PerformanceTest.class);
    // retrieve the test configuration options
    int warmuptime = performanceAnnotation.warmuptime();
    int runtime = performanceAnnotation.runtime();
    int warmupinvocations = performanceAnnotation.warmupinvocations();
    int runinvocations = performanceAnnotation.runinvocations();
    double threshold = performanceAnnotation.threshold();
    DescriptiveStatistics statistics = new DescriptiveStatistics();
    if (warmupinvocations != 0) {
        // for warming up the system
        for (int invocationIndex = 0; invocationIndex < warmupinvocations; invocationIndex++) {
            recursiveCallSpecificMethod(this.target.getClass(), this.target, BeforeMethodInvocation.class);
            // TODO: implement the method to run a before a specific test
            // method
            // recursiveCallSpecificMethod(this.target.getClass(),
            // this.target, BeforeSpecificTest.class);
            response = super.invokeExplosively(this.target, params);
            // TODO: implement the method to run a after a specific test
            // method
            // recursiveCallSpecificMethod(this.target.getClass(),
            // this.target, AfterSpecificTest.class);
            recursiveCallSpecificMethod(this.target.getClass(), this.target, AfterMethodInvocation.class);
        }
    } else {
        // Run a few iterations to warm up the system
        long warmupEnd = System.currentTimeMillis() + warmuptime * 1000;
        while (System.currentTimeMillis() < warmupEnd) {
            recursiveCallSpecificMethod(this.target.getClass(), this.target, BeforeMethodInvocation.class);
            // TODO: implement the method to run a before a specific test
            // method
            // recursiveCallSpecificMethod(this.target.getClass(),
            // this.target, BeforeSpecificTest.class);
            response = super.invokeExplosively(this.target, params);
            // recursiveCallSpecificMethod(this.target.getClass(),
            // this.target, AfterSpecificTest.class);
            // TODO: implement the method to run a after a specific test
            // method
            recursiveCallSpecificMethod(this.target.getClass(), this.target, AfterMethodInvocation.class);
        }
    }
    // testMethodToInvoke.getName());
    if (runinvocations != 0) {
        // times
        for (int invocationIndex = 0; invocationIndex < runinvocations; invocationIndex++) {
            response = this.invokeTimedTestMethod(testMethodToInvoke, statistics, params);
        }
    } else {
        // Run test iterations and capture the execution times
        long runtimeEnd = System.currentTimeMillis() + runtime * 1000;
        while (System.currentTimeMillis() < runtimeEnd) {
            response = this.invokeTimedTestMethod(testMethodToInvoke, statistics, params);
        }
    }
    if (statistics.getN() > 0) {
        if (referenceMethod == null) {
            ReportLogger.writeReport(this.performanceSuiteState.testSuiteName, testCaseName, className, getMethod().getName(), statistics, ReportLogger.ReportType.TXT, reportLevel);
        } else {
            ReportLogger reportLogger = ReportLogger.getOrCreate(this.performanceSuiteState.testSuiteName, testCaseName, getMethod().getDeclaringClass().getName(), referenceMethod);
            reportLogger.recordStatistics(getMethod().getName(), statistics, threshold);
        }
    }
    // just skip this as JUnit will run the methods itself
    if ((performanceSuiteState != null) && !performanceSuiteState.testSuiteName.equals(ParameterizedTestList.TEST_CASE_ONLY)) {
        recursiveCallSpecificMethod(this.target.getClass(), this.target, After.class);
    }
    // and run the AfterSuite method
    if ((performanceSuiteState != null) && (performanceSuiteState.getAfterSuiteMethod() != null) && (performanceSuiteState.getTargetObjectSuite() != null) && (performanceSuiteState.getNumberOfExecutedMethods() == performanceSuiteState.getNumberOfMethodsInSuite()) && !performanceSuiteState.testSuiteName.equals(ParameterizedTestList.TEST_CASE_ONLY)) {
        performanceSuiteState.getAfterSuiteMethod().invoke(performanceSuiteState.getTargetObjectSuite());
    }
    return response;
}
Also used : DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Method(java.lang.reflect.Method) PerformanceTest(org.apache.sling.performance.annotation.PerformanceTest)

Example 13 with DescriptiveStatistics

use of org.apache.commons.math.stat.descriptive.DescriptiveStatistics in project sling by apache.

the class ReportLogger method checkThresholds.

/**
     * Test if any of the <link>PerformanceRecord</link> exceeds their threshold against the reference
     *
     * @return
     */
public List<Failure> checkThresholds() throws ClassNotFoundException {
    PerformanceRecord referenceRecord = records.get(referenceMethod);
    if (referenceRecord == null) {
        return Collections.EMPTY_LIST;
    }
    DescriptiveStatistics referenceStatistics = referenceRecord.getStatistics();
    List<Failure> failures = new ArrayList<Failure>();
    for (String methodName : records.keySet()) {
        PerformanceRecord performanceRecord = records.get(methodName);
        String result = performanceRecord.checkThreshold(referenceStatistics);
        if (result != null) {
            failures.add(new Failure(Description.createTestDescription(Class.forName(className), methodName), new Exception(result)));
        }
    }
    return failures;
}
Also used : DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics) ArrayList(java.util.ArrayList) Failure(org.junit.runner.notification.Failure) IOException(java.io.IOException)

Example 14 with DescriptiveStatistics

use of org.apache.commons.math.stat.descriptive.DescriptiveStatistics in project beast-mcmc by beast-dev.

the class OneOverStDevPeriodPriorDistribution method calculateLogLikelihood.

public double calculateLogLikelihood(double[] values) {
    DescriptiveStatistics stats = new DescriptiveStatistics(values);
    logL = -Math.log(stats.getStandardDeviation());
    return logL;
}
Also used : DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics)

Aggregations

DescriptiveStatistics (org.apache.commons.math.stat.descriptive.DescriptiveStatistics)14 ArrayList (java.util.ArrayList)5 File (java.io.File)4 TimeValue (alma.acs.algorithms.DataBinner.TimeValue)3 DataBinner (alma.acs.algorithms.DataBinner)2 BinnedTimeValues (alma.acs.algorithms.DataBinner.BinnedTimeValues)2 PrintStream (java.io.PrintStream)2 List (java.util.List)2 ComponentRequest (alma.acs.manager.logparser.ManagerStdoutParser.ComponentRequest)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 GenericResponse (com.linkedin.thirdeye.dashboard.views.GenericResponse)1 ByteBuf (io.netty.buffer.ByteBuf)1 BufferedReader (java.io.BufferedReader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1