Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: base/trace_event/trace_event_impl.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/trace_event/trace_event_impl.h ('k') | base/trace_event/trace_event_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1890 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 1901
1902 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when 1902 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when
1903 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> 1903 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) ->
1904 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... 1904 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ...
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 DCHECK(!timestamp.is_null());
1911 1912
1912 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) 1913 if (flags & TRACE_EVENT_FLAG_MANGLE_ID)
1913 id ^= process_id_hash_; 1914 id ^= process_id_hash_;
1914 1915
1915 TimeTicks now = OffsetTimestamp(timestamp); 1916 TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp);
1917 TimeTicks now = OffsetNow();
1916 TimeTicks thread_now = ThreadNow(); 1918 TimeTicks thread_now = ThreadNow();
1917 1919
1918 ThreadLocalEventBuffer* thread_local_event_buffer = NULL; 1920 ThreadLocalEventBuffer* thread_local_event_buffer = NULL;
1919 // A ThreadLocalEventBuffer needs the message loop 1921 // A ThreadLocalEventBuffer needs the message loop
1920 // - to know when the thread exits; 1922 // - to know when the thread exits;
1921 // - to handle the final flush. 1923 // - to handle the final flush.
1922 // For a thread without a message loop or the message loop may be blocked, the 1924 // 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. 1925 // trace events will be added into the main buffer directly.
1924 if (!thread_blocks_message_loop_.Get() && MessageLoop::current()) { 1926 if (!thread_blocks_message_loop_.Get() && MessageLoop::current()) {
1925 thread_local_event_buffer = thread_local_event_buffer_.Get(); 1927 thread_local_event_buffer = thread_local_event_buffer_.Get();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1978 1980
1979 TraceEvent* trace_event = NULL; 1981 TraceEvent* trace_event = NULL;
1980 if (thread_local_event_buffer) { 1982 if (thread_local_event_buffer) {
1981 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); 1983 trace_event = thread_local_event_buffer->AddTraceEvent(&handle);
1982 } else { 1984 } else {
1983 lock.EnsureAcquired(); 1985 lock.EnsureAcquired();
1984 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true); 1986 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true);
1985 } 1987 }
1986 1988
1987 if (trace_event) { 1989 if (trace_event) {
1988 trace_event->Initialize(thread_id, now, thread_now, phase, 1990 trace_event->Initialize(thread_id, offset_event_timestamp, thread_now,
1989 category_group_enabled, name, id, 1991 phase, category_group_enabled, name, id,
1990 num_args, arg_names, arg_types, arg_values, 1992 num_args, arg_names, arg_types, arg_values,
1991 convertable_values, flags); 1993 convertable_values, flags);
1992 1994
1993 #if defined(OS_ANDROID) 1995 #if defined(OS_ANDROID)
1994 trace_event->SendToATrace(); 1996 trace_event->SendToATrace();
1995 #endif 1997 #endif
1996 } 1998 }
1997 1999
1998 if (trace_options() & kInternalEchoToConsole) { 2000 if (trace_options() & kInternalEchoToConsole) {
1999 console_message = EventToConsoleMessage( 2001 console_message = EventToConsoleMessage(
(...skipping 17 matching lines...) Expand all
2017 if (event_name_matches) { 2019 if (event_name_matches) {
2018 if (!watch_event_callback_copy.is_null()) 2020 if (!watch_event_callback_copy.is_null())
2019 watch_event_callback_copy.Run(); 2021 watch_event_callback_copy.Run();
2020 } 2022 }
2021 } 2023 }
2022 2024
2023 if (*category_group_enabled & ENABLED_FOR_EVENT_CALLBACK) { 2025 if (*category_group_enabled & ENABLED_FOR_EVENT_CALLBACK) {
2024 EventCallback event_callback = reinterpret_cast<EventCallback>( 2026 EventCallback event_callback = reinterpret_cast<EventCallback>(
2025 subtle::NoBarrier_Load(&event_callback_)); 2027 subtle::NoBarrier_Load(&event_callback_));
2026 if (event_callback) { 2028 if (event_callback) {
2027 event_callback(now, 2029 event_callback(offset_event_timestamp,
2028 phase == TRACE_EVENT_PHASE_COMPLETE ? 2030 phase == TRACE_EVENT_PHASE_COMPLETE ?
2029 TRACE_EVENT_PHASE_BEGIN : phase, 2031 TRACE_EVENT_PHASE_BEGIN : phase,
2030 category_group_enabled, name, id, 2032 category_group_enabled, name, id,
2031 num_args, arg_names, arg_types, arg_values, 2033 num_args, arg_names, arg_types, arg_values,
2032 flags); 2034 flags);
2033 } 2035 }
2034 } 2036 }
2035 2037
2038 // Use |now| instead of |offset_event_timestamp| to compute overhead, because
2039 // event timestamp may be not the real time that we started to add the event
2040 // (e.g. event with zero timestamp or that was generated some time ago).
2036 if (thread_local_event_buffer) 2041 if (thread_local_event_buffer)
2037 thread_local_event_buffer->ReportOverhead(now, thread_now); 2042 thread_local_event_buffer->ReportOverhead(now, thread_now);
2038 2043
2039 return handle; 2044 return handle;
2040 } 2045 }
2041 2046
2042 // May be called when a COMPELETE event ends and the unfinished event has been 2047 // 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). 2048 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL).
2044 std::string TraceLog::EventToConsoleMessage(unsigned char phase, 2049 std::string TraceLog::EventToConsoleMessage(unsigned char phase,
2045 const TimeTicks& timestamp, 2050 const TimeTicks& timestamp,
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
2585 } 2590 }
2586 2591
2587 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 2592 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
2588 if (*category_group_enabled_) { 2593 if (*category_group_enabled_) {
2589 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, 2594 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_,
2590 name_, event_handle_); 2595 name_, event_handle_);
2591 } 2596 }
2592 } 2597 }
2593 2598
2594 } // namespace trace_event_internal 2599 } // namespace trace_event_internal
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_impl.h ('k') | base/trace_event/trace_event_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698