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/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 TimeDelta overhead_; | 809 TimeDelta overhead_; |
810 | 810 |
811 DISALLOW_COPY_AND_ASSIGN(ThreadLocalEventBuffer); | 811 DISALLOW_COPY_AND_ASSIGN(ThreadLocalEventBuffer); |
812 }; | 812 }; |
813 | 813 |
814 TraceLog::ThreadLocalEventBuffer::ThreadLocalEventBuffer(TraceLog* trace_log) | 814 TraceLog::ThreadLocalEventBuffer::ThreadLocalEventBuffer(TraceLog* trace_log) |
815 : trace_log_(trace_log), | 815 : trace_log_(trace_log), |
816 event_count_(0) { | 816 event_count_(0) { |
817 logged_events_.reserve(kTraceEventThreadLocalBufferSize); | 817 logged_events_.reserve(kTraceEventThreadLocalBufferSize); |
818 | 818 |
819 if (g_category_group_enabled[g_category_trace_event_overhead]) { | |
820 int thread_id = static_cast<int>(PlatformThread::CurrentId()); | |
821 logged_events_.push_back(TraceEvent( | |
822 thread_id, | |
823 TimeTicks::NowFromSystemTraceTime() - trace_log->time_offset_, | |
824 ThreadNow(), | |
825 TRACE_EVENT_PHASE_ASYNC_BEGIN, | |
826 &g_category_group_enabled[g_category_trace_event_overhead], | |
827 "thread_trace_event", | |
828 thread_id, | |
829 0, NULL, NULL, NULL, NULL, | |
830 TRACE_EVENT_FLAG_HAS_ID)); | |
831 } | |
832 | |
833 // ThreadLocalEventBuffer is created only if the thread has a message loop, so | 819 // ThreadLocalEventBuffer is created only if the thread has a message loop, so |
834 // the following message_loop won't be NULL. | 820 // the following message_loop won't be NULL. |
835 MessageLoop* message_loop = MessageLoop::current(); | 821 MessageLoop* message_loop = MessageLoop::current(); |
836 message_loop->AddDestructionObserver(this); | 822 message_loop->AddDestructionObserver(this); |
837 | 823 |
838 AutoLock lock(trace_log->lock_); | 824 AutoLock lock(trace_log->lock_); |
839 trace_log->thread_message_loops_.insert(message_loop); | 825 trace_log->thread_message_loops_.insert(message_loop); |
840 } | 826 } |
841 | 827 |
842 TraceLog::ThreadLocalEventBuffer::~ThreadLocalEventBuffer() { | 828 TraceLog::ThreadLocalEventBuffer::~ThreadLocalEventBuffer() { |
843 CheckThisIsCurrentBuffer(); | 829 CheckThisIsCurrentBuffer(); |
844 MessageLoop::current()->RemoveDestructionObserver(this); | 830 MessageLoop::current()->RemoveDestructionObserver(this); |
845 | 831 |
846 // Zero event_count_ happens in either of the following cases: | 832 // Zero event_count_ happens in either of the following cases: |
847 // - no event generated for the thread; | 833 // - no event generated for the thread; |
848 // - the thread has no message loop; | 834 // - the thread has no message loop; |
849 // - trace_event_overhead is disabled. | 835 // - trace_event_overhead is disabled. |
850 // The trace-viewer will ignore the TRACE_EVENT_PHASE_ASYNC_BEGIN event | |
851 // because of no matching TRACE_EVENT_PHASE_ASYNC_END event. | |
852 if (event_count_) { | 836 if (event_count_) { |
853 const char* arg_names[2] = { "event_count", "average_overhead" }; | 837 const char* arg_names[2] = { "event_count", "average_overhead" }; |
854 unsigned char arg_types[2]; | 838 unsigned char arg_types[2]; |
855 unsigned long long arg_values[2]; | 839 unsigned long long arg_values[2]; |
856 trace_event_internal::SetTraceValue( | 840 trace_event_internal::SetTraceValue( |
857 event_count_, &arg_types[0], &arg_values[0]); | 841 event_count_, &arg_types[0], &arg_values[0]); |
858 trace_event_internal::SetTraceValue( | 842 trace_event_internal::SetTraceValue( |
859 overhead_.InMillisecondsF() / event_count_, | 843 overhead_.InMillisecondsF() / event_count_, |
860 &arg_types[1], &arg_values[1]); | 844 &arg_types[1], &arg_values[1]); |
861 int thread_id = static_cast<int>(PlatformThread::CurrentId()); | |
862 logged_events_.push_back(TraceEvent( | 845 logged_events_.push_back(TraceEvent( |
863 thread_id, | 846 static_cast<int>(PlatformThread::CurrentId()), |
864 TimeTicks::NowFromSystemTraceTime() - trace_log_->time_offset_, | 847 TimeTicks(), TimeTicks(), TRACE_EVENT_PHASE_METADATA, |
865 ThreadNow(), | 848 &g_category_group_enabled[g_category_metadata], |
866 TRACE_EVENT_PHASE_ASYNC_END, | 849 "trace_event_overhead", trace_event_internal::kNoEventId, |
867 &g_category_group_enabled[g_category_trace_event_overhead], | |
868 "thread_trace_event", | |
869 thread_id, | |
870 2, arg_names, arg_types, arg_values, NULL, | 850 2, arg_names, arg_types, arg_values, NULL, |
871 TRACE_EVENT_FLAG_HAS_ID)); | 851 TRACE_EVENT_FLAG_NONE)); |
872 } | 852 } |
873 | 853 |
874 NotificationHelper notifier(trace_log_); | 854 NotificationHelper notifier(trace_log_); |
875 { | 855 { |
876 AutoLock lock(trace_log_->lock_); | 856 AutoLock lock(trace_log_->lock_); |
877 FlushWhileLocked(¬ifier); | 857 FlushWhileLocked(¬ifier); |
878 trace_log_->thread_message_loops_.erase(MessageLoop::current()); | 858 trace_log_->thread_message_loops_.erase(MessageLoop::current()); |
879 } | 859 } |
880 trace_log_->thread_local_event_buffer_.Set(NULL); | 860 trace_log_->thread_local_event_buffer_.Set(NULL); |
881 notifier.SendNotificationIfAny(); | 861 notifier.SendNotificationIfAny(); |
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2031 0, // num_args | 2011 0, // num_args |
2032 NULL, // arg_names | 2012 NULL, // arg_names |
2033 NULL, // arg_types | 2013 NULL, // arg_types |
2034 NULL, // arg_values | 2014 NULL, // arg_values |
2035 NULL, // convertable values | 2015 NULL, // convertable values |
2036 TRACE_EVENT_FLAG_NONE); // flags | 2016 TRACE_EVENT_FLAG_NONE); // flags |
2037 } | 2017 } |
2038 } | 2018 } |
2039 | 2019 |
2040 } // namespace trace_event_internal | 2020 } // namespace trace_event_internal |
OLD | NEW |