Commit a0ef836d authored by Sami Kyostila's avatar Sami Kyostila Committed by Commit Bot

Tracing: Handle mismatching Looper log lines

If the target object of a Looper message gets garbage collected after
the message is handled but before Looper logs the 'finished' line, the
signature of the object may not match the original 'dispatching' log
line. To work around this, store a reference to the original target
signature to ensure a matching end event.

This patch also adds some extra debug logging when duplicate early trace
events are started simultaneously.

Bug: 935869
Change-Id: I4bafba4a5469ca5743d9cd6d64cb043e82387b8c
Reviewed-on: https://chromium-review.googlesource.com/c/1491612
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636773}
parent 5de9621c
...@@ -227,7 +227,7 @@ public class EarlyTraceEvent { ...@@ -227,7 +227,7 @@ public class EarlyTraceEvent {
} }
if (conflictingEvent != null) { if (conflictingEvent != null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Multiple pending trace events can't have the same name"); "Multiple pending trace events can't have the same name: " + name);
} }
} }
......
...@@ -35,6 +35,7 @@ public class TraceEvent implements AutoCloseable { ...@@ -35,6 +35,7 @@ public class TraceEvent implements AutoCloseable {
private static class BasicLooperMonitor implements Printer { private static class BasicLooperMonitor implements Printer {
private static final String LOOPER_TASK_PREFIX = "Looper.dispatch: "; private static final String LOOPER_TASK_PREFIX = "Looper.dispatch: ";
private static final int SHORTEST_LOG_PREFIX_LENGTH = "<<<<< Finished to ".length(); private static final int SHORTEST_LOG_PREFIX_LENGTH = "<<<<< Finished to ".length();
private String mCurrentTarget;
@Override @Override
public void println(final String line) { public void println(final String line) {
...@@ -51,25 +52,25 @@ public class TraceEvent implements AutoCloseable { ...@@ -51,25 +52,25 @@ public class TraceEvent implements AutoCloseable {
// will filter the event in this case. // will filter the event in this case.
boolean earlyTracingActive = EarlyTraceEvent.isActive(); boolean earlyTracingActive = EarlyTraceEvent.isActive();
if (sEnabled || earlyTracingActive) { if (sEnabled || earlyTracingActive) {
String target = getTraceEventName(line); mCurrentTarget = getTraceEventName(line);
if (sEnabled) { if (sEnabled) {
nativeBeginToplevel(target); nativeBeginToplevel(mCurrentTarget);
} else { } else {
EarlyTraceEvent.begin(target); EarlyTraceEvent.begin(mCurrentTarget);
} }
} }
} }
void endHandling(final String line) { void endHandling(final String line) {
boolean earlyTracingActive = EarlyTraceEvent.isActive(); boolean earlyTracingActive = EarlyTraceEvent.isActive();
if (sEnabled || earlyTracingActive) { if ((sEnabled || earlyTracingActive) && mCurrentTarget != null) {
String target = getTraceEventName(line);
if (sEnabled) { if (sEnabled) {
nativeEndToplevel(target); nativeEndToplevel(mCurrentTarget);
} else { } else {
EarlyTraceEvent.end(target); EarlyTraceEvent.end(mCurrentTarget);
} }
} }
mCurrentTarget = null;
} }
private static String getTraceEventName(String line) { private static String getTraceEventName(String line) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment