| Index: base/debug/trace_event_impl.cc
|
| diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
|
| index 07679d1131250fb101401191d02434dc6e59e8b8..371c5876eb20ec158b0e9bcb7a4c1a7acdbf971f 100644
|
| --- a/base/debug/trace_event_impl.cc
|
| +++ b/base/debug/trace_event_impl.cc
|
| @@ -20,6 +20,7 @@
|
| #include "base/sys_info.h"
|
| #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
|
| #include "base/threading/platform_thread.h"
|
| +#include "base/threading/thread_id_name_manager.h"
|
| #include "base/threading/thread_local.h"
|
| #include "base/time.h"
|
| #include "base/utf_string_conversions.h"
|
| @@ -65,9 +66,8 @@ const int g_category_categories_exhausted = 1;
|
| const int g_category_metadata = 2;
|
| int g_category_index = 3; // skip initial 3 categories
|
|
|
| -// The most-recently captured name of the current thread
|
| -LazyInstance<ThreadLocalPointer<const char> >::Leaky
|
| - g_current_thread_name = LAZY_INSTANCE_INITIALIZER;
|
| +// The most-recently captured version of the current thread name
|
| +uint32 g_current_thread_name_version = 0;
|
|
|
| } // namespace
|
|
|
| @@ -610,14 +610,16 @@ void TraceLog::Flush(const TraceLog::OutputCallback& cb) {
|
| }
|
|
|
| void TraceLog::AddTraceEvent(char phase,
|
| - const unsigned char* category_enabled,
|
| - const char* name,
|
| - unsigned long long id,
|
| - int num_args,
|
| - const char** arg_names,
|
| - const unsigned char* arg_types,
|
| - const unsigned long long* arg_values,
|
| - unsigned char flags) {
|
| + const unsigned char* category_enabled,
|
| + const char* name,
|
| + unsigned long long id,
|
| + int thread_id,
|
| + int64 timestamp,
|
| + int num_args,
|
| + const char** arg_names,
|
| + const unsigned char* arg_types,
|
| + const unsigned long long* arg_values,
|
| + unsigned char flags) {
|
| DCHECK(name);
|
|
|
| #if defined(OS_ANDROID)
|
| @@ -625,8 +627,9 @@ void TraceLog::AddTraceEvent(char phase,
|
| num_args, arg_names, arg_types, arg_values);
|
| #endif
|
|
|
| - TimeTicks now = TimeTicks::NowFromSystemTraceTime() - time_offset_;
|
| + TimeTicks now = TimeTicks::FromInternalValue(timestamp);
|
| NotificationHelper notifier(this);
|
| +
|
| {
|
| AutoLock lock(lock_);
|
| if (*category_enabled != CATEGORY_ENABLED)
|
| @@ -634,16 +637,17 @@ void TraceLog::AddTraceEvent(char phase,
|
| if (logged_events_.size() >= kTraceEventBufferSize)
|
| return;
|
|
|
| - int thread_id = static_cast<int>(PlatformThread::CurrentId());
|
| + ThreadIdNameManager* manager = ThreadIdNameManager::GetInstance();
|
| + const char* new_name = manager->GetNameForId(thread_id);
|
| + uint32 new_version = manager->GetVersionForId(thread_id);
|
|
|
| - const char* new_name = PlatformThread::GetName();
|
| // Check if the thread name has been set or changed since the previous
|
| // call (if any), but don't bother if the new name is empty. Note this will
|
| // not detect a thread name change within the same char* buffer address: we
|
| // favor common case performance over corner case correctness.
|
| - if (new_name != g_current_thread_name.Get().Get() &&
|
| - new_name && *new_name) {
|
| - g_current_thread_name.Get().Set(new_name);
|
| + if (new_version != g_current_thread_name_version && new_name && *new_name) {
|
| + g_current_thread_name_version = new_version;
|
| +
|
| base::hash_map<int, std::string>::iterator existing_name =
|
| thread_names_.find(thread_id);
|
| if (existing_name == thread_names_.end()) {
|
| @@ -785,5 +789,9 @@ void TraceLog::SetTimeOffset(TimeDelta offset) {
|
| time_offset_ = offset;
|
| }
|
|
|
| +TimeDelta TraceLog::GetTimeOffset() {
|
| + return time_offset_;
|
| +}
|
| +
|
| } // namespace debug
|
| } // namespace base
|
|
|