LockAgent: Refactor violation data
Start to make violation less opaque to improve more generic handling in the future. Test: m Test: manual Change-Id: Ic9780590301010798c7fe6df59526e609dc6f93a
This commit is contained in:
@@ -66,7 +66,8 @@ public class LockHook {
|
||||
|
||||
static final StatLogger sStats = new StatLogger(new String[] { "on-thread", });
|
||||
|
||||
private static final ConcurrentLinkedQueue<Object> sViolations = new ConcurrentLinkedQueue<>();
|
||||
private static final ConcurrentLinkedQueue<Violation> sViolations =
|
||||
new ConcurrentLinkedQueue<>();
|
||||
private static final int MAX_VIOLATIONS = 50;
|
||||
|
||||
private static final LockChecker[] sCheckers;
|
||||
@@ -101,8 +102,8 @@ public class LockHook {
|
||||
}
|
||||
}
|
||||
|
||||
static void wtf(String message) {
|
||||
sHandler.wtf(message);
|
||||
static void wtf(Violation v) {
|
||||
sHandler.wtf(v);
|
||||
}
|
||||
|
||||
static void doCheckOnThisThread(boolean check) {
|
||||
@@ -151,10 +152,10 @@ public class LockHook {
|
||||
super(looper);
|
||||
}
|
||||
|
||||
public void wtf(String msg) {
|
||||
public void wtf(Violation v) {
|
||||
sDoCheck.set(false);
|
||||
SomeArgs args = SomeArgs.obtain();
|
||||
args.arg1 = msg;
|
||||
args.arg1 = v;
|
||||
obtainMessage(MSG_WTF, args).sendToTarget();
|
||||
sDoCheck.set(true);
|
||||
}
|
||||
@@ -164,13 +165,18 @@ public class LockHook {
|
||||
switch (msg.what) {
|
||||
case MSG_WTF:
|
||||
SomeArgs args = (SomeArgs) msg.obj;
|
||||
Log.wtf(TAG, (String) args.arg1);
|
||||
handleViolation((Violation) args.arg1);
|
||||
args.recycle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleViolation(Violation v) {
|
||||
String msg = v.toString();
|
||||
Log.wtf(TAG, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a hash for a given stacktrace of a {@link Throwable}.
|
||||
*/
|
||||
@@ -224,8 +230,10 @@ public class LockHook {
|
||||
}
|
||||
}
|
||||
|
||||
static void addViolation(Object o) {
|
||||
sViolations.offer(o);
|
||||
static void addViolation(Violation v) {
|
||||
wtf(v);
|
||||
|
||||
sViolations.offer(v);
|
||||
while (sViolations.size() > MAX_VIOLATIONS) {
|
||||
sViolations.poll();
|
||||
}
|
||||
@@ -287,4 +295,7 @@ public class LockHook {
|
||||
|
||||
void dump(PrintWriter pw);
|
||||
}
|
||||
|
||||
interface Violation {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ class OnThreadLockChecker implements LockHook.LockChecker {
|
||||
heldLocks.remove(index);
|
||||
}
|
||||
|
||||
private static class Violation {
|
||||
private static class Violation implements LockHook.Violation {
|
||||
int mSelfTid;
|
||||
String mSelfName;
|
||||
Object mAlreadyHeld;
|
||||
@@ -323,7 +323,6 @@ class OnThreadLockChecker implements LockHook.LockChecker {
|
||||
if (LockHook.shouldDumpStacktrace(mStacktraceHasher.get(), mDumpedStacktraceHashes,
|
||||
Boolean.TRUE, v.mStack, 0, to)) {
|
||||
mNumDetectedUnique.incrementAndGet();
|
||||
LockHook.wtf(v.toString());
|
||||
LockHook.addViolation(v);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user