diff options
author | Jeff Hao <jeffhao@google.com> | 2014-09-08 09:38:18 -0700 |
---|---|---|
committer | Jeff Hao <jeffhao@google.com> | 2014-09-09 11:39:38 -0700 |
commit | d063d912e5580222b1822b152de315420cef49ee (patch) | |
tree | 98399fb92eaeefab47daf6ce9b77f03ffb8841d8 /runtime/trace.cc | |
parent | 5bc47ebe278af65e8e2a2d6b603ac94a020285f7 (diff) | |
download | art-d063d912e5580222b1822b152de315420cef49ee.zip art-d063d912e5580222b1822b152de315420cef49ee.tar.gz art-d063d912e5580222b1822b152de315420cef49ee.tar.bz2 |
Change when sampling thread is reset during shutdown to prevent races.
Also adds some extra argument checking and testing for tracing.
Bug: 17412385
(cherry picked from commit f8bdd4e783842577e49f418a0b5962ba49dfdd93)
Change-Id: Ifc4f1a296155d73255b29d264b5475024e6419da
Diffstat (limited to 'runtime/trace.cc')
-rw-r--r-- | runtime/trace.cc | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/runtime/trace.cc b/runtime/trace.cc index ca5e150..6dcc5fe 100644 --- a/runtime/trace.cc +++ b/runtime/trace.cc @@ -334,8 +334,14 @@ void Trace::Start(const char* trace_filename, int trace_fd, int buffer_size, int return; } } - Runtime* runtime = Runtime::Current(); - runtime->GetThreadList()->SuspendAll(); + + // Check interval if sampling is enabled + if (sampling_enabled && interval_us <= 0) { + LOG(ERROR) << "Invalid sampling interval: " << interval_us; + ScopedObjectAccess soa(self); + ThrowRuntimeException("Invalid sampling interval: %d", interval_us); + return; + } // Open trace file if not going directly to ddms. std::unique_ptr<File> trace_file; @@ -348,13 +354,15 @@ void Trace::Start(const char* trace_filename, int trace_fd, int buffer_size, int } if (trace_file.get() == NULL) { PLOG(ERROR) << "Unable to open trace file '" << trace_filename << "'"; - runtime->GetThreadList()->ResumeAll(); ScopedObjectAccess soa(self); ThrowRuntimeException("Unable to open trace file '%s'", trace_filename); return; } } + Runtime* runtime = Runtime::Current(); + runtime->GetThreadList()->SuspendAll(); + // Create Trace object. { MutexLock mu(self, *Locks::trace_lock_); @@ -383,6 +391,7 @@ void Trace::Start(const char* trace_filename, int trace_fd, int buffer_size, int } } } + runtime->GetThreadList()->ResumeAll(); } @@ -399,7 +408,6 @@ void Trace::Stop() { the_trace = the_trace_; the_trace_ = NULL; sampling_pthread = sampling_pthread_; - sampling_pthread_ = 0U; } } if (the_trace != NULL) { @@ -421,6 +429,7 @@ void Trace::Stop() { if (sampling_pthread != 0U) { CHECK_PTHREAD_CALL(pthread_join, (sampling_pthread, NULL), "sampling thread shutdown"); + sampling_pthread_ = 0U; } } |