Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 763F1D58A for ; Mon, 15 Oct 2012 07:36:05 +0000 (UTC) Received: (qmail 89054 invoked by uid 500); 15 Oct 2012 07:36:04 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 88866 invoked by uid 500); 15 Oct 2012 07:35:59 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 88838 invoked by uid 99); 15 Oct 2012 07:35:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Oct 2012 07:35:58 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Oct 2012 07:35:54 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4E1B623888E4; Mon, 15 Oct 2012 07:34:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1398205 - in /sling/trunk/performance/base/src/main/java/org/apache/sling/performance: FrameworkPerformanceMethod.java PerformanceRunner.java ReportLogger.java Date: Mon, 15 Oct 2012 07:34:46 -0000 To: commits@sling.apache.org From: asanso@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121015073446.4E1B623888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: asanso Date: Mon Oct 15 07:34:45 2012 New Revision: 1398205 URL: http://svn.apache.org/viewvc?rev=1398205&view=rev Log: SLING-2593 - Improvement for the Sling performance tools. Adding Report level parameter. Thanks Christian Vazzolla for the patch. Modified: sling/trunk/performance/base/src/main/java/org/apache/sling/performance/FrameworkPerformanceMethod.java sling/trunk/performance/base/src/main/java/org/apache/sling/performance/PerformanceRunner.java sling/trunk/performance/base/src/main/java/org/apache/sling/performance/ReportLogger.java Modified: sling/trunk/performance/base/src/main/java/org/apache/sling/performance/FrameworkPerformanceMethod.java URL: http://svn.apache.org/viewvc/sling/trunk/performance/base/src/main/java/org/apache/sling/performance/FrameworkPerformanceMethod.java?rev=1398205&r1=1398204&r2=1398205&view=diff ============================================================================== --- sling/trunk/performance/base/src/main/java/org/apache/sling/performance/FrameworkPerformanceMethod.java (original) +++ sling/trunk/performance/base/src/main/java/org/apache/sling/performance/FrameworkPerformanceMethod.java Mon Oct 15 07:34:45 2012 @@ -37,13 +37,14 @@ class FrameworkPerformanceMethod extends private Object target; private PerformanceSuiteState performanceSuiteState; + private PerformanceRunner.ReportLevel reportLevel = PerformanceRunner.ReportLevel.ClassLevel; public FrameworkPerformanceMethod(Method method, Object target, - PerformanceSuiteState performanceSuiteState) { + PerformanceSuiteState performanceSuiteState, PerformanceRunner.ReportLevel reportLevel) { super(method); this.target = target; this.performanceSuiteState = performanceSuiteState; - + this.reportLevel = reportLevel; } @Override @@ -176,7 +177,7 @@ class FrameworkPerformanceMethod extends .writeReport(this.target.getClass().getName(), this.performanceSuiteState.testSuiteName, getMethod().getName(), statistics, - ReportLogger.ReportType.TXT); + ReportLogger.ReportType.TXT, reportLevel); } // In case of a PerformanceSuite we need to run the methods annotated Modified: sling/trunk/performance/base/src/main/java/org/apache/sling/performance/PerformanceRunner.java URL: http://svn.apache.org/viewvc/sling/trunk/performance/base/src/main/java/org/apache/sling/performance/PerformanceRunner.java?rev=1398205&r1=1398204&r2=1398205&view=diff ============================================================================== --- sling/trunk/performance/base/src/main/java/org/apache/sling/performance/PerformanceRunner.java (original) +++ sling/trunk/performance/base/src/main/java/org/apache/sling/performance/PerformanceRunner.java Mon Oct 15 07:34:45 2012 @@ -17,6 +17,10 @@ package org.apache.sling.performance; import java.lang.annotation.Annotation; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; @@ -37,12 +41,34 @@ import org.junit.runners.model.Initializ * The custom JUnit runner that collects the performance tests * */ + + + public class PerformanceRunner extends BlockJUnit4ClassRunner { protected LinkedList tests = new LinkedList(); private List suitesState = new ArrayList(); - + public ReportLevel reportLevel = ReportLevel.ClassLevel; + + public static enum ReportLevel{ + ClassLevel, + MethodLevel + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + public @interface Parameters { + public ReportLevel reportLevel() default ReportLevel.ClassLevel; + } + public PerformanceRunner(Class clazz) throws InitializationError { super(clazz); + + // set the report level for the tests that are run with the PerformanceRunner + // by default set to class level for legacy tests compatibility + if (clazz.getAnnotation(Parameters.class) != null){ + reportLevel = clazz.getAnnotation(Parameters.class).reportLevel(); + } + try { computeTests(); } catch (Exception e) { @@ -159,7 +185,7 @@ public class PerformanceRunner extends B for (Method method : testMethods) { FrameworkPerformanceMethod performaceTestMethod = new FrameworkPerformanceMethod( - method, testObject, current); + method, testObject, current, reportLevel); tests.add(performaceTestMethod); } } @@ -174,7 +200,7 @@ public class PerformanceRunner extends B PerformanceTest.class)) { Object targetObject = getTestClass().getJavaClass().newInstance(); FrameworkPerformanceMethod performaceTestMethod = new FrameworkPerformanceMethod( - method.getMethod(), targetObject, current); + method.getMethod(), targetObject, current, reportLevel); tests.add(performaceTestMethod); } Modified: sling/trunk/performance/base/src/main/java/org/apache/sling/performance/ReportLogger.java URL: http://svn.apache.org/viewvc/sling/trunk/performance/base/src/main/java/org/apache/sling/performance/ReportLogger.java?rev=1398205&r1=1398204&r2=1398205&view=diff ============================================================================== --- sling/trunk/performance/base/src/main/java/org/apache/sling/performance/ReportLogger.java (original) +++ sling/trunk/performance/base/src/main/java/org/apache/sling/performance/ReportLogger.java Mon Oct 15 07:34:45 2012 @@ -17,11 +17,11 @@ public class ReportLogger { } public static void writeReport(String test, String testSuiteName, - String name, DescriptiveStatistics statistics, ReportType reportType) + String name, DescriptiveStatistics statistics, ReportType reportType, PerformanceRunner.ReportLevel reportlevel) throws Exception { switch (reportType) { case TXT: - writeReportTxt(test, testSuiteName, name, statistics); + writeReportTxt(test, testSuiteName, name, statistics, reportlevel); break; default: throw new Exception( @@ -40,19 +40,18 @@ public class ReportLogger { * the statistics data to be written * @throws IOException */ - public static void writeReportTxt(String test, String testSuiteName, - String name, DescriptiveStatistics statistics) throws IOException { + public static void writeReportTxt(String test, String testSuiteName, String name, DescriptiveStatistics statistics, PerformanceRunner.ReportLevel reportlevel) + throws Exception{ String className = test; className = className.substring(className.lastIndexOf(".") + 1); File reportDir = new File("target/performance-reports"); if (!reportDir.exists()) { - boolean test1 = reportDir.mkdir(); + if (!reportDir.mkdir()) + throw new IOException("Unable to create performance-reports directory"); } - File report = new File("target/performance-reports", className + ".txt"); - // need this in the case a user wants to set the suite name from the // command line // useful if we run the test cases from the command line for example @@ -63,25 +62,93 @@ public class ReportLogger { } } - boolean needsPrefix = !report.exists(); - PrintWriter writer = new PrintWriter(new FileWriterWithEncoding(report, - "UTF-8", true)); - try { - if (needsPrefix) { - writer.format( - "# %-34.34s min 10%% 50%% 90%% max%n", - className); + String resultFileName = className; + if (reportlevel.equals(PerformanceRunner.ReportLevel.ClassLevel)){ + writeReportClassLevel(resultFileName, testSuiteName, statistics); + }else if (reportlevel.equals(PerformanceRunner.ReportLevel.MethodLevel)){ + resultFileName = test + "." + name; + writeReportMethodLevel(resultFileName, testSuiteName, statistics); } - - writer.format("%-36.36s %6.0f %6.0f %6.0f %6.0f %6.0f%n", - testSuiteName, statistics.getMin(), - statistics.getPercentile(10.0), - statistics.getPercentile(50.0), - statistics.getPercentile(90.0), statistics.getMax()); - } finally { - writer.close(); - } } + + /** + * Write report for class level tests + * @param resultFileName the name of the result file (without extension) + * @param testSuiteName the name of the test suite name + * @param statistics the statistics object used to compute different medians + * @throws IOException + */ + private static void writeReportClassLevel(String resultFileName, String testSuiteName, DescriptiveStatistics statistics) + throws IOException{ + + File report = new File("target/performance-reports", resultFileName + ".txt"); + boolean needsPrefix = !report.exists(); + PrintWriter writer = new PrintWriter( + new FileWriterWithEncoding(report, "UTF-8", true)); + try { + if (needsPrefix) { + writer.format( + "# %-34.34s min 10%% 50%% 90%% max%n", + resultFileName); + } + + writer.format( + "%-36.36s %6.0f %6.0f %6.0f %6.0f %6.0f%n", + testSuiteName, + statistics.getMin(), + statistics.getPercentile(10.0), + statistics.getPercentile(50.0), + statistics.getPercentile(90.0), + statistics.getMax()); + } finally { + writer.close(); + } + } + + /** + * Write report for method level tests + * @param resultFileName the name of the result file (without extension) + * @param testSuiteName the name of the test suite name + * @param statistics the statistics object used to compute different medians + * @throws IOException + */ + private static void writeReportMethodLevel(String resultFileName, String testSuiteName, DescriptiveStatistics statistics) + throws IOException{ + File report = new File("target/performance-reports", resultFileName + ".txt"); + + String className = resultFileName.substring(0, resultFileName.lastIndexOf(".")); + String methodName = resultFileName.substring(resultFileName.lastIndexOf(".") + 1); + + boolean needsPrefix = !report.exists(); + PrintWriter writer = new PrintWriter( + new FileWriterWithEncoding(report, "UTF-8", true)); + try { + if (needsPrefix) { + writer.format( + "%-40.40s|%-80.80s|%-40.40s| DateTime | min | 10%% | 50%% | 90%% | max%n", + "Test Suite", + "Test Class", + "Test Method"); + } + + writer.format( + "%-40.40s|%-80.80s|%-40.40s|%-20.20s|%7.0f|%9.0f|%9.0f|%9.0f|%9.0f%n", + testSuiteName, + className, + methodName, + getDate(), + statistics.getMin(), + statistics.getPercentile(10.0), + statistics.getPercentile(50.0), + statistics.getPercentile(90.0), + statistics.getMax()); + } finally { + writer.close(); + } + } + + + /** * Get the date that will be written into the result file