cvs commit: xml-fop/src/org/apache/fop/apps LayoutHandler.java
olegt 2002/12/18 15:09:28 Modified:src/org/apache/fop/apps LayoutHandler.java Log: Cleaned up unused imports, made collection of the statistics optional. Revision ChangesPath 1.9 +39 -39xml-fop/src/org/apache/fop/apps/LayoutHandler.java Index: LayoutHandler.java === RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/LayoutHandler.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- LayoutHandler.java9 Dec 2002 11:22:35 - 1.8 +++ LayoutHandler.java18 Dec 2002 23:09:28 - 1.9 @@ -7,42 +7,43 @@ package org.apache.fop.apps; +// Java import java.io.OutputStream; import java.io.IOException; -import java.util.HashSet; import java.util.List; +// SAX import org.xml.sax.SAXException; +// FOP import org.apache.fop.layout.FontInfo; -import org.apache.fop.area.PageViewport; import org.apache.fop.area.AreaTree; -import org.apache.fop.area.CachedRenderPagesModel; import org.apache.fop.area.Title; import org.apache.fop.area.TreeExt; import org.apache.fop.render.Renderer; import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fo.pagination.LayoutMasterSet; -import org.apache.avalon.framework.logger.Logger; - /** * Layout handler that receives the structure events. * This initiates layout processes and corresponding * rendering processes such as start/end. */ public class LayoutHandler extends StructureHandler { -private static final boolean MEM_PROFILE_WITH_GC = false; + +// TODO: Collecting of statistics should be configurable +private final boolean collectStatistics = true; +private final boolean MEM_PROFILE_WITH_GC = false; /** Somewhere to get our stats from. */ -private Runtime runtime = Runtime.getRuntime(); +private Runtime runtime; /** Keep track of the number of pages rendered. */ -int pageCount = 0; +private int pageCount; /** Keep track of heap memory allocated, @@ -87,6 +88,8 @@ */ public LayoutHandler(OutputStream outputStream, Renderer renderer, boolean store) { +if (collectStatistics) +runtime = Runtime.getRuntime(); this.outputStream = outputStream; this.renderer = renderer; @@ -112,15 +115,15 @@ * @throws SAXException if there is an error */ public void startDocument() throws SAXException { -pageCount = 0; - -if (MEM_PROFILE_WITH_GC) { -System.gc(); // This takes time but gives better results +//Initialize statistics +if (collectStatistics) { +pageCount = 0; +if (MEM_PROFILE_WITH_GC) { +System.gc(); // This takes time but gives better results +} +initialMemory = runtime.totalMemory() - runtime.freeMemory(); +startTime = System.currentTimeMillis(); } - -initialMemory = runtime.totalMemory() - runtime.freeMemory(); -startTime = System.currentTimeMillis(); - try { renderer.setupFontInfo(fontInfo); // check that the any,normal,400 font exists @@ -147,30 +150,27 @@ throw new SAXException(e); } -if (getLogger().isDebugEnabled()) { +if (collectStatistics) { if (MEM_PROFILE_WITH_GC) { // This takes time but gives better results System.gc(); } - long memoryNow = runtime.totalMemory() - runtime.freeMemory(); long memoryUsed = (memoryNow - initialMemory) / 1024L; -getLogger().debug(Initial heap size: + (initialMemory / 1024L) + Kb); -getLogger().debug(Current heap size: + (memoryNow / 1024L) + Kb); -getLogger().debug(Total memory used: + memoryUsed + Kb); - -if (!MEM_PROFILE_WITH_GC) { -getLogger().debug( Memory use is indicative; no GC was performed); -getLogger().debug( These figures should not be used comparatively); -} -} - -if (getLogger().isDebugEnabled()) { long timeUsed = System.currentTimeMillis() - startTime; -getLogger().debug(Total time used: + timeUsed + ms); -getLogger().debug(Pages rendered: + pageCount); -if (pageCount 0) { -getLogger().debug(Avg render time: + (timeUsed / pageCount) + ms/page); +if (getLogger().isDebugEnabled()) { +getLogger().debug(Initial heap size: + (initialMemory / 1024L) + Kb); +getLogger().debug(Current heap size:
cvs commit: xml-fop/src/org/apache/fop/apps LayoutHandler.java
keiron 2002/12/09 03:22:35 Modified:src/org/apache/fop/apps LayoutHandler.java Log: added some comments and changed debugging a bit Revision ChangesPath 1.8 +63 -20xml-fop/src/org/apache/fop/apps/LayoutHandler.java Index: LayoutHandler.java === RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/LayoutHandler.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- LayoutHandler.java25 Oct 2002 09:29:39 - 1.7 +++ LayoutHandler.java9 Dec 2002 11:22:35 - 1.8 @@ -96,10 +96,21 @@ areaTree.setTreeModel(atModel); } +/** + * Get the area tree for this layout handler. + * + * @return the area tree for this document + */ public AreaTree getAreaTree() { return areaTree; } +/** + * Start the document. + * This starts the document in the renderer. + * + * @throws SAXException if there is an error + */ public void startDocument() throws SAXException { pageCount = 0; @@ -122,6 +133,11 @@ } } +/** + * End the document. + * + * @throws SAXException if there is some error + */ public void endDocument() throws SAXException { try { //processAreaTree(atModel); @@ -131,14 +147,14 @@ throw new SAXException(e); } -if (MEM_PROFILE_WITH_GC) { -System.gc(); // This takes time but gives better results -} - -long memoryNow = runtime.totalMemory() - runtime.freeMemory(); -long memoryUsed = (memoryNow - initialMemory) / 1024L; - if (getLogger().isDebugEnabled()) { +if (MEM_PROFILE_WITH_GC) { +// This takes time but gives better results +System.gc(); +} + +long memoryNow = runtime.totalMemory() - runtime.freeMemory(); +long memoryUsed = (memoryNow - initialMemory) / 1024L; getLogger().debug(Initial heap size: + (initialMemory / 1024L) + Kb); getLogger().debug(Current heap size: + (memoryNow / 1024L) + Kb); getLogger().debug(Total memory used: + memoryUsed + Kb); @@ -149,9 +165,8 @@ } } -long timeUsed = System.currentTimeMillis() - startTime; - if (getLogger().isDebugEnabled()) { +long timeUsed = System.currentTimeMillis() - startTime; getLogger().debug(Total time used: + timeUsed + ms); getLogger().debug(Pages rendered: + pageCount); if (pageCount 0) { @@ -160,6 +175,15 @@ } } +/** + * Start a page sequence. + * At the start of a page sequence it can start the page sequence + * on the area tree with the page sequence title. + * + * @param pageSeq the page sequence starting + * @param seqTitle the title of the page sequence + * @param lms the layout master set + */ public void startPageSequence(PageSequence pageSeq, org.apache.fop.fo.Title seqTitle, LayoutMasterSet lms) { Title title = null; if (seqTitle != null) { @@ -169,24 +193,38 @@ } /** - Format the PageSequence. The PageSequence - formats Pages and adds them to the AreaTree, - which subsequently calls the StreamRenderer - instance (this) again to render the page. - At this time the page might be printed - or it might be queued. A page might not - be renderable immediately if the IDReferences - are not all valid. In this case we defer - the rendering until they are all valid. + * End the PageSequence. + * The PageSequence formats Pages and adds them to the AreaTree. + * The area tree then handles what happens with the pages. + * + * @param pageSequence the page sequence ending + * @throws FOPException if there is an error formatting the pages */ public void endPageSequence(PageSequence pageSequence) throws FOPException { //areaTree.setFontInfo(fontInfo); +if (getLogger().isDebugEnabled()) { +if (MEM_PROFILE_WITH_GC) { +// This takes time but gives better results +System.gc(); +} + +long memoryNow = runtime.totalMemory() - runtime.freeMemory(); +getLogger().debug(Current heap size: + (memoryNow / 1024L) + Kb); +} + pageSequence.format(areaTree); } - +/** + * Process an area tree. + * If a store pages model is used this can read and send all the + * pages to the renderer. + * + * @param