diff options
author | Vitaly Provodin <vitaly.provodin@jetbrains.com> | 2017-02-15 10:20:52 +0700 |
---|---|---|
committer | Vitaly Provodin <vitaly.provodin@jetbrains.com> | 2017-02-15 10:20:52 +0700 |
commit | 7a7b4a00b8b35bc65faedd67637488c06da371ab (patch) | |
tree | 06bd0365a09aa031e8e5394845c248c12b687f94 /src/share/demo/java2d/J2DBench | |
parent | ee3c86aa7a1c394d71f9d059754c12d7d91d92f1 (diff) | |
download | jdk8u_jdk-7a7b4a00b8b35bc65faedd67637488c06da371ab.tar.gz |
J2DBench: introduced result reader for TC's chartsjb8u112-b732
Diffstat (limited to 'src/share/demo/java2d/J2DBench')
3 files changed, 294 insertions, 2 deletions
diff --git a/src/share/demo/java2d/J2DBench/build.xml b/src/share/demo/java2d/J2DBench/build.xml index c2af9ec600..a864880289 100644 --- a/src/share/demo/java2d/J2DBench/build.xml +++ b/src/share/demo/java2d/J2DBench/build.xml @@ -49,7 +49,7 @@ <target name="compile" depends="init" description="compile the source " > <!-- Compile the java code from ${src} into ${build} --> - <javac debug="flase" source="1.5" target="1.5" srcdir="${src}" destdir="${build}"/> + <javac debug="flase" source="1.8" target="1.8" srcdir="${src}" destdir="${build}"/> </target> <target name="run" depends="dist" diff --git a/src/share/demo/java2d/J2DBench/src/j2dbench/report/TCChartReporter.java b/src/share/demo/java2d/J2DBench/src/j2dbench/report/TCChartReporter.java new file mode 100644 index 0000000000..3faf6cea13 --- /dev/null +++ b/src/share/demo/java2d/J2DBench/src/j2dbench/report/TCChartReporter.java @@ -0,0 +1,292 @@ +package j2dbench.report; + +import java.io.IOException; +import java.nio.file.DirectoryIteratorException; +import java.nio.file.DirectoryStream; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +/** + * The class reads J2DBench scores and reports them into output stream in format applicable for TeamCity charts. + * The directory, where J2DBench result files placed, is specified via command line parameter like follows: + * <p> + * <code>-basexml | -b <xml file path></code> + * </p> + * This directory must contain one file with pattern <code>*{openjdk}*.{res}</code> which is considered as a container + * of reference scores and several <code>*{jbsdk}*.{res}</code>. + * <p> + * <p> Names of these files have several mandatory fields separated by <code>"_"</code> and look like + * <code>osName_jdkName_renderName_*.res</code> + * </p> + * <p> + * If any of score is less than corresponding reference value by 5% then exit code <code>1</code> is returned otherwise + * exit code <code>0</code> is returned. + * <p> + * Standard output will contain scores in format required for TeamCity charts. + * <p> + * Created by vprovodin on 13/02/2017. + */ +public class TCChartReporter { + + private static final DecimalFormat decimalFormat = + new DecimalFormat("0.00"); + + private static FileSystem defaultFileSystem = FileSystems.getDefault(); + + /** + * Level at which tests are grouped to be displayed in summary + */ + private static final int LEVEL = 2; + + /** + * Holds the groups and corresponding group-display-names + */ + private static List<String> groups = new ArrayList<>(); + private static Map<String, Double> referenceValues = new HashMap<>(); + private static boolean testFailed = false; + + private static void printUsage() { + String usage = + "\njava TCChartReporter [options] " + + " \n\n" + + "where options include: " + + " \n" + + " -basexml | -b <xml file path> " + + "path to base-build result"; + System.out.println(usage); + System.exit(0); + } + + /** + * String = getTestResultsTableForSummary() + */ + private static double generateTestCaseReport( + Object key, + Map<String, J2DAnalyzer.ResultHolder> testCaseResult, + Map<String, Integer> testCaseResultCount) { + + Integer curTestCountObj = testCaseResultCount.get(key.toString()); + int curTestCount = 0; + if (curTestCountObj != null) { + curTestCount = curTestCountObj; + } + + double totalScore = 0; + + for (int i = 0; i < curTestCount; i++) { + J2DAnalyzer.ResultHolder resultTCR = testCaseResult.get(key.toString() + "_" + i); + totalScore = totalScore + resultTCR.getScore(); + } + + return totalScore; + } + + /** + * Generate Testcase Summary Report for TC - *.out + */ + private static void generateTestCaseSummaryReport( + String OJRname, + Map<String, Double> consoleResult, + Map<String, J2DAnalyzer.ResultHolder> testCaseResult, + Map<String, Integer> testCaseResultCount, + boolean rememberReference) { + + String curGroupName, curTestName; + + Object[] groupNameArray = groups.toArray(); + + Object[] testCaseList = consoleResult.keySet().toArray(); + Arrays.sort(testCaseList); + + for (Object aGroupNameArray : groupNameArray) { + + double value; + curGroupName = aGroupNameArray.toString(); + + for (Object aTestCaseList : testCaseList) { + + curTestName = aTestCaseList.toString(); + + if (curTestName.contains(curGroupName)) { + + value = generateTestCaseReport(curTestName, testCaseResult, testCaseResultCount); + + System.out.println("##teamcity[buildStatisticValue key='" + OJRname + "." + curTestName + + "' value='" + decimalFormat.format(value) + "']\n"); + if (rememberReference) { + referenceValues.put(curTestName, value); + } else { + double refValue = referenceValues.getOrDefault(curTestName, 0.); + if ((refValue - value) >= refValue * 0.1) { + System.err.println(curTestName); + System.err.println("\treferenceValue=" + refValue); + System.err.println("\t actualValue=" + value); + System.err.println("\t diff:" + (Math.abs(1 - value / refValue) * 100)); + testFailed = true; + } + } + } + } + } + } + + /** + * main + */ + public static void main(String args[]) { + + String baseXML = null; + int group = 2; + + /* ---- Analysis Mode ---- + BEST = 1; + WORST = 2; + AVERAGE = 3; + MIDAVG = 4; + ------------------------ */ + int analyzerMode = 4; + + try { + + for (int i = 0; i < args.length; i++) { + + if (args[i].startsWith("-basexml") || + args[i].startsWith("-b")) { + i++; + baseXML = args[i]; + } + } + } catch (Exception e) { + printUsage(); + } + + XMLHTMLReporter.setGroupLevel(group); + J2DAnalyzer.setMode(analyzerMode); + if (baseXML != null) { + generateComparisonReport(defaultFileSystem.getPath(baseXML)); + } else { + printUsage(); + } + + if (testFailed) + System.exit(1); + } + + /** + * Add Test Group to the list + */ + private static void addGroup(String testName) { + + String testNameSplit[] = testName.replace('.', '_').split("_"); + StringBuilder group = new StringBuilder(testNameSplit[0]); + for (int i = 1; i < LEVEL; i++) { + group.append(".").append(testNameSplit[i]); + } + + if (!groups.contains(group.toString())) + groups.add(group.toString()); + } + + private static List<Path> listResFiles(Path dir, String pattern) throws IOException { + List<Path> result = new ArrayList<>(); + try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, pattern)) { + for (Path entry : stream) { + result.add(entry); + } + } catch (DirectoryIteratorException ex) { + throw ex.getCause(); + } + return result; + } + + /** + * Generate the reports from the base & target result XML + */ + private static void generateComparisonReport(Path directoryToResFiles) { + + List<Path> jbsdkFiles, openjdkFiles; + + try { + jbsdkFiles = listResFiles(directoryToResFiles, "*{jbsdk}*.{res}"); + openjdkFiles = listResFiles(directoryToResFiles, "*{openjdk}*.{res}"); + } catch (IOException e) { + e.printStackTrace(); + return; + } + + readScores(openjdkFiles.get(0), true); + + for (Path file : jbsdkFiles) { + readScores(file, false); + } + } + + private static void readScores(Path file, boolean rememberReference) { + String fileName = file.getName(file.getNameCount() - 1).toString(); + String[] fileNameComponents = fileName.split("_"); + String osName = fileNameComponents[0]; + String jdkName = fileNameComponents[1]; + String renderName = fileNameComponents[2]; + String resultXMLFileName = file.toString(); + + J2DAnalyzer.results = new Vector(); + J2DAnalyzer.readResults(resultXMLFileName); + J2DAnalyzer.SingleResultSetHolder baseSRSH = + (J2DAnalyzer.SingleResultSetHolder) J2DAnalyzer.results.elementAt(0); + Enumeration baseEnum_ = baseSRSH.getKeyEnumeration(); + Vector<String> baseKeyvector = new Vector<>(); + while (baseEnum_.hasMoreElements()) { + baseKeyvector.add((String) baseEnum_.nextElement()); + } + String baseKeys[] = new String[baseKeyvector.size()]; + baseKeyvector.copyInto(baseKeys); + J2DAnalyzer.sort(baseKeys); + + Map<String, Double> consoleBaseRes = new HashMap<>(); + + Map<String, J2DAnalyzer.ResultHolder> testCaseBaseResult = new HashMap<>(); + Map<String, Integer> testCaseResultCount = new HashMap<>(); + + for (String baseKey : baseKeys) { + + J2DAnalyzer.ResultHolder baseTCR = + baseSRSH.getResultByKey(baseKey); + + Integer curTestCountObj = testCaseResultCount.get(baseTCR.getName()); + int curTestCount = 0; + if (curTestCountObj != null) { + curTestCount = curTestCountObj; + } + curTestCount++; + testCaseBaseResult.put(baseTCR.getName() + "_" + (curTestCount - 1), baseTCR); + testCaseResultCount.put(baseTCR.getName(), curTestCount); + + addGroup(baseTCR.getName()); + + Double curTotalScoreObj = consoleBaseRes.get(baseTCR.getName()); + double curTotalScore = 0; + if (curTotalScoreObj != null) { + curTotalScore = curTotalScoreObj; + } + curTotalScore = curTotalScore + baseTCR.getScore(); + consoleBaseRes.put(baseTCR.getName(), curTotalScore); + } + + generateTestCaseSummaryReport(osName + "." + jdkName + "." + renderName, + consoleBaseRes, + testCaseBaseResult, + testCaseResultCount, + rememberReference); + + } +} diff --git a/src/share/demo/java2d/J2DBench/src/j2dbench/report/XMLHTMLReporter.java b/src/share/demo/java2d/J2DBench/src/j2dbench/report/XMLHTMLReporter.java index 35c5902214..14c03a30c9 100644 --- a/src/share/demo/java2d/J2DBench/src/j2dbench/report/XMLHTMLReporter.java +++ b/src/share/demo/java2d/J2DBench/src/j2dbench/report/XMLHTMLReporter.java @@ -117,7 +117,7 @@ public class XMLHTMLReporter { /** * Generate a Display Name for this group */ - private static String getDisplayGroupName(String group) { + static String getDisplayGroupName(String group) { String groupSplit[] = group.replace('.', '_').split("_"); |