[jboss-cvs] JBossAS SVN: r107804 - in projects/jboss-jca/branches/performance: apps and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Aug 26 06:17:34 EDT 2010


Author: jeff.zhang
Date: 2010-08-26 06:17:33 -0400 (Thu, 26 Aug 2010)
New Revision: 107804

Added:
   projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/ChartGraphics.java
   projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/CompareHtmlBenchmarkReport.java
Modified:
   projects/jboss-jca/branches/performance/apps/build.xml
   projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/BenchmarkReport.java
   projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/HtmlBenchmarkReport.java
   projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/TxtBenchmarkReport.java
   projects/jboss-jca/branches/performance/build.xml
Log:
[JBJCA-394] generate graphic

Modified: projects/jboss-jca/branches/performance/apps/build.xml
===================================================================
--- projects/jboss-jca/branches/performance/apps/build.xml	2010-08-26 10:15:04 UTC (rev 107803)
+++ projects/jboss-jca/branches/performance/apps/build.xml	2010-08-26 10:17:33 UTC (rev 107804)
@@ -102,6 +102,20 @@
   </target>
 
   <!-- ================================= 
+       Target: benchmark-report-summary
+       ================================= -->
+  <target name="benchmark-report-summary">
+    <path id="benchmark.report.classpath">
+      <fileset dir="${target.dir}" includes="ironjacamar-performance-apps.jar"/>
+    </path>
+    <java classname="org.jboss.jca.performance.apps.CompareHtmlBenchmarkReport" dir="${build.dir}">
+      <arg value="${root.dir}"/>
+      <arg value="${report.num}"/>
+      <classpath refid="benchmark.report.classpath"/>
+    </java>
+  </target>
+
+  <!-- ================================= 
        Target: docs
        ================================= -->
   <target name="docs" depends="compile">

Modified: projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/BenchmarkReport.java
===================================================================
--- projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/BenchmarkReport.java	2010-08-26 10:15:04 UTC (rev 107803)
+++ projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/BenchmarkReport.java	2010-08-26 10:17:33 UTC (rev 107804)
@@ -131,24 +131,13 @@
          }
       }
    }
-
-   /**
-    * print usage
-    *
-    * @param msg usage message
-    */
-   static void usage(String msg)
-   {
-      System.err.println(msg);
-      System.err.println("Usage: java " + BenchmarkReport.class.getName() + " rootDir serverVersion runNumber");
-      System.exit(1);
-   }
    
    class Data
    {
       private String trans;
       private String number;
       private String time;
+      private String server;
       
       public Data(String trans, String number, String time)
       {
@@ -187,5 +176,25 @@
       {
          return time;
       }
+
+      /**
+       * Set the server.
+       * 
+       * @param server The server to set.
+       */
+      public void setServer(String server)
+      {
+         this.server = server;
+      }
+
+      /**
+       * Get the server.
+       * 
+       * @return the server.
+       */
+      public String getServer()
+      {
+         return server;
+      }
    }
 }

