Author: [email protected]
Date: Wed Apr  1 11:39:45 2009
New Revision: 5146

Added:
    trunk/tools/soyc-vis/src/com/google/gwt/soyc/Settings.java   (contents,  
props changed)
Modified:
    trunk/tools/soyc-vis/src/com/google/gwt/soyc/GlobalInformation.java
    trunk/tools/soyc-vis/src/com/google/gwt/soyc/MakeTopLevelHtmlForPerm.java
    trunk/tools/soyc-vis/src/com/google/gwt/soyc/SoycDashboard.java

Log:
Inlined the table of runAsync fragments into the top-level HTML so
that it doesn't get a separate scroll bar.  Also, adds a -resource
argument for where the CSS and other resource files should be found.

Patch by: spoon, knorton (pair prog)

Modified:  
trunk/tools/soyc-vis/src/com/google/gwt/soyc/GlobalInformation.java
==============================================================================
--- trunk/tools/soyc-vis/src/com/google/gwt/soyc/GlobalInformation.java  
(original)
+++ trunk/tools/soyc-vis/src/com/google/gwt/soyc/GlobalInformation.java Wed  
Apr  1 11:39:45 2009
@@ -58,6 +58,8 @@

    public static HashMap<String, String> storiesToLitType = new  
HashMap<String, String>();

+  public static Settings settings = new Settings();
+
    public static void computePackageSizes() {
      cumSizeFromPackages = 0;
      packageToSize.clear();

Modified:  
trunk/tools/soyc-vis/src/com/google/gwt/soyc/MakeTopLevelHtmlForPerm.java
==============================================================================
---  
trunk/tools/soyc-vis/src/com/google/gwt/soyc/MakeTopLevelHtmlForPerm.java       
 
(original)
+++  
trunk/tools/soyc-vis/src/com/google/gwt/soyc/MakeTopLevelHtmlForPerm.java       
 
Wed Apr  1 11:39:45 2009
@@ -306,18 +306,17 @@
      // this will contain the place holder iframes where the actual  
information
      // is going to go.

-    System.out.println("making html shell");
      // copy from the bin directory to the current directory
-    String classPath = System.getProperty("java.class.path");
+    String classPath = GlobalInformation.settings.resources.get();
+    if (classPath == null) {
+      classPath = System.getProperty("java.class.path");
+    }
      if (!classPath.endsWith("/")) {
        classPath += "/";
      }
      String inputFileName = "roundedCorners.css";
      File inputFile = new File(classPath + inputFileName);
      File outputFile = new File("roundedCorners.css");
-    System.err.println("now trying to copy inputFile |" + inputFile
-        + "| to outputFile |" + outputFile + "|, classPath is " + classPath
-        + ", inputFileName is: |" + inputFileName);
      copyFileOrDirectory(inputFile, outputFile, classPath, inputFileName,  
false);

      inputFileName = "classLevel.css";
@@ -339,6 +338,7 @@
      outFile.println("<head>");
      outFile.println("<title>Story of Your Compile - Top Level Dashboard  
for Permutation</title>");

+    outFile.println("<link rel=\"stylesheet\"  
href=\"roundedcorners.css\">");
      outFile.println("<style type=\"text/css\">");
      outFile.println("body {background-color: #728FCE}");
      outFile.println("h2 {background-color: transparent}");
@@ -419,18 +419,16 @@

      if (GlobalInformation.fragmentToStories.size() > 1) {
        outFile.println("  <div style=\"width:50%;  float:left; padding-top:  
10px;\">");
-      outFile.println("<b>Breakdown by runAsync split points</b>");
+      outFile.println("<b>Breakdown of key runAsync fragments</b>");
        outFile.println("    </div>");

        outFile.println("  <div style=\"width:100%;  float:left;  
padding-top: 10px;\">");
        outFile.println("<div style=\"width: 110px; float: left;  
font-size:16px;\">Size</div>");
-      outFile.println("<div style=\"width: 200px; float: left;  
text-align:left; font-size:16px; \">Fragment Name</div>");
+      outFile.println("<div style=\"width: 200px; float: left;  
text-align:left; font-size:16px; \">Fragment</div>");
        outFile.println("    </div>");

-      outFile.println("<div style=\"height:35%; width:100%; margin:0 auto;  
background-color:white; float:left;\">");
-      outFile.println("<iframe src=\"fragmentsBreakdown.html\" width=100%  
height=100% scrolling=auto></iframe>");
-      outFile.println("</div>");
-      makeFragmentsHtml("fragmentsBreakdown.html");
+      outFile.println("<br style=\"clear:both\">");
+      makeFragmentsHtml(outFile);
      }

      outFile.println("  </body>");
@@ -806,9 +804,7 @@
              }
            }
          }
