Cleaner resource leak report by excluding noisy stack trace elements
This commit is contained in:
parent
293e34e13f
commit
0bf5ca22cb
@ -259,13 +259,13 @@ public final class ResourceLeakDetector<T> {
|
||||
private DefaultResourceLeak prev;
|
||||
private DefaultResourceLeak next;
|
||||
|
||||
public DefaultResourceLeak(Object referent) {
|
||||
DefaultResourceLeak(Object referent) {
|
||||
super(referent, referent != null? refQueue : null);
|
||||
|
||||
if (referent != null) {
|
||||
Level level = getLevel();
|
||||
if (level.ordinal() >= Level.ADVANCED.ordinal()) {
|
||||
creationRecord = newRecord();
|
||||
creationRecord = newRecord(3);
|
||||
} else {
|
||||
creationRecord = null;
|
||||
}
|
||||
@ -288,7 +288,7 @@ public final class ResourceLeakDetector<T> {
|
||||
@Override
|
||||
public void record() {
|
||||
if (creationRecord != null) {
|
||||
String value = newRecord();
|
||||
String value = newRecord(2);
|
||||
|
||||
synchronized (lastRecords) {
|
||||
int size = lastRecords.size();
|
||||
@ -352,17 +352,33 @@ public final class ResourceLeakDetector<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private static String newRecord() {
|
||||
private static final String[] STACK_TRACE_ELEMENT_EXCLUSIONS = {
|
||||
"io.netty.buffer.AbstractByteBufAllocator.toLeakAwareBuffer(",
|
||||
};
|
||||
|
||||
static String newRecord(int recordsToSkip) {
|
||||
StringBuilder buf = new StringBuilder(4096);
|
||||
StackTraceElement[] array = new Throwable().getStackTrace();
|
||||
int recordsToSkip = 3;
|
||||
for (StackTraceElement e: array) {
|
||||
if (recordsToSkip > 0) {
|
||||
recordsToSkip --;
|
||||
} else {
|
||||
buf.append('\t');
|
||||
buf.append(e.toString());
|
||||
buf.append(NEWLINE);
|
||||
String estr = e.toString();
|
||||
|
||||
// Strip the noisy stack trace elements.
|
||||
boolean excluded = false;
|
||||
for (String exclusion: STACK_TRACE_ELEMENT_EXCLUSIONS) {
|
||||
if (estr.startsWith(exclusion)) {
|
||||
excluded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!excluded) {
|
||||
buf.append('\t');
|
||||
buf.append(estr);
|
||||
buf.append(NEWLINE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user