OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/debug/trace_event_impl.h" | 5 #include "base/debug/trace_event_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
19 #include "base/strings/string_tokenizer.h" | 19 #include "base/strings/string_tokenizer.h" |
20 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
21 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 21 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
22 #include "base/threading/platform_thread.h" | 22 #include "base/threading/platform_thread.h" |
23 #include "base/threading/thread_id_name_manager.h" | |
23 #include "base/threading/thread_local.h" | 24 #include "base/threading/thread_local.h" |
24 #include "base/time.h" | 25 #include "base/time.h" |
25 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
26 | 27 |
27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
28 #include "base/debug/trace_event_win.h" | 29 #include "base/debug/trace_event_win.h" |
29 #endif | 30 #endif |
30 | 31 |
31 class DeleteTraceLogForTesting { | 32 class DeleteTraceLogForTesting { |
32 public: | 33 public: |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 new RefCountedString(); | 617 new RefCountedString(); |
617 TraceEvent::AppendEventsAsJSON(previous_logged_events, | 618 TraceEvent::AppendEventsAsJSON(previous_logged_events, |
618 i, | 619 i, |
619 kTraceEventBatchSize, | 620 kTraceEventBatchSize, |
620 &(json_events_str_ptr->data())); | 621 &(json_events_str_ptr->data())); |
621 cb.Run(json_events_str_ptr); | 622 cb.Run(json_events_str_ptr); |
622 } | 623 } |
623 } | 624 } |
624 | 625 |
625 void TraceLog::AddTraceEvent(char phase, | 626 void TraceLog::AddTraceEvent(char phase, |
626 const unsigned char* category_enabled, | 627 const unsigned char* category_enabled, |
627 const char* name, | 628 const char* name, |
628 unsigned long long id, | 629 unsigned long long id, |
629 int num_args, | 630 int num_args, |
630 const char** arg_names, | 631 const char** arg_names, |
631 const unsigned char* arg_types, | 632 const unsigned char* arg_types, |
632 const unsigned long long* arg_values, | 633 const unsigned long long* arg_values, |
633 unsigned char flags) { | 634 unsigned char flags) { |
635 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); | |
636 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); | |
jar (doing other things)
2013/02/14 02:17:54
nit: This surely shouts for passing in a TimeTicks
dsinclair
2013/02/14 15:38:47
Done.
| |
637 AddTraceEvent(phase, category_enabled, name, id, thread_id, | |
638 now.ToInternalValue(), num_args, arg_names, arg_types, | |
639 arg_values, flags); | |
640 } | |
641 | |
642 void TraceLog::AddTraceEvent(char phase, | |
643 const unsigned char* category_enabled, | |
644 const char* name, | |
645 unsigned long long id, | |
646 int thread_id, | |
647 int64 timestamp, | |
648 int num_args, | |
649 const char** arg_names, | |
650 const unsigned char* arg_types, | |
651 const unsigned long long* arg_values, | |
652 unsigned char flags) { | |
634 DCHECK(name); | 653 DCHECK(name); |
635 | 654 |
636 #if defined(OS_ANDROID) | 655 #if defined(OS_ANDROID) |
637 SendToATrace(phase, GetCategoryName(category_enabled), name, | 656 SendToATrace(phase, GetCategoryName(category_enabled), name, |
638 num_args, arg_names, arg_types, arg_values); | 657 num_args, arg_names, arg_types, arg_values); |
639 #endif | 658 #endif |
640 | 659 |
641 TimeTicks now = TimeTicks::NowFromSystemTraceTime() - time_offset_; | 660 TimeTicks now = TimeTicks::FromInternalValue(timestamp) - time_offset_; |
642 NotificationHelper notifier(this); | 661 NotificationHelper notifier(this); |
662 | |
643 { | 663 { |
644 AutoLock lock(lock_); | 664 AutoLock lock(lock_); |
645 if (*category_enabled != CATEGORY_ENABLED) | 665 if (*category_enabled != CATEGORY_ENABLED) |
646 return; | 666 return; |
647 if (logged_events_.size() >= kTraceEventBufferSize) | 667 if (logged_events_.size() >= kTraceEventBufferSize) |
648 return; | 668 return; |
649 | 669 |
650 int thread_id = static_cast<int>(PlatformThread::CurrentId()); | 670 const char* new_name = ThreadIdNameManager::GetInstance()-> |
651 | 671 GetName(thread_id); |
652 const char* new_name = PlatformThread::GetName(); | |
653 // Check if the thread name has been set or changed since the previous | 672 // Check if the thread name has been set or changed since the previous |
654 // call (if any), but don't bother if the new name is empty. Note this will | 673 // call (if any), but don't bother if the new name is empty. Note this will |
655 // not detect a thread name change within the same char* buffer address: we | 674 // not detect a thread name change within the same char* buffer address: we |
656 // favor common case performance over corner case correctness. | 675 // favor common case performance over corner case correctness. |
657 if (new_name != g_current_thread_name.Get().Get() && | 676 if (new_name != g_current_thread_name.Get().Get() && |
658 new_name && *new_name) { | 677 new_name && *new_name) { |
659 g_current_thread_name.Get().Set(new_name); | 678 g_current_thread_name.Get().Set(new_name); |
679 | |
660 hash_map<int, std::string>::iterator existing_name = | 680 hash_map<int, std::string>::iterator existing_name = |
661 thread_names_.find(thread_id); | 681 thread_names_.find(thread_id); |
662 if (existing_name == thread_names_.end()) { | 682 if (existing_name == thread_names_.end()) { |
663 // This is a new thread id, and a new name. | 683 // This is a new thread id, and a new name. |
664 thread_names_[thread_id] = new_name; | 684 thread_names_[thread_id] = new_name; |
665 } else { | 685 } else { |
666 // This is a thread id that we've seen before, but potentially with a | 686 // This is a thread id that we've seen before, but potentially with a |
667 // new name. | 687 // new name. |
668 std::vector<StringPiece> existing_names; | 688 std::vector<StringPiece> existing_names; |
669 Tokenize(existing_name->second, ",", &existing_names); | 689 Tokenize(existing_name->second, ",", &existing_names); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 unsigned long long pid = static_cast<unsigned long long>(process_id_); | 813 unsigned long long pid = static_cast<unsigned long long>(process_id_); |
794 process_id_hash_ = (offset_basis ^ pid) * fnv_prime; | 814 process_id_hash_ = (offset_basis ^ pid) * fnv_prime; |
795 } | 815 } |
796 | 816 |
797 void TraceLog::SetTimeOffset(TimeDelta offset) { | 817 void TraceLog::SetTimeOffset(TimeDelta offset) { |
798 time_offset_ = offset; | 818 time_offset_ = offset; |
799 } | 819 } |
800 | 820 |
801 } // namespace debug | 821 } // namespace debug |
802 } // namespace base | 822 } // namespace base |
OLD | NEW |