Added: projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/ChartGraphics.java
===================================================================
--- projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/ChartGraphics.java	                        (rev 0)
+++ projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/ChartGraphics.java	2010-08-26 10:17:33 UTC (rev 107804)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.performance.apps;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
+
+import com.sun.image.codec.jpeg.JPEGCodec;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
+
+public class ChartGraphics
+{
+   final static Color[] COLORS = {Color.red, Color.green, Color.blue, Color.yellow};
+   private BufferedImage image;
+
+   public void createImage(String fileLocation)
+   {
+      try
+      {
+         FileOutputStream fos = new FileOutputStream(fileLocation);
+         BufferedOutputStream bos = new BufferedOutputStream(fos);
+         JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
+         encoder.encode(image);
+         bos.close();
+      }
+      catch (Exception e)
+      {
+         System.out.println(e);
+      }
+   }
+
+   public void graphicsGeneration(int[][] data, String imageFile)
+   {
+      final int X = 20;
+      int imageWidth = 950;
+      int imageHeight = 600;
+      int columnWidth = 10;
+      int columnHeight = 550;
+      int groupDistance = 140;
+      int barDistance = 5;
+      final int H = 50;
+      final int Y = 70;
+
+      this.image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
+      Graphics2D graphics = (Graphics2D)this.image.getGraphics();
+      graphics.setColor(Color.white);
+      graphics.fillRect(0, 0, imageWidth, imageHeight);
+      for (int i = 0; i < data[0].length; i++)
+      {
+         graphics.setColor(COLORS[i]);
+         for (int j = 0; j < data.length; j++)
+         {
+            if (data[j][i] <= 0)
+               continue;
+            int h = (int)(Math.log10(new Integer(data[j][i]).doubleValue()) * 100);
+            int s = j / 2;
+            int p = j - s * 2;
+            graphics.fill3DRect(X + s * groupDistance + (i * 2 + p) * columnWidth + barDistance * i, 
+               columnHeight - h, columnWidth, h, true);
+         }
+         graphics.fill3DRect(X, H + i * (columnWidth + barDistance), 100, columnWidth, true); 
+         graphics.drawString(CompareHtmlBenchmarkReport.servers[i], X + 105, H + i * (columnWidth + barDistance) + 10);
+      }
+      
+      graphics.setColor(Color.black);
+      graphics.drawLine(imageWidth - Y, H, imageWidth - Y, columnHeight);
+      for (int i = 0 ; i < CompareHtmlBenchmarkReport.units.length; i++)
+      {
+         graphics.drawString(CompareHtmlBenchmarkReport.units[i], imageWidth - Y + 2, columnHeight - i * 100);
+      }
+      
+      this.createImage(imageFile);
+   }
+}

