001 package railo.runtime.debug; 002 003 import railo.runtime.PageSource; 004 import railo.runtime.op.Caster; 005 006 007 /** 008 * a single debug entry 009 */ 010 public final class DebugEntryImpl implements DebugEntry { 011 private PageSource source; 012 //private long start; 013 private int fileLoadTime; 014 private int exeTime; 015 016 //boolean isRunning; 017 private String key; 018 private int count=1; 019 private int queryTime; 020 private static int _id=1; 021 private String id; 022 023 private int max; 024 private int min=0; 025 026 /** 027 * constructor of the class 028 * @param source 029 * @param key 030 */ 031 protected DebugEntryImpl(PageSource source, String key) { 032 this.source=source; 033 this.key=key; 034 id=Caster.toString(++_id); 035 } 036 037 038 /* * 039 * @see railo.runtime.debug.DebugEntry#start() 040 * / 041 public void start() { 042 isRunning=true; 043 start=System.currentTimeMillis(); 044 }*/ 045 046 /* * 047 * @see railo.runtime.debug.DebugEntry#stop() 048 * / 049 public int stop() { 050 if(isRunning) { 051 int time=(int)(System.currentTimeMillis()-start); 052 isRunning=false; 053 return time; 054 055 } 056 return 0; 057 }*/ 058 059 /* * 060 * @see railo.runtime.debug.DebugEntry#time() 061 * / 062 public int time() { 063 if(isRunning)return (int)(System.currentTimeMillis()-start); 064 return 0; 065 }*/ 066 067 /* * 068 * @see railo.runtime.debug.DebugEntry#reset() 069 * / 070 public void reset() { 071 start=0; 072 isRunning=false; 073 }*/ 074 075 /** 076 * @see railo.runtime.debug.DebugEntry#getExeTime() 077 */ 078 public int getExeTime() { 079 return positiv(exeTime); 080 } 081 /** 082 * @see railo.runtime.debug.DebugEntry#updateExeTime(int) 083 */ 084 public void updateExeTime(int exeTime) { 085 if(exeTime>=0) { 086 if(count==1 || min>exeTime)min=exeTime; 087 if(max<exeTime)max=exeTime; 088 089 this.exeTime += exeTime; 090 } 091 } 092 /** 093 * @see railo.runtime.debug.DebugEntry#getFileLoadTime() 094 */ 095 public int getFileLoadTime() { 096 return positiv(fileLoadTime); 097 } 098 099 private int positiv(int time) { 100 if(time<0)return 0; 101 return time; 102 } 103 104 105 /** 106 * @see railo.runtime.debug.DebugEntry#updateFileLoadTime(int) 107 */ 108 public void updateFileLoadTime(int fileLoadTime) { 109 if(fileLoadTime>0)this.fileLoadTime+= fileLoadTime; 110 } 111 /** 112 * @see railo.runtime.debug.DebugEntry#updateQueryTime(int) 113 */ 114 public void updateQueryTime(int queryTime) { 115 if(queryTime>0)this.queryTime+=queryTime; 116 } 117 /** 118 * @see railo.runtime.debug.DebugEntry#getSrc() 119 */ 120 public String getSrc() { 121 return getSrc(source,key);//source.getDisplayPath()+(key==null?"":"$"+key); 122 } 123 /** 124 * @param source 125 * @param key 126 * @return Returns the src. 127 */ 128 public static String getSrc(PageSource source, String key) { 129 return 130 (source==null?"":source.getDisplayPath()) 131 + 132 (key==null?"":"$"+key); 133 } 134 135 /** 136 * increment the inner counter 137 */ 138 protected void countPP() { 139 count++; 140 141 } 142 /** 143 * @see railo.runtime.debug.DebugEntry#getCount() 144 */ 145 public int getCount() { 146 return count; 147 } 148 /** 149 * @see railo.runtime.debug.DebugEntry#getQueryTime() 150 */ 151 public int getQueryTime() { 152 return positiv(queryTime); 153 } 154 /** 155 * @see railo.runtime.debug.DebugEntry#getMax() 156 */ 157 public int getMax() { 158 return positiv(max); 159 } 160 /** 161 * @see railo.runtime.debug.DebugEntry#getMin() 162 */ 163 public int getMin() { 164 return positiv(min); 165 } 166 /** 167 * @see railo.runtime.debug.DebugEntry#resetQueryTime() 168 */ 169 public void resetQueryTime() { 170 this.queryTime=0; 171 } 172 173 174 public PageSource getPageSource() { 175 return source; 176 } 177 178 179 /** 180 * @return the id 181 */ 182 public String getId() { 183 return id; 184 } 185 }