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.runtime.PageSource; 022import lucee.runtime.op.Caster; 023 024public abstract class DebugEntrySupport implements DebugEntry { 025 026 private static final long serialVersionUID = -2495816599745340388L; 027 028 private static int _id=1; 029 private String id; 030 031 private long exeTime; 032 private String path; 033 private int count=1; 034 private long min=0; 035 private long max=0; 036 037 038 /** 039 * constructor of the class 040 * @param source 041 * @param key 042 */ 043 protected DebugEntrySupport(PageSource source) { 044 this.path=source==null?"":source.getDisplayPath(); 045 id=Caster.toString(++_id); 046 } 047 048 049 @Override 050 public long getExeTime() { 051 return positiv(exeTime); 052 } 053 054 @Override 055 public void updateExeTime(long exeTime) { 056 if(exeTime>=0) { 057 if(count==1 || min>exeTime)min=exeTime; 058 if(max<exeTime)max=exeTime; 059 060 this.exeTime += exeTime; 061 } 062 } 063 064 @Override 065 public String getPath() { 066 return path; 067 } 068 069 @Override 070 public String getId() { 071 return id; 072 } 073 074 /** 075 * increment the inner counter 076 */ 077 protected void countPP() { 078 count++; 079 080 } 081 082 @Override 083 public int getCount() { 084 return count; 085 } 086 087 @Override 088 public long getMax() { 089 return positiv(max); 090 } 091 092 @Override 093 public long getMin() { 094 return positiv(min); 095 } 096 097 protected long positiv(long time) { 098 if(time<0)return 0; 099 return time; 100 } 101 102}