Added: projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/CompareHtmlBenchmarkReport.java
===================================================================
--- projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/CompareHtmlBenchmarkReport.java	                        (rev 0)
+++ projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/CompareHtmlBenchmarkReport.java	2010-08-26 10:17:33 UTC (rev 107804)
@@ -0,0 +1,315 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.performance.apps;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ * A CompareHtmlBenchmarkReport.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class CompareHtmlBenchmarkReport extends BenchmarkReport
+{
+   final static String[] servers = {"jbas-4.2.3.GA", "jbas-5.1.0.GA", "jbjca-1.0.0.Beta1", "jbjca-daily"};
+   final static String[] units = {"1", "10", "100", "1000", "10000", "100000"};
+   final static String[] transactions = {"NoTransaction", "XATransaction"};
+   
+   int[][] workManagerArray = new int[units.length * 2][servers.length];
+   int[][] workManagerBlockArray = new int[units.length * 2][servers.length];
+   int[][] connectionArray = new int[units.length * 2][servers.length];
+   
+   /**
+    * main
+    *
+    * @param args param
+    */
+   public static void main(String[] args)
+   {
+      if (args.length < 2)
+         usage("Wrong number of arguments.");
+      
+      String reportDir = args[0] + File.separator + "reports" + File.separator + "benchmark" + File.separator + args[1];
+      String dataFilename;
+     
+      try
+      {
+         
+         CompareHtmlBenchmarkReport report = new CompareHtmlBenchmarkReport();
+         
+         for (String server : servers)
+         {
+            dataFilename = args[0] + File.separator + "runs" + File.separator + server + File.separator + "raw"
+            + File.separator + args[1] + File.separator + "data.txt";
+            
+            FileInputStream fin = new FileInputStream(dataFilename);
+            InputStreamReader isr = new InputStreamReader(fin);
+            BufferedReader br = new BufferedReader(isr);
+
+            report.serverVersion = server;
+            report.readData(br);
+            fin.close();
+         }
+         
+         File path = new File(reportDir);
+         if (!path.exists())
+         {
+            if (!path.mkdirs())
+               throw new IOException("outdir can't be created");
+         }
+
+         FileWriter fw = new FileWriter(reportDir + File.separator + "report.html");
+         report.generateTextReport(fw);
+         fw.close();
+         
+         ChartGraphics cg = new ChartGraphics();
+         cg.graphicsGeneration(report.workManagerArray, reportDir + File.separator + "wm.jpg");
+         cg.graphicsGeneration(report.workManagerBlockArray, reportDir + File.separator + "wmb.jpg");
+         cg.graphicsGeneration(report.connectionArray, reportDir + File.separator + "conn.jpg");
+      }
+      catch (IOException ioe)
+      {
+         ioe.printStackTrace();
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+      }
+   }
+
+   /**
+    * read data from file
+    * 
+    * @param br reader
+    * @throws IOException
+    */
+   @Override
+   void readData(BufferedReader br) throws IOException
+   {
+      String str;
+      while ((str = br.readLine()) != null)
+      {
+         String part[] = str.split(",");
+         if (part[0].equals("workmanager"))
+         {
+            Data data = new Data(part[2], part[3], part[4]);
+            data.setServer(serverVersion);
+            workmanagerData.add(data);
+            
+            writeDataArray(part, workManagerArray);
+
+         }
+         else if (part[0].equals("workmanager-block"))
+         {
+            Data data = new Data(part[2], part[3], part[4]);
+            data.setServer(serverVersion);
+            workmanagerBlockData.add(data);
+            
+            writeDataArray(part, workManagerBlockArray);
+         }
+         if (part[0].equals("connection"))
+         {
+            Data data = new Data(part[2], part[3], part[4]);
+            data.setServer(serverVersion);
+            connectionData.add(data);
+            
+            writeDataArray(part, connectionArray);
+         }
+      }
+   }
+
+   /**
+    * write data array
+    * 
+    * @param part
+    * @param dataArray 
+    */
+   private void writeDataArray(String[] part, int[][] dataArray)
+   {
+      int unit = 0;
+      int tran = 0;
+      int server = 0;
+      for (int i = 0; i < units.length; i++)
+      {
+         if (part[3].equals(units[i]))
+            unit = i;
+      }
+
+      if (part[2].equals("XATransaction"))
+         tran = 1;
+      else
+         tran = 0;
+      for (int i = 0; i < servers.length; i++)
+      {
+         if (serverVersion.equals(servers[i]))
+            server = i;
+      }
+      dataArray[unit * 2 + tran][server] = Integer.parseInt(part[4]);
+   }
+   
+   /**
+    * write html header
+    * 
+    * @param fw writer
+    * @throws IOException
+    */
+   @Override
+   void writeTop(FileWriter fw) throws IOException
+   {
+      fw.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
+      writeEol(fw);
+      fw.write("<html><head><title>benchmark report</title></head><body>");
+      writeEol(fw);
+   }
+   
+   /**
+    * generate subject
+    * 
+    * @param fw writer
+    * @throws IOException
+    */
+   @Override
+   void generateSubject(FileWriter fw) throws IOException
+   {
+      fw.write("<p><b1>Servers</b1></p>");
+      writeEol(fw);
+   }
+   /**
+    * generate body
+    * 
+    * @param fw writer
+    * @throws IOException
+    */
+   @Override
+   void generateBody(FileWriter fw) throws IOException
+   {
+      writeArrayData(fw, workManagerArray, "WorkManager test cases");
+      fw.write("<image src=\"wm.jpg\" alt=\"work manager\"/>");
+      writeEol(fw);
+      writeArrayData(fw, workManagerBlockArray, "WorkManager with block test cases");
+      fw.write("<image src=\"wmb.jpg\" alt=\"work manager\"/>");
+      writeEol(fw);
+      writeArrayData(fw, connectionArray, "Connection test cases");
+      fw.write("<image src=\"conn.jpg\" alt=\"work manager\"/>");
+      writeEol(fw);
+   }
+
+   /**
+    * write array data
+    * 
+    * @param fw
+    * @param data list of data
+    * @param text description
+    * @throws IOException
+    */
+   private void writeArrayData(FileWriter fw, int[][] data, String text) throws IOException
+   {
+      fw.write("<p><b2>");
+      fw.write(text);
+      fw.write("</b2></p>");
+      writeEol(fw);
+      fw.write("<table border=\"1\">");
+      writeEol(fw);
+      writeHeader(fw);
+      writeData(fw, data);
+      fw.write("</table>");
+      writeEol(fw);
+   }
+
+   
+   /**
+    * write data table header
+    * 
+    * @param fw writer
+    * @throws IOException
+    */
+   void writeHeader(FileWriter fw) throws IOException
+   {
+      fw.write("<theader><td>Units</td><td>Transaction</td>");
+      for (int i = 0; i < servers.length; i++)
+      {
+         fw.write("<td>" + servers[i] + "</td>");
+      }
+      fw.write("</theader>");
+      writeEol(fw);
+   }
+
+
+   /**
+    * write data
+    * 
+    * @param fw writer
+    * @param data list of data
+    * @throws IOException
+    */
+   void writeData(FileWriter fw, int[][] data) throws IOException
+   {
+
+      for (int i = 0; i < units.length; i++)
+      {
+         for (int j = 0; j < transactions.length; j++)
+         {
+            fw.write("<tr><td>" + units[i] + "</td><td>" + transactions[j] + "</td>");
+            for (int k = 0; k < servers.length; k ++)
+            {
+               fw.write("<td>" + data[i * transactions.length + j][k] + "</td>");
+            }
+            fw.write("</tr>");
+            writeEol(fw);
+         }
+      }
+
+   }
+   
+   /**
+    * write bottom
+    * 
+    * @param fw writer
+    * @throws IOException
+    */
+   @Override
+   void writeBottom(FileWriter fw) throws IOException
+   {
+      fw.write("</table></body></html>");
+      writeEol(fw);
+   }
+   
+
+   /**
+    * print usage
+    *
+    * @param msg usage message
+    */
+   static void usage(String msg)
+   {
+      System.err.println(msg);
+      System.err.println("Usage: java " + CompareHtmlBenchmarkReport.class.getName() + " rootDir runNumber");
+      System.exit(1);
+   }
+   
+}

