Fix tracing shutdown
Method tracing was being disabled before the listener was removed.
In some cases, this would cause the stack restoration to trigger
trace entries - resulting in out-of-order method exits.
By removing the listeners before disabling tracing, no one is around
to receive the erroneous stack restoration "exits".
Bug: 129716777
Test: Builds, ran on x86 emulator:
adb shell am start -S -W --start-profiler \
/data/local/tmp/test.trace --sampling 1 \
-a \android.intent.action.MAIN \
-n com.android.calendar/com.android.calendar.AllInOneActivity && \
sleep 5 && \
adb shell am profile stop com.android.calendar && \
adb pull /data/local/tmp/test.trace
and inspected resulting tracefile; parsed fine in Android Studio 3.0.1
Change-Id: I90f0751f4b4253c7c9711d05d53f31b3e545fc3b
diff --git a/runtime/trace.cc b/runtime/trace.cc
index f2bfb0b..0e28f29 100644
--- a/runtime/trace.cc
+++ b/runtime/trace.cc
@@ -478,11 +478,11 @@
MutexLock mu(self, *Locks::thread_list_lock_);
runtime->GetThreadList()->ForEach(ClearThreadStackTraceAndClockBase, nullptr);
} else {
- runtime->GetInstrumentation()->DisableMethodTracing(kTracerInstrumentationKey);
runtime->GetInstrumentation()->RemoveListener(
the_trace, instrumentation::Instrumentation::kMethodEntered |
instrumentation::Instrumentation::kMethodExited |
instrumentation::Instrumentation::kMethodUnwind);
+ runtime->GetInstrumentation()->DisableMethodTracing(kTracerInstrumentationKey);
}
}
// At this point, code may read buf_ as it's writers are shutdown