Title: [40672] trunk/hudson/plugins/serenity: Ongoing development on the profiler.

Diff

Modified: trunk/hudson/plugins/serenity/.project (40671 => 40672)


--- trunk/hudson/plugins/serenity/.project	2012-07-18 10:53:48 UTC (rev 40671)
+++ trunk/hudson/plugins/serenity/.project	2012-07-18 13:41:35 UTC (rev 40672)
@@ -15,15 +15,9 @@
 			<arguments>
 			</arguments>
 		</buildCommand>
-		<buildCommand>
-			<name>com.instantiations.assist.eclipse.coverage.instrumentationBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>org.maven.ide.eclipse.maven2Nature</nature>
 		<nature>org.eclipse.jdt.core.javanature</nature>
-		<nature>com.instantiations.assist.eclipse.coverage.codeCoverageNature</nature>
 	</natures>
 </projectDescription>

Modified: trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/Configuration.java (40671 => 40672)


--- trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/Configuration.java	2012-07-18 10:53:48 UTC (rev 40671)
+++ trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/Configuration.java	2012-07-18 13:41:35 UTC (rev 40672)
@@ -159,6 +159,14 @@
 		}
 		return -1;
 	}
+	
+	public double getTimeUnitDenominator() {
+		String timeUnit = System.getProperty(IConstants.TIME_UNIT);
+		if (timeUnit != null && Toolkit.isDigits(timeUnit)) {
+			return Long.parseLong(timeUnit);
+		}
+		return 1000;
+	}
 
 	private void addIncludedPackages() {
 		String packageNames = System.getProperty(IConstants.INCLUDED_PACKAGES_PROPERTY);

Modified: trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/IConstants.java (40671 => 40672)


--- trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/IConstants.java	2012-07-18 10:53:48 UTC (rev 40671)
+++ trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/IConstants.java	2012-07-18 13:41:35 UTC (rev 40672)
@@ -58,6 +58,8 @@
 	public String SNAPSHOT_INTERVAL = "snapshotInterval";
 	/** The interval between report dumps for the profiler. */
 	public String REPORT_INTERVAL = "reportInterval";
+	/** The time unit to use, default is nano seconds. */
+	public String TIME_UNIT = "timeUnit";
 
 	public String COVERAGE = "coverage";
 	public String COMPLEXITY = "complexity";
@@ -111,17 +113,14 @@
 	public int PORT = 50005;
 
 	public String STYLE_SHEET = "profiler-report-style.css";
-	public String METHOD_SERIES = "methodSeries.html";
-	public String METHOD_NET_SERIES = "methodNetSeries.html";
+	public String METHOD_SERIES = "greatestAverageTimePerMethod.html";
+	public String METHOD_NET_SERIES = "netGreatestAverageTimePerMethod.html";
 	public String METHOD_CHANGE_SERIES = "methodChangeSeries.html";
 	public String METHOD_NET_CHANGE_SERIES = "methodNetChangeSeries.html";
 
 	public String STYLE_SHEET_FILE = SERENITY_DIRECTORY + File.separatorChar + STYLE_SHEET;
 	public String METHOD_SERIES_FILE = SERENITY_DIRECTORY + File.separatorChar + METHOD_SERIES;
-	public String METHOD_NET_SERIES_FILE = SERENITY_DIRECTORY + File.separatorChar + METHOD_NET_SERIES;
-	public String METHOD_CHANGE_SERIES_FILE = SERENITY_DIRECTORY + File.separatorChar + METHOD_CHANGE_SERIES;
-	public String METHOD_NET_CHANGE_SERIES_FILE = SERENITY_DIRECTORY + File.separatorChar + METHOD_NET_CHANGE_SERIES;
-
+	
 	public String CHARTS = "charts";
 	public File chartDirectory = new File(SERENITY_DIRECTORY + File.separatorChar + CHARTS);
 

Modified: trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/Profiler.java (40671 => 40672)


--- trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/Profiler.java	2012-07-18 10:53:48 UTC (rev 40671)
+++ trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/Profiler.java	2012-07-18 13:41:35 UTC (rev 40672)
@@ -16,7 +16,7 @@
 
 /**
  * This class generates the reports for the profiled classes.
- *
+ * 
  * <pre>
  * Model:
  * Class class
@@ -33,7 +33,7 @@
  *             long wait
  *             Date start
  *             Date end
- *
+ * 
  * Calculations:
  * 1) Calculate the total time for each method - totalMethodTime()
  *     Snapshots {2, 5, 3, 6, 5} = 2 + 5 + 3 + 6 + 5 = 21
@@ -55,7 +55,7 @@
  *     Snapshots {2, 5, 3, 6, 5} = 3
  * 10) Calculate the net change for the methods - methodNetChange()
  *     Snapshot {1, 2, 4, 3, 2} = 1
- *
+ * 
  * Does this make sense?
  * x) Calculate the average total change for the methods - averageMethodChange()
  *     Snapshots {2, 5, 3, 6, 5} = 3, -2, 3, -1 = 3/5 = 0.66
@@ -63,10 +63,10 @@
  * 	    Snapshot {1, 2, 4, 3, 2} = 1, 2, -1, -1  = 1/5 = 0.20
  * xxx) Calculate the average change in total time for each class - averageClassTimeChange()
  * xxxx) Calculate the average change in net time for each class - averageClassNetTimeChange()
- *
+ * 
  * 1) Calculate the total time for each class - totalClassTime()
  * 2) Calculate the total net time for each class - totalNetClassTime()
- *
+ * 
  * 5) Calculate the highest average total change for the classes - highestAverageClassChange()
  * 6) Calculate the highest average net change for the classes - highestAverageNetClassChange()
  * 7) Calculate the highest total change for the classes - highestClassChange()
@@ -75,9 +75,9 @@
  * 10) Calculate the series for the net times for the class - classNetSeries()
  * 11) Calculate the series for the change in total time for the class -
  * 12) Calculate the series for the change in net time for the class
- *
+ * 
  * </pre>
- *
+ * 
  * @author Michael Couck
  * @since 12.06.10
  * @version 01.00
@@ -86,6 +86,8 @@
 
 	protected static Logger LOGGER = Logger.getLogger(Profiler.class);
 
+	private static double TIME_UNIT_DENOMINATOR = 1d;
+
 	public static void initialize(final IDataBase dataBase) {
 		long snapshptInterval = Configuration.getConfiguration().getSnapshotInterval();
 		LOGGER.error("Profiler initialize : " + dataBase + ", " + snapshptInterval);
@@ -121,18 +123,23 @@
 			};
 			timer.schedule(timerTask, snapshptInterval, snapshptInterval);
 		}
+		TIME_UNIT_DENOMINATOR = Configuration.getConfiguration().getTimeUnitDenominator();
 	}
 
+	private static final double getValue(final double value) {
+		return value / TIME_UNIT_DENOMINATOR;
+	}
+
 	/**
 	 * Calculate the series for the total times for the method<br>
 	 * methodSeries()<br>
 	 * Snapshots {2, 5, 3, 6, 5}
 	 */
-	public static List<Long> methodSeries(Method<?, ?> method) {
-		List<Long> series = new ArrayList<Long>();
+	public static List<Double> methodSeries(Method<?, ?> method) {
+		List<Double> series = new ArrayList<Double>();
 		List<Snapshot<?, ?>> snapshots = method.getSnapshots();
 		for (Snapshot<?, ?> snapshot : snapshots) {
-			series.add(snapshot.getTotal());
+			series.add(getValue(snapshot.getTotal()));
 		}
 		return series;
 	}
@@ -142,12 +149,12 @@
 	 * methodNetSeries()<br>
 	 * Snapshot {1, 2, 4, 3, 2}
 	 */
-	public static List<Long> methodNetSeries(Method<?, ?> method) {
-		List<Long> series = new ArrayList<Long>();
+	public static List<Double> methodNetSeries(Method<?, ?> method) {
+		List<Double> series = new ArrayList<Double>();
 		List<Snapshot<?, ?>> snapshots = method.getSnapshots();
 		for (Snapshot<?, ?> snapshot : snapshots) {
-			long netTime = snapshot.getTotal() - snapshot.getWait();
-			snapshot.setNet(netTime);
+			double netTime = snapshot.getTotal() - snapshot.getWait();
+			snapshot.setNet(getValue(netTime));
 			series.add(snapshot.getNet());
 		}
 		return series;
@@ -158,13 +165,13 @@
 	 * totalMethodTime()<br>
 	 * Snapshots {2, 5, 3, 6, 5} = 2 + 5 + 3 + 6 + 5 = 21
 	 */
-	public static long totalMethodTime(Method<?, ?> method) {
-		List<Long> methodSeries = methodSeries(method);
+	public static double totalMethodTime(Method<?, ?> method) {
+		List<Double> methodSeries = methodSeries(method);
 		long totalTime = 0;
-		for (Long time : methodSeries) {
+		for (Double time : methodSeries) {
 			totalTime += time;
 		}
-		return totalTime;
+		return getValue(totalTime);
 	}
 
 	/**
@@ -172,13 +179,13 @@
 	 * totalNetMethodTime()<br>
 	 * Snapshot {1, 2, 4, 3, 2 } = 1 + 2 + 4 + 3 + 2 = 12
 	 */
-	public static long totalNetMethodTime(Method<?, ?> method) {
-		List<Long> methodNetSeries = methodNetSeries(method);
+	public static double totalNetMethodTime(Method<?, ?> method) {
+		List<Double> methodNetSeries = methodNetSeries(method);
 		long totalNetTime = 0;
-		for (Long netTime : methodNetSeries) {
+		for (Double netTime : methodNetSeries) {
 			totalNetTime += netTime;
 		}
-		return totalNetTime;
+		return getValue(totalNetTime);
 	}
 
 	/**
@@ -186,12 +193,12 @@
 	 * methodChangeSeries()<br>
 	 * Snapshots {2, 5, 3, 6, 5} = {3, -2, 3, -1}
 	 */
-	public static List<Long> methodChangeSeries(Method<?, ?> method) {
-		List<Long> series = new ArrayList<Long>();
-		List<Long> methodSeries = methodSeries(method);
-		long previousTime = 0;
-		for (Long time : methodSeries) {
-			long change = time - previousTime;
+	public static List<Double> methodChangeSeries(Method<?, ?> method) {
+		List<Double> series = new ArrayList<Double>();
+		List<Double> methodSeries = methodSeries(method);
+		double previousTime = 0;
+		for (Double time : methodSeries) {
+			double change = getValue(time - previousTime);
 			series.add(change);
 			previousTime = time;
 		}
@@ -203,12 +210,12 @@
 	 * methodNetChangeSeries()<br>
 	 * Snapshot {1, 2, 4, 3, 2} = {1, 2, -1, -1}
 	 */
-	public static List<Long> methodNetChangeSeries(Method<?, ?> method) {
-		List<Long> series = new ArrayList<Long>();
-		List<Long> methodNetSeries = methodNetSeries(method);
-		long previousTime = 0;
-		for (Long time : methodNetSeries) {
-			long change = time - previousTime;
+	public static List<Double> methodNetChangeSeries(Method<?, ?> method) {
+		List<Double> series = new ArrayList<Double>();
+		List<Double> methodNetSeries = methodNetSeries(method);
+		double previousTime = 0;
+		for (Double time : methodNetSeries) {
+			double change = getValue(time - previousTime);
 			series.add(change);
 			previousTime = time;
 		}
@@ -220,11 +227,11 @@
 	 * averageMethodTime()<br>
 	 * Snapshot {2, 5, 3, 6, 5} = (2 + 5 + 3 + 6 + 5)/5 = 21/5 = 4.2
 	 */
-	public static long averageMethodTime(Method<?, ?> method) {
-		List<Long> methodSeries = methodSeries(method);
-		long totalTime = 0;
-		for (Long time : methodSeries) {
-			totalTime += time;
+	public static double averageMethodTime(Method<?, ?> method) {
+		List<Double> methodSeries = methodSeries(method);
+		double totalTime = 0;
+		for (Double time : methodSeries) {
+			totalTime += getValue(time);
 		}
 		long denominator = methodSeries.size() > 0 ? methodSeries.size() : 1;
 		return totalTime / denominator;
@@ -235,11 +242,11 @@
 	 * averageMethodNetTime()<br>
 	 * Snapshot {1, 2, 4, 3, 2} = (1 + 2 + 4 + 3 + 2)/5 = 12/5 = 2.4
 	 */
-	public static long averageMethodNetTime(Method<?, ?> method) {
-		List<Long> methodNetSeries = methodNetSeries(method);
-		long totalTime = 0;
-		for (Long time : methodNetSeries) {
-			totalTime += time;
+	public static double averageMethodNetTime(Method<?, ?> method) {
+		List<Double> methodNetSeries = methodNetSeries(method);
+		double totalTime = 0;
+		for (Double time : methodNetSeries) {
+			totalTime += getValue(time);
 		}
 		long denominator = methodNetSeries.size() > 0 ? methodNetSeries.size() : 1;
 		return totalTime / denominator;
@@ -250,12 +257,12 @@
 	 * methodChange()<br>
 	 * Snapshots {2, 5, 3, 6, 5} = 3
 	 */
-	public static long methodChange(Method<?, ?> method) {
-		List<Long> methodSeries = methodSeries(method);
-		long totalChange = 0;
-		long previousTime = 0;
-		for (Long time : methodSeries) {
-			long change = time - previousTime;
+	public static double methodChange(Method<?, ?> method) {
+		List<Double> methodSeries = methodSeries(method);
+		double totalChange = 0;
+		double previousTime = 0;
+		for (Double time : methodSeries) {
+			double change = getValue(time - previousTime);
 			totalChange += change;
 			previousTime = time;
 		}
@@ -267,12 +274,12 @@
 	 * methodNetChange()<br>
 	 * Snapshot {1, 2, 4, 3, 2} = 1
 	 */
-	public static long methodNetChange(Method<?, ?> method) {
-		List<Long> methodNetSeries = methodNetSeries(method);
-		long totalChange = 0;
-		long previousTime = 0;
-		for (Long time : methodNetSeries) {
-			long change = time - previousTime;
+	public static double methodNetChange(Method<?, ?> method) {
+		List<Double> methodNetSeries = methodNetSeries(method);
+		double totalChange = 0;
+		double previousTime = 0;
+		for (Double time : methodNetSeries) {
+			double change = getValue(time - previousTime);
 			totalChange += change;
 			previousTime = time;
 		}

Modified: trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/model/Snapshot.java (40671 => 40672)


--- trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/model/Snapshot.java	2012-07-18 10:53:48 UTC (rev 40671)
+++ trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/model/Snapshot.java	2012-07-18 13:41:35 UTC (rev 40672)
@@ -5,25 +5,25 @@
 
 public class Snapshot<E, F> extends Composite<Package<?, ?>, Method<?, ?>> implements Comparable<Class<?, ?>>, Serializable {
 
-	private long net;
-	private long total;
-	private long wait;
+	private double net;
+	private double total;
+	private double wait;
 	private Date start;
 	private Date end;
 
-	public long getNet() {
+	public double getNet() {
 		return net;
 	}
 
-	public void setNet(long net) {
+	public void setNet(double net) {
 		this.net = net;
 	}
 
-	public long getTotal() {
+	public double getTotal() {
 		return total;
 	}
 
-	public void setTotal(long total) {
+	public void setTotal(double total) {
 		this.total = total;
 	}
 
@@ -43,11 +43,11 @@
 		this.end = end;
 	}
 
-	public long getWait() {
+	public double getWait() {
 		return wait;
 	}
 
-	public void setWait(long wait) {
+	public void setWait(double wait) {
 		this.wait = wait;
 	}
 

Modified: trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/process/Reporter.java (40671 => 40672)


--- trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/process/Reporter.java	2012-07-18 10:53:48 UTC (rev 40671)
+++ trunk/hudson/plugins/serenity/src/main/java/com/ikokoon/serenity/process/Reporter.java	2012-07-18 13:41:35 UTC (rev 40672)
@@ -10,6 +10,7 @@
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
 
 import org.dom4j.Document;
 import org.dom4j.DocumentHelper;
@@ -37,7 +38,7 @@
 
 /**
  * This class takes a database and produces reports based on the snapshots for each method, for the profiler.
- *
+ * 
  * @author Michael Couck
  * @since 19.06.10
  * @version 01.00
@@ -72,12 +73,6 @@
 
 			String html = methodSeries(dataBase);
 			writeReport(IConstants.METHOD_SERIES_FILE, html);
-			html = methodNetSeries(dataBase);
-			writeReport(IConstants.METHOD_NET_SERIES_FILE, html);
-			html = methodChangeSeries(dataBase);
-			writeReport(IConstants.METHOD_CHANGE_SERIES_FILE, html);
-			html = methodNetChangeSeries(dataBase);
-			writeReport(IConstants.METHOD_NET_CHANGE_SERIES_FILE, html);
 		} catch (Exception e) {
 			logger.error("Exception writing the reports", e);
 		}
@@ -86,11 +81,9 @@
 
 	/**
 	 * Writes the report data to the file system.
-	 *
-	 * @param name
-	 *            the name of the report
-	 * @param html
-	 *            the html to write in the file
+	 * 
+	 * @param name the name of the report
+	 * @param html the html to write in the file
 	 */
 	private void writeReport(String name, String html) {
 		try {
@@ -109,15 +102,15 @@
 	}
 
 	/**
-	 * This method generates the time series for the methods and puts it in an HTML string. The methods are sorted according to the greatest average
-	 * time for each method.
+	 * This method generates the time series for the methods and puts it in an HTML string. The methods are sorted according to the greatest
+	 * average time for each method.
 	 */
-	@SuppressWarnings("unchecked")
+	@SuppressWarnings({ "unchecked", "rawtypes" })
 	protected String methodSeries(final IDataBase dataBase) {
 		Comparator<Method> comparator = new Comparator<Method>() {
 			public int compare(Method o1, Method o2) {
-				Long o1Average = new Long(Profiler.averageMethodTime(o1));
-				Long o2Average = new Long(Profiler.averageMethodTime(o2));
+				Double o1Average = new Double(Profiler.averageMethodTime(o1));
+				Double o2Average = new Double(Profiler.averageMethodTime(o2));
 				// We want a descending table, i.e. the most expensive at the top
 				return o2Average.compareTo(o1Average);
 			}
@@ -134,132 +127,33 @@
 			String className = klass.getName();
 			String methodName = method.getName();
 
-			List<Long> methodSeries = Profiler.methodSeries(method);
-			String url = "" method, methodSeries);
 			Element rowElement = addElement(tableElement, "tr", null);
 			addElement(rowElement, "td", className);
 			addElement(rowElement, "td", methodName);
-			addElement(rowElement, "td", Long.toString(Profiler.totalMethodTime(method)));
-			addElement(rowElement, "td", Long.toString(Profiler.totalNetMethodTime(method)));
-			Element dataElement = addElement(rowElement, "td", null);
-			Element imageElement = addElement(dataElement, "img", null);
-			addAttributes(imageElement, new String[] { "src" }, new String[] { url });
-		}
+			addElement(rowElement, "td", Double.toString(Profiler.averageMethodTime(method)));
+			addElement(rowElement, "td", Double.toString(Profiler.averageMethodNetTime(method)));
+			addElement(rowElement, "td", Double.toString(Profiler.totalMethodTime(method)));
+			addElement(rowElement, "td", Double.toString(Profiler.totalNetMethodTime(method)));
+			addElement(rowElement, "td", Integer.toString(method.getInvocations()));
 
-		Document document = tableElement.getDocument();
-		return prettyPrint(document);
-
-	}
-
-	@SuppressWarnings("unchecked")
-	protected String methodNetSeries(final IDataBase dataBase) {
-		Comparator<Method> comparator = new Comparator<Method>() {
-			public int compare(Method o1, Method o2) {
-				Long o1Average = new Long(Profiler.averageMethodNetTime(o1));
-				Long o2Average = new Long(Profiler.averageMethodNetTime(o2));
-				// We want a descending table, i.e. the most expensive at the top
-				return o2Average.compareTo(o1Average);
-			}
-		};
-		Set<Method> sortedMethods = new TreeSet<Method>(comparator);
-		List<Method> methods = dataBase.find(Method.class);
-		sortedMethods.addAll(methods);
-
-		List<Snapshot<?, ?>> snapshots = methods.size() > 0 ? methods.get(0).getSnapshots() : new ArrayList<Snapshot<?, ?>>();
-		Element tableElement = tableElement(snapshots);
-
-		for (Method method : sortedMethods) {
-			Class<?, ?> klass = (Class<?, ?>) method.getParent();
-			String className = klass.getName();
-			String methodName = method.getName();
-
-			List<Long> methodSeries = Profiler.methodNetSeries(method);
-			String url = "" method, methodSeries);
-			Element rowElement = addElement(tableElement, "tr", null);
-			addElement(rowElement, "td", className);
-			addElement(rowElement, "td", methodName);
-			addElement(rowElement, "td", Long.toString(Profiler.totalMethodTime(method)));
-			addElement(rowElement, "td", Long.toString(Profiler.totalNetMethodTime(method)));
 			Element dataElement = addElement(rowElement, "td", null);
 			Element imageElement = addElement(dataElement, "img", null);
+			// Add the method series graph for the average and total time for the method
+			List<Double> methodSeries = Profiler.methodSeries(method);
+			String url = "" method, methodSeries);
 			addAttributes(imageElement, new String[] { "src" }, new String[] { url });
-		}
 
-		Document document = tableElement.getDocument();
-		return prettyPrint(document);
-	}
-
-	@SuppressWarnings("unchecked")
-	protected String methodChangeSeries(final IDataBase dataBase) {
-		Comparator<Method> comparator = new Comparator<Method>() {
-			public int compare(Method o1, Method o2) {
-				Long o1Average = new Long(Profiler.averageMethodTime(o1));
-				Long o2Average = new Long(Profiler.averageMethodTime(o2));
-				return o2Average.compareTo(o1Average);
-			}
-		};
-		Set<Method> sortedMethods = new TreeSet<Method>(comparator);
-		List<Method> methods = dataBase.find(Method.class);
-		sortedMethods.addAll(methods);
-
-		List<Snapshot<?, ?>> snapshots = methods.size() > 0 ? methods.get(0).getSnapshots() : new ArrayList<Snapshot<?, ?>>();
-		Element tableElement = tableElement(snapshots);
-
-		for (Method method : sortedMethods) {
-			Class<?, ?> klass = (Class<?, ?>) method.getParent();
-			String className = klass.getName();
-			String methodName = method.getName();
-
-			List<Long> methodSeries = Profiler.methodChangeSeries(method);
-			String url = "" method, methodSeries);
-			Element rowElement = addElement(tableElement, "tr", null);
-			addElement(rowElement, "td", className);
-			addElement(rowElement, "td", methodName);
-			addElement(rowElement, "td", Long.toString(Profiler.averageMethodTime(method)));
-			addElement(rowElement, "td", Long.toString(Profiler.averageMethodNetTime(method)));
-			Element dataElement = addElement(rowElement, "td", null);
-			Element imageElement = addElement(dataElement, "img", null);
+			dataElement = addElement(rowElement, "td", null);
+			imageElement = addElement(dataElement, "img", null);
+			// Add the method change graph, i.e. the change in the average time for the method
+			List<Double> methodChangeSeries = Profiler.methodChangeSeries(method);
+			url = "" method, methodChangeSeries);
 			addAttributes(imageElement, new String[] { "src" }, new String[] { url });
 		}
 
 		Document document = tableElement.getDocument();
 		return prettyPrint(document);
-	}
 
-	@SuppressWarnings("unchecked")
-	protected String methodNetChangeSeries(final IDataBase dataBase) {
-		Comparator<Method> comparator = new Comparator<Method>() {
-			public int compare(Method o1, Method o2) {
-				Long o1Average = new Long(Profiler.averageMethodTime(o1));
-				Long o2Average = new Long(Profiler.averageMethodTime(o2));
-				return o2Average.compareTo(o1Average);
-			}
-		};
-		Set<Method> sortedMethods = new TreeSet<Method>(comparator);
-		List<Method> methods = dataBase.find(Method.class);
-		sortedMethods.addAll(methods);
-
-		List<Snapshot<?, ?>> snapshots = methods.size() > 0 ? methods.get(0).getSnapshots() : new ArrayList<Snapshot<?, ?>>();
-		Element tableElement = tableElement(snapshots);
-
-		for (Method method : sortedMethods) {
-			Class<?, ?> klass = (Class<?, ?>) method.getParent();
-			String className = klass.getName();
-			String methodName = method.getName();
-			List<Long> methodSeries = Profiler.methodNetChangeSeries(method);
-			String url = "" method, methodSeries);
-			Element rowElement = addElement(tableElement, "tr", null);
-			addElement(rowElement, "td", className);
-			addElement(rowElement, "td", methodName);
-			addElement(rowElement, "td", Long.toString(Profiler.averageMethodTime(method)));
-			addElement(rowElement, "td", Long.toString(Profiler.averageMethodNetTime(method)));
-			Element dataElement = addElement(rowElement, "td", null);
-			Element imageElement = addElement(dataElement, "img", null);
-			addAttributes(imageElement, new String[] { "src" }, new String[] { url });
-		}
-
-		Document document = tableElement.getDocument();
-		return prettyPrint(document);
 	}
 
 	private Element tableElement(List<Snapshot<?, ?>> snapshots) {
@@ -267,8 +161,8 @@
 		Element htmlElement = document.addElement("html");
 		Element headElement = addElement(htmlElement, "head", null);
 		Element linkElement = addElement(headElement, "link", null);
-		addAttributes(linkElement, new String[] { "href", "rel", "type", "media" }, new String[] { IConstants.STYLE_SHEET, "stylesheet", "text/css",
-				"screen" });
+		addAttributes(linkElement, new String[] { "href", "rel", "type", "media" }, new String[] { IConstants.STYLE_SHEET, "stylesheet",
+				"text/css", "screen" });
 
 		Element bodyElement = addElement(linkElement, "body", null);
 		Element tableElement = addElement(bodyElement, "table", null);
@@ -297,14 +191,18 @@
 			periods = builder.toString();
 		}
 		Element headerElement = addElement(headerRowElement, "th", "Period from : " + periods);
-		addAttributes(headerElement, new String[] { "colspan" }, new String[] { "5" });
+		addAttributes(headerElement, new String[] { "colspan" }, new String[] { "9" });
 
 		Element rowElement = addElement(tableElement, "tr", null);
 		addElement(rowElement, "th", "Class");
 		addElement(rowElement, "th", "Method");
 		addElement(rowElement, "th", "Time");
 		addElement(rowElement, "th", "Net time");
+		addElement(rowElement, "th", "Delta time");
+		addElement(rowElement, "th", "Net delta time");
+		addElement(rowElement, "th", "Invocations");
 		addElement(rowElement, "th", "Graph");
+		addElement(rowElement, "th", "Delta draph");
 		return tableElement;
 	}
 
@@ -325,11 +223,6 @@
 	private String prettyPrint(Document document) {
 		try {
 			OutputFormat format = OutputFormat.createPrettyPrint();
-
-			// XMLWriter writer = new XMLWriter(System.out, format);
-			// writer.write(document);
-			// format = OutputFormat.createCompactFormat();
-
 			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
 			XMLWriter writer = new XMLWriter(byteArrayOutputStream, format);
 			writer.write(document);
@@ -340,19 +233,19 @@
 		return document.asXML();
 	}
 
-	@SuppressWarnings("unchecked")
-	protected String buildGraph(String seriesDirectory, Method method, List<Long> datas) {
+	protected String buildGraph(String seriesDirectory, Method<?, ?> method, List<Double> datas) {
 		XYSeries series = new XYSeries("XYGraph", false, false);
 
 		double snapshot = 0;
-		for (Long data : datas) {
-			double seconds = nanosToSeconds(data);
+		for (Double data : datas) {
+			double seconds = TimeUnit.NANOSECONDS.toSeconds(data.intValue());
 			series.add(snapshot++, seconds);
 		}
 
 		XYSeriesCollection seriesCollection = new XYSeriesCollection();
 		seriesCollection.addSeries(series);
-		JFreeChart chart = ChartFactory.createXYLineChart(null, "Snapshots", "Time", seriesCollection, PlotOrientation.VERTICAL, false, false, false);
+		JFreeChart chart = ChartFactory.createXYLineChart(null, "Snapshots", "Time", seriesCollection, PlotOrientation.VERTICAL, false,
+				false, false);
 		chart.setTitle(new TextTitle(method.getName(), new Font("Arial", Font.BOLD, 11)));
 
 		XYPlot xyPlot = chart.getXYPlot();
@@ -398,37 +291,4 @@
 		return null;
 	}
 
-	@SuppressWarnings("unused")
-	private double nanosToMillis(Long nanos) {
-		double millis = nanos / 1000000d;
-		return millis;
-	}
-
-	private double nanosToSeconds(Long nanos) {
-		double seconds = nanos / 1000000000d;
-		return seconds;
-	}
-
-	@SuppressWarnings("unused")
-	private long min(List<Long> datas) {
-		long min = 0;
-		for (Long data : datas) {
-			if (data < min) {
-				min = data;
-			}
-		}
-		return min;
-	}
-
-	@SuppressWarnings("unused")
-	private long max(List<Long> datas) {
-		long max = 0;
-		for (Long data : datas) {
-			if (data > max) {
-				max = data;
-			}
-		}
-		return max;
-	}
-
-}
+}
\ No newline at end of file

Modified: trunk/hudson/plugins/serenity/src/test/java/com/ikokoon/serenity/ProfilerTest.java (40671 => 40672)


--- trunk/hudson/plugins/serenity/src/test/java/com/ikokoon/serenity/ProfilerTest.java	2012-07-18 10:53:48 UTC (rev 40671)
+++ trunk/hudson/plugins/serenity/src/test/java/com/ikokoon/serenity/ProfilerTest.java	2012-07-18 13:41:35 UTC (rev 40672)
@@ -44,7 +44,7 @@
 		for (Class klass : classes) {
 			List<Method<?, ?>> methods = klass.getChildren();
 			for (Method<?, ?> method : methods) {
-				long averageMethodNetTime = Profiler.averageMethodNetTime(method);
+				double averageMethodNetTime = Profiler.averageMethodNetTime(method);
 				logger.debug("Average net method time : method : " + method.getName() + " - " + averageMethodNetTime);
 			}
 		}
@@ -57,7 +57,7 @@
 		for (Class klass : classes) {
 			List<Method<?, ?>> methods = klass.getChildren();
 			for (Method<?, ?> method : methods) {
-				long averageMethodTime = Profiler.averageMethodTime(method);
+				double averageMethodTime = Profiler.averageMethodTime(method);
 				logger.debug("Average method : method : " + method.getName() + " - " + averageMethodTime);
 			}
 		}
@@ -70,7 +70,7 @@
 		for (Class klass : classes) {
 			List<Method<?, ?>> methods = klass.getChildren();
 			for (Method<?, ?> method : methods) {
-				long methodChange = Profiler.methodChange(method);
+				double methodChange = Profiler.methodChange(method);
 				logger.debug("Method change : method : " + method.getName() + " - " + methodChange);
 			}
 		}
@@ -83,7 +83,7 @@
 		for (Class klass : classes) {
 			List<Method<?, ?>> methods = klass.getChildren();
 			for (Method<?, ?> method : methods) {
-				List<Long> series = Profiler.methodChangeSeries(method);
+				List<Double> series = Profiler.methodChangeSeries(method);
 				logger.debug("Method change series : " + method.getName() + " - " + series);
 			}
 		}
@@ -96,7 +96,7 @@
 		for (Class klass : classes) {
 			List<Method<?, ?>> methods = klass.getChildren();
 			for (Method<?, ?> method : methods) {
-				long methodNetChange = Profiler.methodNetChange(method);
+				double methodNetChange = Profiler.methodNetChange(method);
 				logger.debug("Method net change : method : " + method.getName() + " - " + methodNetChange);
 			}
 		}
@@ -109,7 +109,7 @@
 		for (Class klass : classes) {
 			List<Method<?, ?>> methods = klass.getChildren();
 			for (Method<?, ?> method : methods) {
-				List<Long> methodNetChangeSeries = Profiler.methodNetChangeSeries(method);
+				List<Double> methodNetChangeSeries = Profiler.methodNetChangeSeries(method);
 				logger.debug("Method net change series : method : " + method.getName() + " - " + methodNetChangeSeries);
 			}
 		}
@@ -122,7 +122,7 @@
 		for (Class klass : classes) {
 			List<Method<?, ?>> methods = klass.getChildren();
 			for (Method<?, ?> method : methods) {
-				List<Long> methodNetSeries = Profiler.methodNetSeries(method);
+				List<Double> methodNetSeries = Profiler.methodNetSeries(method);
 				logger.debug("Method net series : method : " + method.getName() + " - " + methodNetSeries);
 			}
 		}
@@ -135,7 +135,7 @@
 		for (Class klass : classes) {
 			List<Method<?, ?>> methods = klass.getChildren();
 			for (Method<?, ?> method : methods) {
-				List<Long> series = Profiler.methodSeries(method);
+				List<Double> series = Profiler.methodSeries(method);
 				logger.debug("Method series : " + method.getName() + " - " + series);
 			}
 		}
@@ -148,7 +148,7 @@
 		for (Class klass : classes) {
 			List<Method<?, ?>> methods = klass.getChildren();
 			for (Method<?, ?> method : methods) {
-				long totalMethodTime = Profiler.totalMethodTime(method);
+				double totalMethodTime = Profiler.totalMethodTime(method);
 				logger.debug("Total method time : method : " + method.getName() + " - " + totalMethodTime);
 			}
 		}
@@ -161,7 +161,7 @@
 		for (Class klass : classes) {
 			List<Method<?, ?>> methods = klass.getChildren();
 			for (Method<?, ?> method : methods) {
-				long totalNetMethodTime = Profiler.totalNetMethodTime(method);
+				double totalNetMethodTime = Profiler.totalNetMethodTime(method);
 				logger.debug("Total net method time : method : " + method.getName() + " - " + totalNetMethodTime);
 			}
 		}

Modified: trunk/hudson/plugins/serenity/src/test/java/com/ikokoon/serenity/process/ReporterTest.java (40671 => 40672)


--- trunk/hudson/plugins/serenity/src/test/java/com/ikokoon/serenity/process/ReporterTest.java	2012-07-18 10:53:48 UTC (rev 40671)
+++ trunk/hudson/plugins/serenity/src/test/java/com/ikokoon/serenity/process/ReporterTest.java	2012-07-18 13:41:35 UTC (rev 40672)
@@ -42,33 +42,16 @@
 
 	@Test
 	public void methodSeries() throws Exception {
+		System.setProperty(IConstants.TIME_UNIT, "1000");
+		String dataBaseFile = "./src/test/resources/profiler/serenity.odb";
+		dataBase = IDataBase.DataBaseManager.getDataBase(DataBaseOdb.class, dataBaseFile, mockInternalDataBase);
+		Profiler.initialize(dataBase);
 		String html = new Reporter(null, dataBase).methodSeries(dataBase);
 		File file = new File(IConstants.METHOD_SERIES_FILE);
 		Toolkit.setContents(file, html.getBytes());
 	}
 
 	@Test
-	public void methodNetSeries() throws Exception {
-		String html = new Reporter(null, dataBase).methodNetSeries(dataBase);
-		File file = new File(IConstants.METHOD_NET_SERIES_FILE);
-		Toolkit.setContents(file, html.getBytes());
-	}
-
-	@Test
-	public void methodChangeSeries() throws Exception {
-		String html = new Reporter(null, dataBase).methodChangeSeries(dataBase);
-		File file = new File(IConstants.METHOD_CHANGE_SERIES_FILE);
-		Toolkit.setContents(file, html.getBytes());
-	}
-
-	@Test
-	public void methodNetChangeSeries() throws Exception {
-		String html = new Reporter(null, dataBase).methodNetChangeSeries(dataBase);
-		File file = new File(IConstants.METHOD_NET_CHANGE_SERIES_FILE);
-		Toolkit.setContents(file, html.getBytes());
-	}
-
-	@Test
 	@SuppressWarnings("unchecked")
 	public void buildGraph() {
 		File chartDirectory = new File(IConstants.SERENITY_DIRECTORY + File.separatorChar + IConstants.CHARTS);
@@ -79,7 +62,7 @@
 		Class klass = dataBase.find(Class.class, id);
 		List<Method> methods = klass.getChildren();
 		for (Method method : methods) {
-			List<Long> methodSeries = Profiler.methodSeries(method);
+			List<Double> methodSeries = Profiler.methodSeries(method);
 			logger.warn("Method series : " + methodSeries);
 			String graph = new Reporter(null, dataBase).buildGraph(IConstants.METHOD_SERIES, method, methodSeries);
 			logger.info("Built graph : " + graph);

Deleted: trunk/hudson/plugins/serenity/src/test/resources/profile.bat (40671 => 40672)


--- trunk/hudson/plugins/serenity/src/test/resources/profile.bat	2012-07-18 10:53:48 UTC (rev 40671)
+++ trunk/hudson/plugins/serenity/src/test/resources/profile.bat	2012-07-18 13:41:35 UTC (rev 40672)
@@ -1 +0,0 @@
-java -jar 
\ No newline at end of file

Reply via email to