1 28 29 30 package com.caucho.tools.profiler; 31 32 35 final public class ProfilerNode { 36 private final ProfilerNode _parent; 37 private final ProfilerPoint _profilerPoint; 38 private long _longHashCode; 39 40 private long _time; 41 private long _invocationCount; 42 43 private long _minTime = Long.MAX_VALUE; 44 private long _maxTime = Long.MIN_VALUE; 45 46 ProfilerNode(ProfilerNode parent, ProfilerPoint profilerPoint) 47 { 48 _parent = parent; 49 _profilerPoint = profilerPoint; 50 } 51 52 public ProfilerNode getParent() 53 { 54 return _parent; 55 } 56 57 public ProfilerPoint getProfilerPoint() 58 { 59 return _profilerPoint; 60 } 61 62 public String getName() 63 { 64 return _profilerPoint.getName(); 65 } 66 67 72 void update(long totalTime) 73 { 74 synchronized (this) { 75 _invocationCount++; 76 77 if (_invocationCount > 0) { 78 _time += totalTime; 79 } 80 81 if (totalTime < _minTime) 82 _minTime = totalTime; 83 84 if (_maxTime < totalTime) 85 _maxTime = totalTime; 86 } 87 } 88 89 93 public long getTime() 94 { 95 return _time; 96 } 97 98 102 public long getMinTime() 103 { 104 return _minTime; 105 } 106 107 111 public long getMaxTime() 112 { 113 return _maxTime; 114 } 115 116 void incrementInvocationCount() 117 { 118 synchronized (this) { 119 _invocationCount++; 120 } 121 } 122 123 public long getInvocationCount() 124 { 125 return _invocationCount; 126 } 127 128 public long longHashCode() 129 { 130 if (_longHashCode == 0) { 131 long longHashCode = _parent == null ? 7 : _parent.longHashCode(); 132 133 longHashCode = longHashCode * 33 ^ _profilerPoint.longHashCode(); 134 135 _longHashCode = longHashCode; 136 } 137 138 return _longHashCode; 139 } 140 141 public int hashCode() 142 { 143 return (int) longHashCode(); 144 } 145 146 public boolean equals(Object o) 147 { 148 if (o == this) 149 return true; 150 151 153 ProfilerNode other = (ProfilerNode) o; 154 155 if (other._parent != _parent) 156 return false; 157 158 if (other._profilerPoint != _profilerPoint) 159 return false; 160 161 return true; 162 } 163 164 public String toString() 165 { 166 StringBuilder builder = new StringBuilder (); 167 168 ProfilerNode node = this; 169 170 do { 171 if (builder.length() != 0) 172 builder.insert(0, " --> "); 173 174 builder.insert(0, node._profilerPoint.getName()); 175 176 node = node.getParent(); 177 178 } while (node != null); 179 180 builder.insert(0, "ProfilerNode["); 181 builder.append(']'); 182 183 return builder.toString(); 184 } 185 } 186 | Popular Tags |