1 8 9 package com.sleepycat.je.utilint; 10 11 12 17 public class EventTrace { 18 static private int MAX_EVENTS = 100; 19 20 static public final boolean TRACE_EVENTS = false; 21 22 static int currentEvent = 0; 23 24 static final EventTrace[] events = new EventTrace[MAX_EVENTS]; 25 static final int[] threadIdHashes = new int[MAX_EVENTS]; 26 static boolean disableEvents = false; 27 28 protected String comment; 29 30 public EventTrace(String comment) { 31 this.comment = comment; 32 } 33 34 public EventTrace() { 35 comment = null; 36 } 37 38 public String toString() { 39 return comment; 40 } 41 42 static public void addEvent(EventTrace event) { 43 if (disableEvents) { 44 return; 45 } 46 int nextEventIdx = currentEvent++ % MAX_EVENTS; 47 events[nextEventIdx] = event; 48 threadIdHashes[nextEventIdx] = 49 System.identityHashCode(Thread.currentThread()); 50 } 51 52 static public void addEvent(String comment) { 53 if (disableEvents) { 54 return; 55 } 56 addEvent(new EventTrace(comment)); 57 } 58 59 static public void dumpEvents() { 60 if (disableEvents) { 61 return; 62 } 63 System.out.println("----- Event Dump -----"); 64 EventTrace[] oldEvents = events; 65 int[] oldThreadIdHashes = threadIdHashes; 66 disableEvents = true; 67 68 int j = 0; 69 for (int i = currentEvent; j < MAX_EVENTS; i++) { 70 EventTrace ev = oldEvents[i % MAX_EVENTS]; 71 if (ev != null) { 72 int thisEventIdx = i % MAX_EVENTS; 73 System.out.print(oldThreadIdHashes[thisEventIdx] + " "); 74 System.out.println(j + "(" + thisEventIdx + "): " + ev); 75 } 76 j++; 77 } 78 } 79 80 static public class ExceptionEventTrace extends EventTrace { 81 private Exception event; 82 83 public ExceptionEventTrace() { 84 event = new Exception (); 85 } 86 87 public String toString() { 88 return Tracer.getStackTrace(event); 89 } 90 } 91 } 92 93 143 144 145 172 246 268 287 314 315 316 | Popular Tags |