-      }
-
-      else {
+      } else {
          String curSplitPointLocation;

          if (fragmentName == 0) {
@@ -1269,65 +1265,33 @@
      outFile.close();
    }

-  private static void makeFragmentsHtml(String outFileName) throws  
IOException {
-
-    // TreeMap<Float, Integer> sortedFragments = new TreeMap<Float,
-    // Integer>(Collections.reverseOrder());
-    TreeMap<Float, String> sortedSplitPoints = new TreeMap<Float, String>(
-        Collections.reverseOrder());
-    float maxSize = 0f;
-    float sumSize = 0f;
+  private static void makeFragmentsHtml(PrintWriter outFile) throws  
IOException {
+    int numSplitPoints = GlobalInformation.splitPointToLocation.size();

-    // initial fragment
-    float initialSize = GlobalInformation.fragmentToPartialSize.get(0);
-    sumSize += initialSize;
-    maxSize = initialSize;
-    sortedSplitPoints.put(initialSize, "initialDownload");
-
-    // all fragments that are not in the initial load order
-    float allOtherFragmentsSize =  
GlobalInformation.allOtherFragmentsPartialSize;
-    sumSize += allOtherFragmentsSize;
-    if (allOtherFragmentsSize > maxSize) {
-      maxSize = allOtherFragmentsSize;
-    }
-    sortedSplitPoints.put(allOtherFragmentsSize, "allOtherFragments");

-    // all exclusive fragments
-    System.out.println("");
-    for (Integer splitPointId :  
GlobalInformation.splitPointToLocation.keySet()) {
-      System.out.println("splitPointId is: " + splitPointId);
-      Float sizeOfCurExclusiveFrag =  
GlobalInformation.fragmentToPartialSize.get(splitPointId);
-      sortedSplitPoints.put(sizeOfCurExclusiveFrag,
-          GlobalInformation.splitPointToLocation.get(splitPointId));
-      sumSize += sizeOfCurExclusiveFrag;
-      if (sizeOfCurExclusiveFrag > maxSize) {
-        maxSize = sizeOfCurExclusiveFrag;
-      }
+    int outerHeight = 25 * (numSplitPoints + 1);
+    outFile.println("<div style=\"width:100%; margin:20px 0 20px 0;  
background-color:white;position:relative;height:"
+        + outerHeight + "\">");
+    float maxSize = 0;
+    for (int i = 0; i <= numSplitPoints; i++) {
+      maxSize += GlobalInformation.fragmentToPartialSize.get(i);
      }

-    final PrintWriter outFile = new PrintWriter(outFileName);
-
-    outFile.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"");
-    outFile.println("\"http://www.w3.org/TR/html4/strict.dtd\";>");
-    outFile.println("<html>");
-    outFile.println("<head>");
-    outFile.println("<meta http-equiv=\"content-type\"  
content=\"text/html;charset=ISO-8859-1\">");
-    outFile.println("<link rel=\"stylesheet\" href=\"roundedCorners.css\"  
media=\"screen\">");
-    outFile.println("</head>");
-    outFile.println("<body>");
-
      int yOffset = 0;
-    for (Float size : sortedSplitPoints.keySet()) {
-      String splitPointName = sortedSplitPoints.get(size);
+    for (int i = 0; i <= numSplitPoints; i++) {
+      String splitPointName = i == 0 ? "initialDownload"
+          : GlobalInformation.splitPointToLocation.get(i);
        String drillDownFileName = "splitPoint" + splitPointName  
+ "Classes.html";
+      String splitPointDescription = i == 0 ? "Initial download"
+          : ("Code exclusive to " + splitPointName);

+      float size = GlobalInformation.fragmentToPartialSize.get(i);
        float ratio = (size / maxSize) * 79;
        if (ratio < 3) {
          ratio = 3;
        }
-      float perc = (size / sumSize) * 100;

-      outFile.println("<div id=\"box\" style=\"width:" + ratio + "%; top: "
+      outFile.println("<div id=\"box\" style=\"width: " + ratio + "%;  
top: "
            + yOffset + "px; left: 110px;\">");
        outFile.println("<div id=\"lb\">");
        outFile.println("<div id=\"rb\">");
@@ -1340,20 +1304,15 @@
        outFile.println("</div>");

        int yOffsetText = yOffset + 8;
-      outFile.printf("<div class=\"barlabel\" style=\"top:" + yOffsetText
+      outFile.printf("<div class=\"barlabel\" style=\"top: " + yOffsetText
            + "px; left:5px;\">%.1f</div>\n", size);
-      outFile.printf("<div class=\"barlabel\" style=\"top:" + yOffsetText
-          + "px; left:80px;\">%.1f", perc);
-      outFile.println("%</div>\n");
-      outFile.println("<div class=\"barlabel\" style=\"top:" + yOffsetText
+      outFile.println("<div class=\"barlabel\" style=\"top: " + yOffsetText
            + "px; left:120px;\"><a href=\"" + drillDownFileName
-          + "\" target=\"_top\">" + splitPointName + "</a></div>");
+          + "\" target=\"_top\">" + splitPointDescription + "</a></div>");

        yOffset = yOffset + 25;
      }
-    outFile.println("</body>");
-    outFile.println("</html>");
-    outFile.close();
+    outFile.println("</div>");
    }

    private static void makeLiteralsHtml(String outFileName,

Added: trunk/tools/soyc-vis/src/com/google/gwt/soyc/Settings.java
==============================================================================
--- (empty file)
+++ trunk/tools/soyc-vis/src/com/google/gwt/soyc/Settings.java  Wed Apr  1  
11:39:45 2009
@@ -0,0 +1,172 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
+ * use this file except in compliance with the License. You may obtain a  
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations  
under
+ * the License.
+ */
+package com.google.gwt.soyc;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Command-line settings for SOYC.
+ */
+public class Settings {
+  /**
+   * An exception indicating that there is a problem in an argument list.
+   */
+  public static class ArgumentListException extends Exception {
+    public ArgumentListException(String message) {
+      super(message);
+    }
+  }
+
+  /**
+   * One individual setting.
+   */
+  public abstract static class Setting<T> {
+    private final String help;
+    private T value;
+
+    public Setting(T initialValue, String help) {
+      value = initialValue;
+      this.help = help;
+    }
+
+    public T get() {
+      return value;
+    }
+
+    public String getHelp() {
+      return help;
+    }
+
+    public void set(T newValue) {
+      value = newValue;
+    }
+
+    /**
+     * Consume arguments from the front of the list. If the front of the
+     * argument list is not a match, do nothing. If the front of the  
argument
+     * list is a match but has some problem, then throw an exception.
+     */
+    abstract boolean consumeArguments(List<String> arguments)
+        throws ArgumentListException;
+  }
+
+  /**
+   * A setting that is an option followed by a string argument.
+   */
+  public static class StringSetting extends Setting<String> {
+    private final String option;
+
+    public StringSetting(String option, String argumentName,
+        String defaultSetting, String description) {
+      super(defaultSetting, option + " " + argumentName + "    " +  
description);
+      this.option = option;
+    }
+
+    @Override
+    public String toString() {
+      return option + " " + get();
+    }
+
+    @Override
+    boolean consumeArguments(List<String> arguments)
+        throws ArgumentListException {
+      if (arguments.get(0).equals(option)) {
+        if (arguments.size() < 2) {
+          throw new ArgumentListException("Option " + option
+              + " requires an argument");
+        }
+        arguments.remove(0);
+        set(arguments.remove(0));
+        return true;
+      }
+
+      return false;
+    }
+  }
+
+  public static Settings fromArgumentList(String[] allArguments)
+      throws ArgumentListException {
+    Settings settings = new Settings();
+    List<String> remainingArguments = new LinkedList<String>(
+        Arrays.asList(allArguments));
+
+    // Handle hyphenated options
+    next_argument : while (!remainingArguments.isEmpty()) {
+      for (Setting<?> setting : settings.allSettings) {
+        if (setting.consumeArguments(remainingArguments)) {
+          continue next_argument;
+        }
+      }
+      break; // No setting wanted the remaining arguments
+    }
+
+    if (remainingArguments.isEmpty()) {
+      throw new ArgumentListException("Must specify the stories file");
+    }
+
+    // Handle bare arguments at the end of the list
+    if (remainingArguments.get(0).startsWith("-")) {
+      throw new ArgumentListException("Unrecognized argument: "
+          + remainingArguments.get(0));
+    }
+
+    settings.storiesFileName = remainingArguments.remove(0);
+
+    if (!remainingArguments.isEmpty()) {
+      settings.depFileName = remainingArguments.remove(0);
+    }
+    if (!remainingArguments.isEmpty()) {
+      settings.splitPointsFileName = remainingArguments.remove(0);
+    }
+
+    if (!remainingArguments.isEmpty()) {
+      throw new ArgumentListException("Too many arguments");
+    }
+
+    return settings;
+  }
+
+  public static String settingsHelp() {
+    StringBuffer help = new StringBuffer();
+    for (Setting<?> setting : new Settings().allSettings) {
+      help.append(setting.getHelp() + "\n");
+    }
+    return help.toString();
+  }
+
+  public String depFileName;
+
+  public final Setting<String> resources = addSetting(new StringSetting(
+      "-resources", "jarfile", null,
+      " directory or jar file with CSS, etc., resources"));
+
+  public String splitPointsFileName;
+
+  public String storiesFileName;
+
+  private List<Setting<?>> allSettings;
+
+  private <T> Setting<T> addSetting(Setting<T> setting) {
+    if (allSettings == null) {
+      allSettings = new ArrayList<Setting<?>>();
+    }
+    allSettings.add(setting);
+    return setting;
+  }
+}

Modified: trunk/tools/soyc-vis/src/com/google/gwt/soyc/SoycDashboard.java
==============================================================================
--- trunk/tools/soyc-vis/src/com/google/gwt/soyc/SoycDashboard.java      
(original)
+++ trunk/tools/soyc-vis/src/com/google/gwt/soyc/SoycDashboard.java     Wed  
Apr  1 11:39:45 2009
@@ -42,38 +42,20 @@
   */
  public class SoycDashboard {

-  /**
-   * @param args Input: XML file containing soyc compile output
-   * @throws IOException
-   * @throws SAXException
-   */
    public static void main(String[] args) {
-
-    String storiesFileName = "";
-    String depFileName = "";
-    String splitPointsFileName = "";
-    if ((args.length == 1) || (args.length == 2) || (args.length == 3)) {
-
-      if (args.length == 1) {
-        GlobalInformation.displayDependencies = false;
-        GlobalInformation.displaySplitPoints = true;
-      } else if (args.length == 2) {
-        GlobalInformation.displayDependencies = true;
-        GlobalInformation.displaySplitPoints = false;
-        depFileName = args[1];
-      } else if (args.length == 3) {
-        GlobalInformation.displayDependencies = true;
-        GlobalInformation.displaySplitPoints = true;
-        depFileName = args[1];
-        splitPointsFileName = args[2];
-      }
-
-    } else {
-      System.err.println("Usage: java com/google/gwt/soyc/SoycDashboard  
soyc-report0.xml[.gz] [soyc-dependencies0.xml[.gz]]  
[soyc-splitpoints0.xml[.gz]]");
+    try {
+      GlobalInformation.settings = Settings.fromArgumentList(args);
+    } catch (Settings.ArgumentListException e) {
+      System.err.println(e.getMessage());
+      System.err.println("Usage: java com.google.gwt.soyc.SoycDashboard  
[options] report0.xml[.gz] [dependencies0.xml[.gz]]  
[splitpoints0.xml[.gz]]");
+      System.err.println("Options:");
+      System.err.println(Settings.settingsHelp());
        System.exit(1);
      }

-    storiesFileName = args[0];
+    Settings settings = GlobalInformation.settings;
+    GlobalInformation.displayDependencies = (settings.depFileName != null);
+    GlobalInformation.displaySplitPoints =  
(settings.splitPointsFileName != null);

      if (GlobalInformation.displayDependencies == true) {
        /**
@@ -88,8 +70,8 @@
        depFactoryMain.setNamespaceAware(true);
        try {
          SAXParser saxParser = depFactoryMain.newSAXParser();
-        InputStream in = new FileInputStream(depFileName);
-        if (depFileName.endsWith(".gz")) {
+        InputStream in = new FileInputStream(settings.depFileName);
+        if (settings.depFileName.endsWith(".gz")) {
            in = new GZIPInputStream(in);
          }
          in = new BufferedInputStream(in);
@@ -123,8 +105,8 @@
        splitPointsFactoryMain.setNamespaceAware(true);
        try {
          SAXParser saxParser = splitPointsFactoryMain.newSAXParser();
-        InputStream in = new FileInputStream(splitPointsFileName);
-        if (depFileName.endsWith(".gz")) {
+        InputStream in = new FileInputStream(settings.splitPointsFileName);
+        if (settings.depFileName.endsWith(".gz")) {
            in = new GZIPInputStream(in);
          }
          in = new BufferedInputStream(in);
@@ -184,8 +166,8 @@
      factoryMain.setNamespaceAware(true);
      try {
        SAXParser saxParser = factoryMain.newSAXParser();
-      InputStream in = new FileInputStream(storiesFileName);
-      if (storiesFileName.endsWith(".gz")) {
+      InputStream in = new FileInputStream(settings.storiesFileName);
+      if (settings.storiesFileName.endsWith(".gz")) {
          in = new GZIPInputStream(in);
        }
        in = new BufferedInputStream(in);
@@ -293,7 +275,6 @@

      DefaultHandler handler = new DefaultHandler() {

-      int ct = 0;
        String curClassId;
        Integer curFragment;
        String curLineNumber;
@@ -433,12 +414,6 @@
        @Override
        public void startElement(String nsUri, String strippedName,
            String tagName, Attributes attributes) {
-
-        if ((ct % 10000) == 0) {
-          System.out.println(ct);
-        }
-        ct++;
-
          valueBuilder.delete(0, valueBuilder.length());

          if (strippedName.compareTo("story") == 0) {
@@ -871,9 +846,6 @@
              GlobalInformation.splitPointToLocation.put(
                  Integer.parseInt(curSplitPoint), curSplitPointLocation);
              GlobalInformation.numSplitPoints++;
-
-            System.out.println("adding split point and location: "
-                + curSplitPoint + "-->" + curSplitPointLocation);
            }
          }
        }

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to