diff options
-rw-r--r-- | runtime/native/dalvik_system_VMDebug.cc | 12 | ||||
-rw-r--r-- | runtime/runtime.cc | 4 | ||||
-rw-r--r-- | runtime/trace.cc | 27 | ||||
-rw-r--r-- | runtime/trace.h | 16 |
4 files changed, 40 insertions, 19 deletions
diff --git a/runtime/native/dalvik_system_VMDebug.cc b/runtime/native/dalvik_system_VMDebug.cc index 57ca2b1303..2724d91f6b 100644 --- a/runtime/native/dalvik_system_VMDebug.cc +++ b/runtime/native/dalvik_system_VMDebug.cc @@ -79,7 +79,9 @@ static void VMDebug_resetAllocCount(JNIEnv*, jclass, jint kinds) { static void VMDebug_startMethodTracingDdmsImpl(JNIEnv*, jclass, jint bufferSize, jint flags, jboolean samplingEnabled, jint intervalUs) { - Trace::Start("[DDMS]", -1, bufferSize, flags, true, samplingEnabled, intervalUs); + Trace::Start("[DDMS]", -1, bufferSize, flags, Trace::TraceOutputMode::kDDMS, + samplingEnabled ? Trace::TraceMode::kSampling : Trace::TraceMode::kMethodTracing, + intervalUs); } static void VMDebug_startMethodTracingFd(JNIEnv* env, jclass, jstring javaTraceFilename, @@ -102,7 +104,9 @@ static void VMDebug_startMethodTracingFd(JNIEnv* env, jclass, jstring javaTraceF if (traceFilename.c_str() == NULL) { return; } - Trace::Start(traceFilename.c_str(), fd, bufferSize, flags, false, samplingEnabled, intervalUs); + Trace::Start(traceFilename.c_str(), fd, bufferSize, flags, Trace::TraceOutputMode::kFile, + samplingEnabled ? Trace::TraceMode::kSampling : Trace::TraceMode::kMethodTracing, + intervalUs); } static void VMDebug_startMethodTracingFilename(JNIEnv* env, jclass, jstring javaTraceFilename, @@ -112,7 +116,9 @@ static void VMDebug_startMethodTracingFilename(JNIEnv* env, jclass, jstring java if (traceFilename.c_str() == NULL) { return; } - Trace::Start(traceFilename.c_str(), -1, bufferSize, flags, false, samplingEnabled, intervalUs); + Trace::Start(traceFilename.c_str(), -1, bufferSize, flags, Trace::TraceOutputMode::kFile, + samplingEnabled ? Trace::TraceMode::kSampling : Trace::TraceMode::kMethodTracing, + intervalUs); } static jint VMDebug_getMethodTracingMode(JNIEnv*, jclass) { diff --git a/runtime/runtime.cc b/runtime/runtime.cc index c462153ed3..c17c0f37ad 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -1012,8 +1012,8 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized) -1, static_cast<int>(method_trace_file_size_), 0, - false, - false, + Trace::TraceOutputMode::kFile, + Trace::TraceMode::kMethodTracing, 0); } diff --git a/runtime/trace.cc b/runtime/trace.cc index 373490385e..ea0a642855 100644 --- a/runtime/trace.cc +++ b/runtime/trace.cc @@ -328,7 +328,7 @@ void* Trace::RunSamplingThread(void* arg) { } void Trace::Start(const char* trace_filename, int trace_fd, int buffer_size, int flags, - bool direct_to_ddms, bool sampling_enabled, int interval_us) { + TraceOutputMode output_mode, TraceMode trace_mode, int interval_us) { Thread* self = Thread::Current(); { MutexLock mu(self, *Locks::trace_lock_); @@ -339,7 +339,7 @@ void Trace::Start(const char* trace_filename, int trace_fd, int buffer_size, int } // Check interval if sampling is enabled - if (sampling_enabled && interval_us <= 0) { + if (trace_mode == TraceMode::kSampling && interval_us <= 0) { LOG(ERROR) << "Invalid sampling interval: " << interval_us; ScopedObjectAccess soa(self); ThrowRuntimeException("Invalid sampling interval: %d", interval_us); @@ -348,7 +348,7 @@ void Trace::Start(const char* trace_filename, int trace_fd, int buffer_size, int // Open trace file if not going directly to ddms. std::unique_ptr<File> trace_file; - if (!direct_to_ddms) { + if (output_mode != TraceOutputMode::kDDMS) { if (trace_fd < 0) { trace_file.reset(OS::CreateEmptyFile(trace_filename)); } else { @@ -377,8 +377,8 @@ void Trace::Start(const char* trace_filename, int trace_fd, int buffer_size, int LOG(ERROR) << "Trace already in progress, ignoring this request"; } else { enable_stats = (flags && kTraceCountAllocs) != 0; - the_trace_ = new Trace(trace_file.release(), buffer_size, flags, sampling_enabled); - if (sampling_enabled) { + the_trace_ = new Trace(trace_file.release(), buffer_size, flags, trace_mode); + if (trace_mode == TraceMode::kSampling) { CHECK_PTHREAD_CALL(pthread_create, (&sampling_pthread_, NULL, &RunSamplingThread, reinterpret_cast<void*>(interval_us)), "Sampling profiler thread"); @@ -427,7 +427,7 @@ void Trace::Stop() { stop_alloc_counting = (the_trace->flags_ & kTraceCountAllocs) != 0; the_trace->FinishTracing(); - if (the_trace->sampling_enabled_) { + if (the_trace->trace_mode_ == TraceMode::kSampling) { MutexLock mu(Thread::Current(), *Locks::thread_list_lock_); runtime->GetThreadList()->ForEach(ClearThreadStackTraceAndClockBase, nullptr); } else { @@ -465,16 +465,21 @@ TracingMode Trace::GetMethodTracingMode() { MutexLock mu(Thread::Current(), *Locks::trace_lock_); if (the_trace_ == NULL) { return kTracingInactive; - } else if (the_trace_->sampling_enabled_) { - return kSampleProfilingActive; } else { - return kMethodTracingActive; + switch (the_trace_->trace_mode_) { + case TraceMode::kSampling: + return kSampleProfilingActive; + case TraceMode::kMethodTracing: + return kMethodTracingActive; + } + LOG(FATAL) << "Unreachable"; + UNREACHABLE(); } } -Trace::Trace(File* trace_file, int buffer_size, int flags, bool sampling_enabled) +Trace::Trace(File* trace_file, int buffer_size, int flags, TraceMode trace_mode) : trace_file_(trace_file), buf_(new uint8_t[buffer_size]()), flags_(flags), - sampling_enabled_(sampling_enabled), clock_source_(default_clock_source_), + trace_mode_(trace_mode), clock_source_(default_clock_source_), buffer_size_(buffer_size), start_time_(MicroTime()), clock_overhead_ns_(GetClockOverheadNanoSeconds()), cur_offset_(0), overflow_(false) { // Set up the beginning of the trace. diff --git a/runtime/trace.h b/runtime/trace.h index dd8186a2cb..80f926f31c 100644 --- a/runtime/trace.h +++ b/runtime/trace.h @@ -51,10 +51,20 @@ class Trace FINAL : public instrumentation::InstrumentationListener { kTraceCountAllocs = 1, }; + enum class TraceOutputMode { + kFile, + kDDMS + }; + + enum class TraceMode { + kMethodTracing, + kSampling + }; + static void SetDefaultClockSource(TraceClockSource clock_source); static void Start(const char* trace_filename, int trace_fd, int buffer_size, int flags, - bool direct_to_ddms, bool sampling_enabled, int interval_us) + TraceOutputMode output_mode, TraceMode trace_mode, int interval_us) LOCKS_EXCLUDED(Locks::mutator_lock_, Locks::thread_list_lock_, Locks::thread_suspend_count_lock_, @@ -107,7 +117,7 @@ class Trace FINAL : public instrumentation::InstrumentationListener { static void StoreExitingThreadInfo(Thread* thread); private: - explicit Trace(File* trace_file, int buffer_size, int flags, bool sampling_enabled); + explicit Trace(File* trace_file, int buffer_size, int flags, TraceMode trace_mode); // The sampling interval in microseconds is passed as an argument. static void* RunSamplingThread(void* arg) LOCKS_EXCLUDED(Locks::trace_lock_); @@ -148,7 +158,7 @@ class Trace FINAL : public instrumentation::InstrumentationListener { const int flags_; // True if traceview should sample instead of instrumenting method entry/exit. - const bool sampling_enabled_; + const TraceMode trace_mode_; const TraceClockSource clock_source_; |