001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.debug;
020
021import lucee.commons.io.res.Resource;
022import lucee.runtime.PageContext;
023import lucee.runtime.dump.DumpData;
024import lucee.runtime.dump.DumpProperties;
025import lucee.runtime.dump.DumpTable;
026import lucee.runtime.dump.Dumpable;
027import lucee.runtime.dump.SimpleDumpData;
028
029/**
030 *
031 *
032 * To change the template for this generated type comment go to
033 * Window - Preferences - Java - Code Generation - Code and Comments
034 */
035public final class DebugPageImpl implements Dumpable, DebugPage {
036
037        private int count;
038        private Resource file;
039
040        private int min;
041        private int max;
042        private int all;
043        private long time;
044        
045        //private long time;
046
047        /**
048         * @param file
049         */
050        public DebugPageImpl(Resource file) {
051                this.file=file;
052        }
053
054        @Override
055        public void set(long t) {
056                this.time=t;
057                if(count==0) {
058                        min=(int) time;
059                        max=(int) time;
060                }
061                else {
062                        if(min>time)min=(int) time;
063                        if(max<time)max=(int) time;
064                }
065                all+=time;
066                
067                count++;
068        }
069        
070        
071        @Override
072        public int getMinimalExecutionTime() {
073                return min;
074        }
075
076        @Override
077        public int getMaximalExecutionTime() {
078                return max;
079        }
080        
081        @Override
082        public int getAverageExecutionTime() {
083                return all/count;
084        }
085        
086        @Override
087        public int getCount() {
088                return count;
089        }
090        
091        @Override
092        public Resource getFile() {
093                return file;
094        }
095
096        @Override
097        public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
098                DumpTable table=new DumpTable("#cccc66","#cccc99","#000000");
099                table.setTitle(file.getAbsolutePath());
100                table.appendRow(1, new SimpleDumpData("min (ms)"), new SimpleDumpData(min));
101                table.appendRow(1, new SimpleDumpData("avg (ms)"), new SimpleDumpData(getAverageExecutionTime()));
102                table.appendRow(1, new SimpleDumpData("max (ms)"), new SimpleDumpData(max));
103                table.appendRow(1, new SimpleDumpData("total (ms)"), new SimpleDumpData(all));
104                return table;
105        }
106        
107}