001    package railo.runtime.debug;
002    
003    import railo.commons.io.res.Resource;
004    import railo.runtime.PageContext;
005    import railo.runtime.dump.DumpData;
006    import railo.runtime.dump.DumpProperties;
007    import railo.runtime.dump.DumpTable;
008    import railo.runtime.dump.Dumpable;
009    import railo.runtime.dump.SimpleDumpData;
010    
011    /**
012     *
013     *
014     * To change the template for this generated type comment go to
015     * Window - Preferences - Java - Code Generation - Code and Comments
016     */
017    public final class DebugPageImpl implements Dumpable, DebugPage {
018    
019            private int count;
020            private Resource file;
021    
022            private int min;
023            private int max;
024            private int all;
025            private long time;
026            
027            //private long time;
028    
029            /**
030             * @param file
031             */
032            public DebugPageImpl(Resource file) {
033                    this.file=file;
034            }
035    
036            /**
037         * @see railo.runtime.debug.DebugPage#set(long)
038         */
039            public void set(long t) {
040                    this.time=t;
041                    if(count==0) {
042                            min=(int) time;
043                            max=(int) time;
044                    }
045                    else {
046                            if(min>time)min=(int) time;
047                            if(max<time)max=(int) time;
048                    }
049                    all+=time;
050                    
051                    count++;
052            }
053            
054            
055            /**
056         * @see railo.runtime.debug.DebugPage#getMinimalExecutionTime()
057         */
058            public int getMinimalExecutionTime() {
059                    return min;
060            }
061    
062            /**
063         * @see railo.runtime.debug.DebugPage#getMaximalExecutionTime()
064         */
065            public int getMaximalExecutionTime() {
066                    return max;
067            }
068            
069            /**
070         * @see railo.runtime.debug.DebugPage#getAverageExecutionTime()
071         */
072            public int getAverageExecutionTime() {
073                    return all/count;
074            }
075            
076            /**
077         * @see railo.runtime.debug.DebugPage#getCount()
078         */
079            public int getCount() {
080                    return count;
081            }
082            
083            /**
084         * @see railo.runtime.debug.DebugPage#getFile()
085         */
086            public Resource getFile() {
087                    return file;
088            }
089    
090            /**
091             * @see railo.runtime.dump.Dumpable#toDumpData(railo.runtime.PageContext, int)
092             */
093            public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
094                    DumpTable table=new DumpTable("#cccc66","#cccc99","#000000");
095                    table.setTitle(file.getAbsolutePath());
096                    table.appendRow(1, new SimpleDumpData("min (ms)"), new SimpleDumpData(min));
097                    table.appendRow(1, new SimpleDumpData("avg (ms)"), new SimpleDumpData(getAverageExecutionTime()));
098                    table.appendRow(1, new SimpleDumpData("max (ms)"), new SimpleDumpData(max));
099                    table.appendRow(1, new SimpleDumpData("total (ms)"), new SimpleDumpData(all));
100                    return table;
101            }
102            
103    }