KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > performance > PerformanceReporter


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.remoting.performance;
8
9 import java.io.File JavaDoc;
10 import java.io.FileWriter JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.util.Date JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.Map JavaDoc;
15
16 /**
17  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
18  */

19 public class PerformanceReporter
20 {
21    /**
22     * Will write to report file with all the values passed.
23     *
24     * @param testName Name of test run. Typically should be class and test method name.
25     * @param totalCount Total number of iterations for a test (i.e. number of calls to the server).
26     * @param totalTime How long, in milliseconds, that the test took. This is really how long it took
27     * to make the calls to the server and not the extra time for test setup.
28     * @param metadata Any key value pairs would like added to the report. For example, would want to
29     * add the transport and maybe the total number of server count.
30     * @throws IOException
31     */

32    public static void writeReport(String JavaDoc testName, long totalTime, int totalCount, Map JavaDoc metadata) throws IOException JavaDoc
33    {
34       File JavaDoc reportFile = new File JavaDoc("performance_report.txt");
35       if(!reportFile.exists())
36       {
37          reportFile.createNewFile();
38       }
39
40       FileWriter JavaDoc reportWriter = new FileWriter JavaDoc(reportFile, true);
41       reportWriter.write("\n\nTest results for test: " + testName + "\n");
42       reportWriter.write("When run: " + new Date JavaDoc());
43       reportWriter.write("\nTotal count: " + totalCount);
44       reportWriter.write("\nTotal time: " + totalTime);
45       if(metadata != null)
46       {
47          Iterator JavaDoc itr = metadata.keySet().iterator();
48          while(itr.hasNext())
49          {
50             Object JavaDoc key = itr.next();
51             Object JavaDoc value = metadata.get(key);
52             reportWriter.write("\n" + key + " = " + value);
53          }
54       }
55       reportWriter.write("\n\n");
56       reportWriter.close();
57    }
58 }
Popular Tags