diff options
| -rw-r--r-- | runtime/trace.cc | 6 | ||||
| -rw-r--r-- | runtime/trace_profile.cc | 11 | ||||
| -rw-r--r-- | runtime/trace_profile.h | 3 |
3 files changed, 20 insertions, 0 deletions
diff --git a/runtime/trace.cc b/runtime/trace.cc index c3fc6fd138..3b7f73284e 100644 --- a/runtime/trace.cc +++ b/runtime/trace.cc @@ -33,6 +33,7 @@ #include "base/utils.h" #include "class_linker.h" #include "common_throws.h" +#include "com_android_art_flags.h" #include "debugger.h" #include "dex/descriptors_names.h" #include "dex/dex_file-inl.h" @@ -52,6 +53,8 @@ #include "thread_list.h" #include "trace_profile.h" +namespace art_flags = com::android::art::flags; + namespace art HIDDEN { struct MethodTraceRecord { @@ -975,6 +978,9 @@ void Trace::ReleaseThreadBuffer(Thread* self) { // Check if we still need to flush inside the trace_lock_. If we are stopping tracing it is // possible we already deleted the trace and flushed the buffer too. if (the_trace_ == nullptr) { + if (art_flags::always_enable_profile_code()) { + TraceProfiler::ReleaseThreadBuffer(self); + } DCHECK_EQ(self->GetMethodTraceBuffer(), nullptr); return; } diff --git a/runtime/trace_profile.cc b/runtime/trace_profile.cc index c1000d2095..ab861136a3 100644 --- a/runtime/trace_profile.cc +++ b/runtime/trace_profile.cc @@ -200,6 +200,17 @@ void TraceProfiler::Dump(std::unique_ptr<File>&& trace_file) { } } +void TraceProfiler::ReleaseThreadBuffer(Thread* self) { + if (!IsTraceProfileInProgress()) { + return; + } + // TODO(mythria): Maybe it's good to cache these and dump them when requested. For now just + // relese the buffer when a thread is exiting. + auto buffer = self->GetMethodTraceBuffer(); + delete[] buffer; + self->SetMethodTraceBuffer(nullptr, 0); +} + bool TraceProfiler::IsTraceProfileInProgress() { return profile_in_progress_; } diff --git a/runtime/trace_profile.h b/runtime/trace_profile.h index 7118cd5882..aec59b58b1 100644 --- a/runtime/trace_profile.h +++ b/runtime/trace_profile.h @@ -49,6 +49,9 @@ class TraceProfiler { static void Dump(int fd); static void Dump(const char* trace_filename); + // Called when thread is exiting to release the allocated buffer. + static void ReleaseThreadBuffer(Thread* self) REQUIRES(Locks::trace_lock_); + static bool IsTraceProfileInProgress() REQUIRES(Locks::trace_lock_); private: |