1 21 package com.db4o; 22 23 24 27 public class DTrace { 28 29 public static final boolean enabled = false; 30 31 private static void breakPoint(){ 32 if(enabled){ } 33 } 34 35 private static final void configure(){ 36 if(enabled){ 37 38 40 42 43 44 46 addRangeWithLength(17673,1); 48 49 56 58 59 trackEventsWithoutRange(); 60 61 63 turnAllOffExceptFor(new DTrace[] {BEGIN_TOP_LEVEL_CALL, END_TOP_LEVEL_CALL}); 64 65 } 68 } 69 70 private static final Object init(){ 71 if(enabled){ 72 ADD_TO_CLASS_INDEX = new DTrace(true, true, "add to class index tree", true); 73 BEGIN_TOP_LEVEL_CALL = new DTrace(true, true, "begin top level call", true); 74 BIND = new DTrace(true, true, "bind", true); 75 BTREE_NODE_REMOVE = new DTrace(true, true, "btreenode remove", true); 76 BTREE_NODE_COMMIT_OR_ROLLBACK = new DTrace(true, true, "btreenode commit or rollback", true); 77 CANDIDATE_READ = new DTrace(true, true, "candidate read", true); 78 CLOSE = new DTrace(true, true, "close", true); 79 COLLECT_CHILDREN = new DTrace(true, true, "collect children", true); 80 COMMIT = new DTrace(false, false, "commit", true); 81 CONTINUESET = new DTrace(true, true, "continueset", true); 82 CREATE_CANDIDATE = new DTrace(true, true, "create candidate", true); 83 DELETE = new DTrace(true, true, "delete", true); 84 DONOTINCLUDE = new DTrace(true, true, "donotinclude", true); 85 END_TOP_LEVEL_CALL = new DTrace(true, true, "end top level call", true); 86 EVALUATE_SELF = new DTrace(true, true, "evaluate self", true); 87 FREE = new DTrace(true, true, "free", true); 88 FILE_FREE = new DTrace(true, true, "fileFree", true); 89 FREE_RAM = new DTrace(true, true, "freeRAM", true); 90 FREE_ON_COMMIT = new DTrace(true, true, "trans freeOnCommit", true); 91 FREE_ON_ROLLBACK = new DTrace(true, true, "trans freeOnRollback", true); 92 GET_SLOT = new DTrace(true, true, "getSlot", true); 93 GET_FREESPACE = new DTrace(true, true, "getFreespace", true); 94 GET_FREESPACE_RAM = new DTrace(true, true, "getFreespaceRam", true); 95 GET_YAPOBJECT = new DTrace(true, true, "get yapObject", true); 96 ID_TREE_ADD = new DTrace(true, true, "id tree add", true); 97 ID_TREE_REMOVE = new DTrace(true, true, "id tree remove", true); 98 IO_COPY = new DTrace(true, true, "io copy", true); 99 JUST_SET = new DTrace(true, true, "just set", true); 100 NEW_INSTANCE = new DTrace(true, true, "newInstance", true); 101 PRODUCE_SLOT_CHANGE = new DTrace(true, true, "produce slot change", true); 102 QUERY_PROCESS = new DTrace(true, true, "query process", true); 103 READ_ARRAY_WRAPPER = new DTrace(true, true, "read array wrapper", true); 104 READ_BYTES = new DTrace(true, true, "readBytes", true); 105 READ_ID = new DTrace(true, true, "read ID", true); 106 READ_SLOT = new DTrace(true, true, "read slot", true); 107 REFERENCE_REMOVED = new DTrace(true, true, "reference removed", true); 108 REGULAR_SEEK = new DTrace(true, true, "regular seek", true); 109 REMOVE_FROM_CLASS_INDEX = new DTrace(true, true, "trans removeFromClassIndexTree", true); 110 REREAD_OLD_UUID = new DTrace(true, true, "reread old uuid", true); 111 SLOT_SET_POINTER = new DTrace(true, true, "slot set pointer", true); 112 SLOT_DELETE = new DTrace(true, true, "slot delete", true); 113 SLOT_FREE_ON_COMMIT = new DTrace(true, true, "slot free on commit", true); 114 SLOT_FREE_ON_ROLLBACK_ID = new DTrace(true, true, "slot free on rollback id", true); 115 SLOT_FREE_ON_ROLLBACK_ADDRESS = new DTrace(true, true, "slot free on rollback address", true); 116 TRANS_COMMIT = new DTrace(false, false, "trans commit", false); 117 TRANS_DELETE = new DTrace(true, true, "trans delete", true); 118 TRANS_DONT_DELETE = new DTrace(true, true, "trans dontDelete", true); 119 TRANS_FLUSH = new DTrace(true, true, "trans flush", true); 120 YAPMETA_WRITE = new DTrace(true, true, "yapmeta write", true); 121 YAPCLASS_BY_ID = new DTrace(true, true, "yapclass by id", true); 122 YAPCLASS_INIT = new DTrace(true, true, "yapclass init", true); 123 YAPMETA_SET_ID = new DTrace(true, true, "yapmeta setid", true); 124 WRITE_BYTES = new DTrace(true, true, "writeBytes", true); 125 WRITE_POINTER = new DTrace(true, true, "write pointer", true); 126 WRITE_UPDATE_DELETE_MEMBERS = new DTrace(true, true, "trans writeUpdateDeleteMembers", true); 127 WRITE_XBYTES = new DTrace(true, true, "writeXBytes", true); 128 129 configure(); 130 } 131 return null; 132 } 133 134 private static void trackEventsWithoutRange() { 135 _trackEventsWithoutRange = true; 136 } 137 138 private DTrace(boolean enabled_, boolean break_, String tag_, boolean log_){ 139 if(enabled){ 140 _enabled = enabled_; 141 _break = break_; 142 _tag = tag_; 143 _log = log_; 144 if(all == null){ 145 all = new DTrace[100]; 146 } 147 all[current++] = this; 148 } 149 } 150 151 private boolean _enabled; 152 private boolean _break; 153 private boolean _log; 154 private String _tag; 155 156 private static long[] _rangeStart; 157 private static long [] _rangeEnd; 158 private static int _rangeCount; 159 160 public static long _eventNr; 161 private static long[] _breakEventNrs; 162 private static int _breakEventCount; 163 164 private static boolean _trackEventsWithoutRange; 165 166 167 public static DTrace ADD_TO_CLASS_INDEX; 168 public static DTrace BEGIN_TOP_LEVEL_CALL; 169 public static DTrace BIND; 170 public static DTrace BTREE_NODE_COMMIT_OR_ROLLBACK; 171 public static DTrace BTREE_NODE_REMOVE; 172 public static DTrace CANDIDATE_READ; 173 public static DTrace CLOSE; 174 public static DTrace COLLECT_CHILDREN; 175 public static DTrace COMMIT; 176 public static DTrace CONTINUESET; 177 public static DTrace CREATE_CANDIDATE; 178 public static DTrace DELETE; 179 public static DTrace DONOTINCLUDE; 180 public static DTrace END_TOP_LEVEL_CALL; 181 public static DTrace EVALUATE_SELF; 182 public static DTrace FILE_FREE; 183 public static DTrace FREE; 184 public static DTrace FREE_RAM; 185 public static DTrace FREE_ON_COMMIT; 186 public static DTrace FREE_ON_ROLLBACK; 187 public static DTrace GET_SLOT; 188 public static DTrace GET_FREESPACE; 189 public static DTrace GET_FREESPACE_RAM; 190 public static DTrace GET_YAPOBJECT; 191 public static DTrace ID_TREE_ADD; 192 public static DTrace ID_TREE_REMOVE; 193 public static DTrace IO_COPY; 194 public static DTrace JUST_SET; 195 public static DTrace NEW_INSTANCE; 196 public static DTrace PRODUCE_SLOT_CHANGE; 197 public static DTrace QUERY_PROCESS; 198 public static DTrace READ_ARRAY_WRAPPER; 199 public static DTrace READ_BYTES; 200 public static DTrace READ_ID; 201 public static DTrace READ_SLOT; 202 public static DTrace REFERENCE_REMOVED; 203 public static DTrace REGULAR_SEEK; 204 public static DTrace REMOVE_FROM_CLASS_INDEX; 205 public static DTrace REREAD_OLD_UUID; 206 public static DTrace SLOT_SET_POINTER; 207 public static DTrace SLOT_DELETE; 208 public static DTrace SLOT_FREE_ON_COMMIT; 209 public static DTrace SLOT_FREE_ON_ROLLBACK_ID; 210 public static DTrace SLOT_FREE_ON_ROLLBACK_ADDRESS; 211 public static DTrace TRANS_COMMIT; 212 public static DTrace TRANS_DONT_DELETE; 213 public static DTrace TRANS_DELETE; 214 public static DTrace TRANS_FLUSH; 215 public static DTrace YAPCLASS_BY_ID; 216 public static DTrace YAPCLASS_INIT; 217 public static DTrace YAPMETA_SET_ID; 218 public static DTrace YAPMETA_WRITE; 219 public static DTrace WRITE_BYTES; 220 public static DTrace WRITE_POINTER; 221 public static DTrace WRITE_XBYTES; 222 public static DTrace WRITE_UPDATE_DELETE_MEMBERS; 223 224 public static final Object forInit = init(); 225 226 private static DTrace all[]; 227 private static int current; 228 229 public void log(){ 230 if(enabled){ 231 log(-1); 232 } 233 } 234 235 public void log(long p){ 236 if(enabled){ 237 logLength(p, 1); 238 } 239 } 240 241 public void logInfo(String info){ 242 if(enabled){ 243 logEnd(-1,0, info ); 244 } 245 } 246 247 public void log(long p, String info){ 248 if(enabled){ 249 logEnd(p, 0, info); 250 } 251 252 } 253 254 public void logLength(long start, long length){ 255 if(enabled){ 256 logEnd(start, start + length - 1); 257 } 258 } 259 260 public void logEnd(long start, long end){ 261 if(enabled){ 262 logEnd(start, end, null); 263 } 264 } 265 266 public void logEnd(long start, long end, String info){ 267 if(enabled){ 268 if(! _enabled){ 269 return; 270 } 271 boolean inRange = false; 272 273 if(_rangeCount == 0){ 274 inRange = true; 275 } 276 277 for (int i = 0; i < _rangeCount; i++) { 278 279 if(start >= _rangeStart[i] && start <= _rangeEnd[i]){ 281 inRange = true; 282 break; 283 } 284 285 if(end != 0){ 286 287 if (end >= _rangeStart[i] && end <= _rangeEnd[i]){ 289 inRange = true; 290 break; 291 } 292 293 if(start <= _rangeStart[i] && end >= _rangeEnd[i]){ 295 inRange = true; 296 break; 297 } 298 } 299 } 300 if(inRange || ( _trackEventsWithoutRange && (start == -1) )){ 301 if(_log){ 302 _eventNr ++; 303 StringBuffer sb = new StringBuffer (":"); 304 sb.append(formatInt(_eventNr, 6)); 305 sb.append(":"); 306 if(start != 0){ 307 sb.append(formatInt(start)); 308 sb.append(":"); 309 } 310 if(end != 0 && start != end){ 311 sb.append(formatInt(end)); 312 sb.append(":"); 313 sb.append(formatInt(end - start + 1)); 314 }else{ 315 sb.append(formatInt(0)); 316 } 317 sb.append(":"); 318 if(info != null){ 319 sb.append(" " + info + " "); 320 sb.append(":"); 321 } 322 sb.append(" "); 323 sb.append(_tag); 324 System.out.println(sb); 325 } 326 if(_break){ 327 if(_breakEventCount > 0){ 328 for (int i = 0; i < _breakEventCount; i++) { 329 if(_breakEventNrs[i] == _eventNr){ 330 breakPoint(); 331 break; 332 } 333 } 334 }else{ 335 breakPoint(); 336 } 337 } 338 } 339 } 340 } 341 342 public static void addRange(long pos){ 343 if(enabled){ 344 addRangeWithEnd(pos, pos); 345 } 346 } 347 348 public static void addRangeWithLength(long start, long length){ 349 if(enabled){ 350 addRangeWithEnd(start, start + length - 1); 351 } 352 } 353 354 public static void addRangeWithEnd(long start, long end){ 355 if(enabled){ 356 if(_rangeStart == null){ 357 _rangeStart = new long[100]; 358 _rangeEnd = new long[100]; 359 } 360 _rangeStart[_rangeCount] = start; 361 _rangeEnd[_rangeCount] = end; 362 _rangeCount++; 363 } 364 } 365 366 private static void breakOnEvent(long eventNr){ 367 if(enabled){ 368 if(_breakEventNrs == null){ 369 _breakEventNrs = new long[100]; 370 } 371 _breakEventNrs[_breakEventCount] = eventNr; 372 _breakEventCount ++; 373 } 374 } 375 376 377 private String formatInt(long i, int len){ 378 if(enabled){ 379 String str = " "; 380 if( i != 0){ 381 str += i + " "; 382 } 383 return str.substring(str.length() - len); 384 } 385 return null; 386 } 387 388 private String formatInt(long i){ 389 if(enabled){ 390 return formatInt(i, 10); 391 } 392 return null; 393 } 394 395 private static void turnAllOffExceptFor(DTrace[] these){ 396 if(enabled){ 397 for (int i = 0; i < all.length; i++) { 398 if(all[i] == null){ 399 break; 400 } 401 boolean turnOff = true; 402 for (int j = 0; j < these.length; j++) { 403 if(all[i] == these[j]){ 404 turnOff = false; 405 break; 406 } 407 } 408 if(turnOff){ 409 all[i]._break = false; 410 all[i]._enabled = false; 411 all[i]._log = false; 412 } 413 } 414 } 415 } 416 417 public static void noWarnings(){ 418 breakOnEvent(0); 419 trackEventsWithoutRange(); 420 } 421 422 } 423 | Popular Tags |