incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
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 GMT
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<FrameworkMethod> tests = new LinkedList<FrameworkMethod>();
 	private List<PerformanceSuiteState> suitesState = new ArrayList<PerformanceSuiteState>();
-
+	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



Mime
View raw message