modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
| 188 ++++++++--
1 file changed, 155 insertions(+), 33 deletions(-)
New commits:
commit d348c2c2395bdbbb8d53d2aabfc0fed950d5426d
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Oct 5 17:48:18 2010 +0200
Do header stuff in bold
diff --git
a/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
index 8d6f9d5..4eaf30c 100644
---
a/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
+++
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
@@ -40,6 +40,7 @@ public class ExcelExporter implements PerformanceReportExporter {
private static final String DOT_XLS = ".xls";
String baseFileName ;
CellStyle integerStyle;
+ CellStyle boldText;
@Override
public void setBaseFile(String fileName) {
@@ -75,6 +76,10 @@ public class ExcelExporter implements PerformanceReportExporter {
DataFormat df = wb.createDataFormat();
integerStyle = wb.createCellStyle();
integerStyle.setDataFormat(df.getFormat("#######0"));
+ Font boldFont = wb.createFont();
+ boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
+ boldText = wb.createCellStyle();
+ boldText.setFont(boldFont);
createOverviewHeaderIfNeeded(sheet);
@@ -104,31 +109,51 @@ public class ExcelExporter implements PerformanceReportExporter {
Sheet sheet = wb.createSheet(result.getName());
Row row = sheet.createRow(0);
- row.createCell(0).setCellValue("Class");
+ Cell cell = row.createCell(0);
+ cell.setCellStyle(boldText);
+ cell.setCellValue("Class");
String name = result.getTestClass().getName();
name =
name.replace("org.rhq.enterprise.server.performance.test.","");
row.createCell(1).setCellValue(name);
row = appendRow(sheet);
- row.createCell(0).setCellValue("Method");
+
+ cell = row.createCell(0);
+ cell.setCellStyle(boldText);
+ cell.setCellValue("Method");
row.createCell(1).setCellValue(result.getName());
- row.createCell(0).setCellValue("Success:");
+ cell = row.createCell(0);
+ cell.setCellStyle(boldText);
+ cell.setCellValue("Success:");
row.createCell(1).setCellValue(result.isSuccess());
+
row = appendRow(sheet);
- row.createCell(0).setCellValue("TestNG timing");
+ cell = row.createCell(0);
+ cell.setCellStyle(boldText);
+ cell.setCellValue("TestNG timing");
row.createCell(1).setCellValue(result.getEndMillis()-result.getStartMillis());
+
row = appendRow(sheet);
- row.createCell(0).setCellValue("Perf test timing");
+ cell = row.createCell(0);
+ cell.setCellStyle(boldText);
+ cell.setCellValue("Perf test timing");
row.createCell(1).setCellValue(getTotalTime(timings));
- row = appendRow(sheet); // Empty
+
+ row = appendRow(sheet); // Empty row
row = appendRow(sheet);
- row.createCell(0).setCellValue("Individual Timings");
+ cell = row.createCell(0);
+ cell.setCellStyle(boldText);
+ cell.setCellValue("Individual Timings");
// Now the timings
row = appendRow(sheet);
- row.createCell(0).setCellValue("Name");
- row.createCell(1).setCellValue("Duration");
+ cell = row.createCell(0);
+ cell.setCellStyle(boldText);
+ cell.setCellValue("Name");
+ cell = row.createCell(1);
+ cell.setCellStyle(boldText);
+ cell.setCellValue("Duration");
Set<Map.Entry<String,Long>> data = timings.entrySet();
SortedSet<Map.Entry<String,Long>> sorted = new
TreeSet<Map.Entry<String,Long>>(new
Comparator<Map.Entry<String,Long>>() {
@@ -142,7 +167,7 @@ public class ExcelExporter implements PerformanceReportExporter {
for (Map.Entry<String,Long> entry: sorted) {
row = appendRow(sheet);
- Cell cell = row.createCell(0);
+ cell = row.createCell(0);
cell.setCellValue(entry.getKey());
cell = row.createCell(1);
cell.setCellStyle(integerStyle);
@@ -185,7 +210,6 @@ public class ExcelExporter implements PerformanceReportExporter {
cell.setCellValue(result.getEndMillis()-result.getStartMillis());
// timing of our business logic
-
cell = row.createCell(4);
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
cell.setCellStyle(integerStyle);
@@ -202,15 +226,21 @@ public class ExcelExporter implements PerformanceReportExporter {
row = sheet.createRow(0);
Cell cell = row.createCell(0);
+ cell.setCellStyle(boldText);
cell.setCellValue("Class");
cell = row.createCell(1);
+ cell.setCellStyle(boldText);
cell.setCellValue("Name");
cell = row.createCell(2);
+ cell.setCellStyle(boldText);
cell.setCellValue("Success");
cell = row.createCell(3);
+ cell.setCellStyle(boldText);
cell.setCellValue("TestNG timing");
+ cell.setCellStyle(boldText);
cell = row.createCell(4);
cell.setCellValue("Perf timing");
+ cell.setCellStyle(boldText);
sheet.autoSizeColumn(0);
sheet.autoSizeColumn(1);
commit 6e422587818f1d28791551fa2ae0532dd907e56d
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Oct 5 17:25:10 2010 +0200
Create detail sheets for individual tests.
diff --git
a/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
index 5959dfa..8d6f9d5 100644
---
a/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
+++
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
@@ -23,7 +23,11 @@ import org.apache.poi.ss.usermodel.*;
import org.testng.ITestResult;
import java.io.*;
+import java.util.Comparator;
import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
/**
@@ -76,6 +80,7 @@ public class ExcelExporter implements PerformanceReportExporter {
createOverviewHeaderIfNeeded(sheet);
long time = getTotalTime(timings);
createOverviewEntry(sheet, time, result);
+ createDetailsSheet(wb,timings,result);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream(baseFileName);
@@ -90,6 +95,65 @@ public class ExcelExporter implements PerformanceReportExporter {
}
/**
+ * Create a sheet per test to show the individual timings we recorded
+ * @param wb Workbook to attach the new sheet to
+ * @param timings The map with timings from the test
+ * @param result TestNG results of the test
+ */
+ private void createDetailsSheet(Workbook wb, Map<String,Long> timings,
ITestResult result) {
+ Sheet sheet = wb.createSheet(result.getName());
+
+ Row row = sheet.createRow(0);
+ row.createCell(0).setCellValue("Class");
+ String name = result.getTestClass().getName();
+ name =
name.replace("org.rhq.enterprise.server.performance.test.","");
+ row.createCell(1).setCellValue(name);
+ row = appendRow(sheet);
+ row.createCell(0).setCellValue("Method");
+ row.createCell(1).setCellValue(result.getName());
+
+
+ row.createCell(0).setCellValue("Success:");
+ row.createCell(1).setCellValue(result.isSuccess());
+ row = appendRow(sheet);
+ row.createCell(0).setCellValue("TestNG timing");
+ row.createCell(1).setCellValue(result.getEndMillis()-result.getStartMillis());
+ row = appendRow(sheet);
+ row.createCell(0).setCellValue("Perf test timing");
+ row.createCell(1).setCellValue(getTotalTime(timings));
+ row = appendRow(sheet); // Empty
+ row = appendRow(sheet);
+ row.createCell(0).setCellValue("Individual Timings");
+
+ // Now the timings
+ row = appendRow(sheet);
+ row.createCell(0).setCellValue("Name");
+ row.createCell(1).setCellValue("Duration");
+
+ Set<Map.Entry<String,Long>> data = timings.entrySet();
+ SortedSet<Map.Entry<String,Long>> sorted = new
TreeSet<Map.Entry<String,Long>>(new
Comparator<Map.Entry<String,Long>>() {
+
+ public int compare(Map.Entry<String,Long> item1,
Map.Entry<String,Long> item2) {
+
+ return item1.getKey().compareTo(item2.getKey());
+ }
+ });
+ sorted.addAll(data);
+
+ for (Map.Entry<String,Long> entry: sorted) {
+ row = appendRow(sheet);
+ Cell cell = row.createCell(0);
+ cell.setCellValue(entry.getKey());
+ cell = row.createCell(1);
+ cell.setCellStyle(integerStyle);
+ cell.setCellValue(entry.getValue());
+ }
+
+ sheet.autoSizeColumn(0);
+ sheet.autoSizeColumn(1);
+ }
+
+ /**
* Create a row on the overview sheet
* @param sheet sheet to use
* @param testTime time this test took within the perf biz logic
commit 83a25b0117d50d0ace4012c4ec48f8ed6cd447f0
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Oct 5 16:06:37 2010 +0200
Refactoring and add class name to sheet
diff --git
a/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
index aabeb23..5959dfa 100644
---
a/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
+++
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
@@ -18,7 +18,6 @@
*/
package org.rhq.helpers.perftest.support.reporting;
-import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.testng.ITestResult;
@@ -36,6 +35,7 @@ public class ExcelExporter implements PerformanceReportExporter {
private static final String DOT_XLS = ".xls";
String baseFileName ;
+ CellStyle integerStyle;
@Override
public void setBaseFile(String fileName) {
@@ -51,7 +51,7 @@ public class ExcelExporter implements PerformanceReportExporter {
Workbook wb;
InputStream inp = null;
- CellStyle integerStyle;
+
// Check if Workbook is present - otherwise create it
try {
inp = new FileInputStream(baseFileName);
@@ -73,32 +73,9 @@ public class ExcelExporter implements PerformanceReportExporter {
integerStyle.setDataFormat(df.getFormat("#######0"));
- createHeaderIfNeeded(sheet);
-
- // Test name
- Row row = appendRow(sheet);
- Cell cell = row.createCell(0);
- cell.setCellType(Cell.CELL_TYPE_STRING);
- cell.setCellValue(result.getName());
-
- // success ?
- cell = row.createCell(1);
- cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
- cell.setCellValue(result.isSuccess());
-
- // timing from TestNG
- cell = row.createCell(2);
- cell.setCellType(Cell.CELL_TYPE_NUMERIC);
- cell.setCellStyle(integerStyle);
- cell.setCellValue(result.getEndMillis()-result.getStartMillis());
-
- // timing of our business logic
+ createOverviewHeaderIfNeeded(sheet);
long time = getTotalTime(timings);
- cell = row.createCell(3);
- cell.setCellType(Cell.CELL_TYPE_NUMERIC);
- cell.setCellStyle(integerStyle);
- cell.setCellValue(time);
-
+ createOverviewEntry(sheet, time, result);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream(baseFileName);
@@ -112,29 +89,80 @@ public class ExcelExporter implements PerformanceReportExporter {
}
}
- private void createHeaderIfNeeded(Sheet sheet) {
+ /**
+ * Create a row on the overview sheet
+ * @param sheet sheet to use
+ * @param testTime time this test took within the perf biz logic
+ * @param result the TestNG result object
+ */
+ private void createOverviewEntry(Sheet sheet, long testTime, ITestResult result) {
+ // Class name
+ Row row = appendRow(sheet);
+ Cell cell = row.createCell(0);
+ cell.setCellType(Cell.CELL_TYPE_STRING);
+ String name = result.getTestClass().getName();
+ name =
name.replace("org.rhq.enterprise.server.performance.test.","");
+ cell.setCellValue(name);
+
+ // Test name
+ cell = row.createCell(1);
+ cell.setCellType(Cell.CELL_TYPE_STRING);
+ cell.setCellValue(result.getName());
+
+ // success ?
+ cell = row.createCell(2);
+ cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
+ cell.setCellValue(result.isSuccess());
+
+ // timing from TestNG
+ cell = row.createCell(3);
+ cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+ cell.setCellStyle(integerStyle);
+ cell.setCellValue(result.getEndMillis()-result.getStartMillis());
+
+ // timing of our business logic
+
+ cell = row.createCell(4);
+ cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+ cell.setCellStyle(integerStyle);
+ cell.setCellValue(testTime);
+ }
+
+ /**
+ * Create a header row that describes the columns on the overview sheet
+ * @param sheet sheet to write to.
+ */
+ private void createOverviewHeaderIfNeeded(Sheet sheet) {
Row row = sheet.getRow(0);
if (row==null)
row = sheet.createRow(0);
+
Cell cell = row.createCell(0);
- cell.setCellValue("Name");
+ cell.setCellValue("Class");
cell = row.createCell(1);
- cell.setCellValue("Success");
+ cell.setCellValue("Name");
cell = row.createCell(2);
- cell.setCellValue("TestNG timing");
+ cell.setCellValue("Success");
cell = row.createCell(3);
+ cell.setCellValue("TestNG timing");
+ cell = row.createCell(4);
cell.setCellValue("Perf timing");
sheet.autoSizeColumn(0);
- sheet.autoSizeColumn(2);
+ sheet.autoSizeColumn(1);
sheet.autoSizeColumn(3);
+ sheet.autoSizeColumn(4);
}
+ /**
+ * Get the accumulated time from all the perf test biz logic of the test
+ * @param timings Map with timings and 'sub tests'
+ * @return summary time
+ */
private long getTotalTime(Map<String, Long> timings) {
long summaryTime = 0L;
for (Map.Entry<String,Long> item : timings.entrySet()) {
- System.out.println(":| " + item.getKey() + " => " +
item.getValue());
summaryTime += item.getValue();
}
return summaryTime;