You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/08/21 17:49:14 UTC

svn commit: r687786 - in /xmlgraphics/fop/trunk/test/java/org/apache/fop/memory: MemoryEater.java Stats.java

Author: jeremias
Date: Thu Aug 21 08:49:13 2008
New Revision: 687786

URL: http://svn.apache.org/viewvc?rev=687786&view=rev
Log:
Added some performance statistics to MemoryEater.

Added:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/Stats.java   (with props)
Modified:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/MemoryEater.java

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/MemoryEater.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/MemoryEater.java?rev=687786&r1=687785&r2=687786&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/MemoryEater.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/MemoryEater.java Thu Aug 21 08:49:13 2008
@@ -34,6 +34,7 @@
 import javax.xml.transform.sax.SAXTransformerFactory;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.NullOutputStream;
 
 import org.apache.fop.apps.FOUserAgent;
@@ -51,28 +52,46 @@
     private FopFactory fopFactory = FopFactory.newInstance();
     private Templates replicatorTemplates;
 
+    private Stats stats = new Stats();
+
     public MemoryEater() throws TransformerConfigurationException, MalformedURLException {
         File xsltFile = new File("test/xsl/fo-replicator.xsl");
         Source xslt = new StreamSource(xsltFile);
         replicatorTemplates = tFactory.newTemplates(xslt);
     }
 
-    private void eatMemory(File foFile, int replicatorRepeats) throws Exception {
+    private void eatMemory(File foFile, int runRepeats, int replicatorRepeats) throws Exception {
+        for (int i = 0; i < runRepeats; i++) {
+            eatMemory(i, foFile, replicatorRepeats);
+            stats.progress(i, runRepeats);
+        }
+        System.out.println(stats.getGoogleChartURL());
+    }
+
+    private void eatMemory(int callIndex, File foFile, int replicatorRepeats) throws Exception {
         Source src = new StreamSource(foFile);
 
         Transformer transformer = replicatorTemplates.newTransformer();
         transformer.setParameter("repeats", new Integer(replicatorRepeats));
 
         OutputStream out = new NullOutputStream(); //write to /dev/nul
-        FOUserAgent userAgent = fopFactory.newFOUserAgent();
-        userAgent.setBaseURL(foFile.getParentFile().toURL().toExternalForm());
-        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out);
-        Result res = new SAXResult(fop.getDefaultHandler());
-
-        transformer.transform(src, res);
-
-        System.out.println("Generated " + fop.getResults().getPageCount() + " pages.");
-
+        try {
+            FOUserAgent userAgent = fopFactory.newFOUserAgent();
+            userAgent.setBaseURL(foFile.getParentFile().toURL().toExternalForm());
+            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out);
+            Result res = new SAXResult(fop.getDefaultHandler());
+
+            transformer.transform(src, res);
+
+            stats.notifyPagesProduced(fop.getResults().getPageCount());
+            if (callIndex == 0) {
+                System.out.println(foFile.getName() + " generates "
+                        + fop.getResults().getPageCount() + " pages.");
+            }
+            stats.checkStats();
+        } finally {
+            IOUtils.closeQuietly(out);
+        }
     }
 
     private static void prompt() throws IOException {
@@ -108,9 +127,7 @@
             long start = System.currentTimeMillis();
 
             MemoryEater app = new MemoryEater();
-            for (int i = 0; i < runRepeats; i++) {
-                app.eatMemory(testFile, replicatorRepeats);
-            }
+            app.eatMemory(testFile, runRepeats, replicatorRepeats);
 
             long duration = System.currentTimeMillis() - start;
             System.out.println("Success! Job took " + duration + " ms");

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/Stats.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/Stats.java?rev=687786&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/Stats.java (added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/Stats.java Thu Aug 21 08:49:13 2008
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.memory;
+
+import java.util.Iterator;
+import java.util.List;
+
+class Stats {
+
+    private static final int INTERVAL = 2000;
+
+    private long lastProgressDump = System.currentTimeMillis();
+    private int pagesProduced;
+
+    private int step;
+    private int stepCount;
+
+    private List samples = new java.util.LinkedList();
+
+    public void checkStats() {
+        long now = System.currentTimeMillis();
+        if (now > lastProgressDump + INTERVAL) {
+            dumpStats();
+            reset();
+        }
+    }
+
+    public void notifyPagesProduced(int count) {
+        pagesProduced += count;
+    }
+
+    public void reset() {
+        pagesProduced = 0;
+        lastProgressDump = System.currentTimeMillis();
+    }
+
+    public void dumpStats() {
+        long duration = System.currentTimeMillis() - lastProgressDump;
+
+        if (stepCount != 0) {
+            int progress = 100 * step / stepCount;
+            System.out.println("Progress: " + progress + "%, " + (stepCount - step) + " left");
+        }
+
+        long ppm = 60000 * pagesProduced / duration;
+        System.out.println("Speed: " + ppm + "ppm");
+        samples.add(new Sample((int)ppm));
+    }
+
+    public String getGoogleChartURL() {
+        StringBuffer sb = new StringBuffer("http://chart.apis.google.com/chart?");
+        //http://chart.apis.google.com/chart?cht=ls&chd=t:60,40&chs=250x100&chl=Hello|World
+        sb.append("cht=ls");
+        sb.append("&chd=t:");
+        boolean first = true;
+        int maxY = 0;
+        Iterator iter = samples.iterator();
+        while (iter.hasNext()) {
+            Sample sample = (Sample)iter.next();
+            if (first) {
+                first = false;
+            } else {
+                sb.append(',');
+            }
+            sb.append(sample.ppm);
+            maxY = Math.max(maxY, sample.ppm);
+        }
+        int ceilY = ((maxY / 1000) + 1) * 1000;
+        sb.append("&chs=1000x300"); //image size
+        sb.append("&chds=0,").append(ceilY); //data scale
+        sb.append("&chg=0,20"); //scale steps
+        sb.append("&chxt=y");
+        sb.append("&chxl=0:|0|" + ceilY);
+        return sb.toString();
+    }
+
+    private static class Sample {
+
+        private int ppm;
+
+        public Sample(int ppm) {
+            this.ppm = ppm;
+        }
+    }
+
+    public void progress(int step, int stepCount) {
+        this.step = step;
+        this.stepCount = stepCount;
+
+    }
+
+}

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/Stats.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/memory/Stats.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org