Fix a couple trace issues

- Adding trace tokens since we can be starting/ending traces out of order
- Fixing issue with draw hitting twice causing the trace stack to be
  popped twice
- Fix issue with endFlagOverrides not removing from the stack

Bug: 142803200

Change-Id: I8649b94249910a352f00f2f2c2459c355d2bab00
This commit is contained in:
Winson Chung
2019-10-16 11:32:41 -07:00
parent 3aefb6d776
commit 5cc62c7d0b
7 changed files with 80 additions and 47 deletions

View File

@@ -46,35 +46,44 @@ public class TraceHelper {
*/
public static TraceHelper INSTANCE = new TraceHelper();
public void beginSection(String sectionName) {
beginSection(sectionName, 0);
/**
* @return a token to pass into {@link #endSection(Object)}.
*/
public Object beginSection(String sectionName) {
return beginSection(sectionName, 0);
}
public void beginSection(String sectionName, int flags) {
public Object beginSection(String sectionName, int flags) {
Trace.beginSection(sectionName);
return null;
}
public void endSection() {
/**
* @param token the token returned from {@link #beginSection(String, int)}
*/
public void endSection(Object token) {
Trace.endSection();
}
/**
* Similar to {@link #beginSection} but doesn't add a trace section.
*/
public void beginFlagsOverride(int flags) { }
public Object beginFlagsOverride(int flags) {
return null;
}
public void endFlagsOverride() { }
public void endFlagsOverride(Object token) { }
/**
* Temporarily ignore blocking binder calls for the duration of this {@link Supplier}.
*/
@MainThread
public static <T> T whitelistIpcs(String rpcName, Supplier<T> supplier) {
INSTANCE.beginSection(rpcName, FLAG_IGNORE_BINDERS);
Object traceToken = INSTANCE.beginSection(rpcName, FLAG_IGNORE_BINDERS);
try {
return supplier.get();
} finally {
INSTANCE.endSection();
INSTANCE.endSection(traceToken);
}
}
}