Modified: projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/HtmlBenchmarkReport.java
===================================================================
--- projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/HtmlBenchmarkReport.java	2010-08-26 10:15:04 UTC (rev 107803)
+++ projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/HtmlBenchmarkReport.java	2010-08-26 10:17:33 UTC (rev 107804)
@@ -37,7 +37,6 @@
  */
 public class HtmlBenchmarkReport extends BenchmarkReport
 {
-   
    /**
     * main
     *

Modified: projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/TxtBenchmarkReport.java
===================================================================
--- projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/TxtBenchmarkReport.java	2010-08-26 10:15:04 UTC (rev 107803)
+++ projects/jboss-jca/branches/performance/apps/src/main/java/org/jboss/jca/performance/apps/TxtBenchmarkReport.java	2010-08-26 10:17:33 UTC (rev 107804)
@@ -37,7 +37,6 @@
  */
 public class TxtBenchmarkReport extends BenchmarkReport
 {
-   
    /**
     * main
     *
@@ -218,5 +217,16 @@
       }
    }
 
+   /**
+    * print usage
+    *
+    * @param msg usage message
+    */
+   static void usage(String msg)
+   {
+      System.err.println(msg);
+      System.err.println("Usage: java " + TxtBenchmarkReport.class.getName() + " rootDir serverVersion runNumber");
+      System.exit(1);
+   }
 
 }

Modified: projects/jboss-jca/branches/performance/build.xml
===================================================================
--- projects/jboss-jca/branches/performance/build.xml	2010-08-26 10:15:04 UTC (rev 107803)
+++ projects/jboss-jca/branches/performance/build.xml	2010-08-26 10:17:33 UTC (rev 107804)
@@ -199,6 +199,12 @@
     </ant>
   </target>
 
+  <target name="benchmark-report-summary" depends="jars">
+    <ant dir="apps" inheritRefs="true" target="benchmark-report-summary">
+      <property name="report.num" value="${report.num}"/>
+    </ant>
+  </target>
+
   <!-- ================================= 
        Target: profiler
        ================================= -->



More information about the jboss-cvs-commits mailing list