Chromium Code Reviews| 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/trace_event/trace_event_impl.h" | 5 #include "base/trace_event/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 1894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1905 if (thread_is_in_trace_event_.Get()) | 1905 if (thread_is_in_trace_event_.Get()) |
| 1906 return handle; | 1906 return handle; |
| 1907 | 1907 |
| 1908 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_); | 1908 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_); |
| 1909 | 1909 |
| 1910 DCHECK(name); | 1910 DCHECK(name); |
| 1911 | 1911 |
| 1912 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) | 1912 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) |
| 1913 id ^= process_id_hash_; | 1913 id ^= process_id_hash_; |
| 1914 | 1914 |
| 1915 TimeTicks now = OffsetTimestamp(timestamp); | 1915 TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp); |
| 1916 TimeTicks now = OffsetNow(); | |
|
nduca
2015/02/13 19:13:44
is this causing us to read the clock twice on ever
Xianzhu
2015/02/13 19:27:26
Yes :(
Possible ways to avoid this:
- check if ov
| |
| 1916 TimeTicks thread_now = ThreadNow(); | 1917 TimeTicks thread_now = ThreadNow(); |
| 1917 | 1918 |
| 1918 ThreadLocalEventBuffer* thread_local_event_buffer = NULL; | 1919 ThreadLocalEventBuffer* thread_local_event_buffer = NULL; |
| 1919 // A ThreadLocalEventBuffer needs the message loop | 1920 // A ThreadLocalEventBuffer needs the message loop |
| 1920 // - to know when the thread exits; | 1921 // - to know when the thread exits; |
| 1921 // - to handle the final flush. | 1922 // - to handle the final flush. |
| 1922 // For a thread without a message loop or the message loop may be blocked, the | 1923 // For a thread without a message loop or the message loop may be blocked, the |
| 1923 // trace events will be added into the main buffer directly. | 1924 // trace events will be added into the main buffer directly. |
| 1924 if (!thread_blocks_message_loop_.Get() && MessageLoop::current()) { | 1925 if (!thread_blocks_message_loop_.Get() && MessageLoop::current()) { |
| 1925 thread_local_event_buffer = thread_local_event_buffer_.Get(); | 1926 thread_local_event_buffer = thread_local_event_buffer_.Get(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1978 | 1979 |
| 1979 TraceEvent* trace_event = NULL; | 1980 TraceEvent* trace_event = NULL; |
| 1980 if (thread_local_event_buffer) { | 1981 if (thread_local_event_buffer) { |
| 1981 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); | 1982 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); |
| 1982 } else { | 1983 } else { |
| 1983 lock.EnsureAcquired(); | 1984 lock.EnsureAcquired(); |
| 1984 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true); | 1985 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true); |
| 1985 } | 1986 } |
| 1986 | 1987 |
| 1987 if (trace_event) { | 1988 if (trace_event) { |
| 1988 trace_event->Initialize(thread_id, now, thread_now, phase, | 1989 trace_event->Initialize(thread_id, offset_event_timestamp, thread_now, |
| 1989 category_group_enabled, name, id, | 1990 phase, category_group_enabled, name, id, |
| 1990 num_args, arg_names, arg_types, arg_values, | 1991 num_args, arg_names, arg_types, arg_values, |
| 1991 convertable_values, flags); | 1992 convertable_values, flags); |
| 1992 | 1993 |
| 1993 #if defined(OS_ANDROID) | 1994 #if defined(OS_ANDROID) |
| 1994 trace_event->SendToATrace(); | 1995 trace_event->SendToATrace(); |
| 1995 #endif | 1996 #endif |
| 1996 } | 1997 } |
| 1997 | 1998 |
| 1998 if (trace_options() & kInternalEchoToConsole) { | 1999 if (trace_options() & kInternalEchoToConsole) { |
| 1999 console_message = EventToConsoleMessage( | 2000 console_message = EventToConsoleMessage( |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2017 if (event_name_matches) { | 2018 if (event_name_matches) { |
| 2018 if (!watch_event_callback_copy.is_null()) | 2019 if (!watch_event_callback_copy.is_null()) |
| 2019 watch_event_callback_copy.Run(); | 2020 watch_event_callback_copy.Run(); |
| 2020 } | 2021 } |
| 2021 } | 2022 } |
| 2022 | 2023 |
| 2023 if (*category_group_enabled & ENABLED_FOR_EVENT_CALLBACK) { | 2024 if (*category_group_enabled & ENABLED_FOR_EVENT_CALLBACK) { |
| 2024 EventCallback event_callback = reinterpret_cast<EventCallback>( | 2025 EventCallback event_callback = reinterpret_cast<EventCallback>( |
| 2025 subtle::NoBarrier_Load(&event_callback_)); | 2026 subtle::NoBarrier_Load(&event_callback_)); |
| 2026 if (event_callback) { | 2027 if (event_callback) { |
| 2027 event_callback(now, | 2028 event_callback(offset_event_timestamp, |
| 2028 phase == TRACE_EVENT_PHASE_COMPLETE ? | 2029 phase == TRACE_EVENT_PHASE_COMPLETE ? |
| 2029 TRACE_EVENT_PHASE_BEGIN : phase, | 2030 TRACE_EVENT_PHASE_BEGIN : phase, |
| 2030 category_group_enabled, name, id, | 2031 category_group_enabled, name, id, |
| 2031 num_args, arg_names, arg_types, arg_values, | 2032 num_args, arg_names, arg_types, arg_values, |
| 2032 flags); | 2033 flags); |
| 2033 } | 2034 } |
| 2034 } | 2035 } |
| 2035 | 2036 |
| 2037 // Use |now| instead of |offset_event_timestamp| to compute overhead, because | |
| 2038 // event timestamp may be not the real time that we started to add the event | |
| 2039 // (e.g. event with zero timestamp or that was generated some time ago). | |
| 2036 if (thread_local_event_buffer) | 2040 if (thread_local_event_buffer) |
| 2037 thread_local_event_buffer->ReportOverhead(now, thread_now); | 2041 thread_local_event_buffer->ReportOverhead(now, thread_now); |
| 2038 | 2042 |
| 2039 return handle; | 2043 return handle; |
| 2040 } | 2044 } |
| 2041 | 2045 |
| 2042 // May be called when a COMPELETE event ends and the unfinished event has been | 2046 // May be called when a COMPELETE event ends and the unfinished event has been |
| 2043 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). | 2047 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). |
| 2044 std::string TraceLog::EventToConsoleMessage(unsigned char phase, | 2048 std::string TraceLog::EventToConsoleMessage(unsigned char phase, |
| 2045 const TimeTicks& timestamp, | 2049 const TimeTicks& timestamp, |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2585 } | 2589 } |
| 2586 | 2590 |
| 2587 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2591 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
| 2588 if (*category_group_enabled_) { | 2592 if (*category_group_enabled_) { |
| 2589 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2593 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
| 2590 name_, event_handle_); | 2594 name_, event_handle_); |
| 2591 } | 2595 } |
| 2592 } | 2596 } |
| 2593 | 2597 |
| 2594 } // namespace trace_event_internal | 2598 } // namespace trace_event_internal |
| OLD | NEW |