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            @Override
037            public void set(long t) {
038                    this.time=t;
039                    if(count==0) {
040                            min=(int) time;
041                            max=(int) time;
042                    }
043                    else {
044                            if(min>time)min=(int) time;
045                            if(max<time)max=(int) time;
046                    }
047                    all+=time;
048                    
049                    count++;
050            }
051            
052            
053            @Override
054            public int getMinimalExecutionTime() {
055                    return min;
056            }
057    
058            @Override
059            public int getMaximalExecutionTime() {
060                    return max;
061            }
062            
063            @Override
064            public int getAverageExecutionTime() {
065                    return all/count;
066            }
067            
068            @Override
069            public int getCount() {
070                    return count;
071            }
072            
073            @Override
074            public Resource getFile() {
075                    return file;
076            }
077    
078            @Override
079            public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
080                    DumpTable table=new DumpTable("#cccc66","#cccc99","#000000");
081                    table.setTitle(file.getAbsolutePath());
082                    table.appendRow(1, new SimpleDumpData("min (ms)"), new SimpleDumpData(min));
083                    table.appendRow(1, new SimpleDumpData("avg (ms)"), new SimpleDumpData(getAverageExecutionTime()));
084                    table.appendRow(1, new SimpleDumpData("max (ms)"), new SimpleDumpData(max));
085                    table.appendRow(1, new SimpleDumpData("total (ms)"), new SimpleDumpData(all));
086                    return table;
087            }
088            
089    }