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

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

Issue 928563003: Avoid twice clock reading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.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.h ('k') | no next file » | 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 1896 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DCHECK(!timestamp.is_null());
1912 1912
1913 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) 1913 if (flags & TRACE_EVENT_FLAG_MANGLE_ID)
1914 id ^= process_id_hash_; 1914 id ^= process_id_hash_;
1915 1915
1916 TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp); 1916 TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp);
1917 TimeTicks now = OffsetNow(); 1917 TimeTicks now = flags & TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP ?
1918 OffsetNow() : offset_event_timestamp;
1918 TimeTicks thread_now = ThreadNow(); 1919 TimeTicks thread_now = ThreadNow();
1919 1920
1920 ThreadLocalEventBuffer* thread_local_event_buffer = NULL; 1921 ThreadLocalEventBuffer* thread_local_event_buffer = NULL;
1921 // A ThreadLocalEventBuffer needs the message loop 1922 // A ThreadLocalEventBuffer needs the message loop
1922 // - to know when the thread exits; 1923 // - to know when the thread exits;
1923 // - to handle the final flush. 1924 // - to handle the final flush.
1924 // For a thread without a message loop or the message loop may be blocked, the 1925 // For a thread without a message loop or the message loop may be blocked, the
1925 // trace events will be added into the main buffer directly. 1926 // trace events will be added into the main buffer directly.
1926 if (!thread_blocks_message_loop_.Get() && MessageLoop::current()) { 1927 if (!thread_blocks_message_loop_.Get() && MessageLoop::current()) {
1927 thread_local_event_buffer = thread_local_event_buffer_.Get(); 1928 thread_local_event_buffer = thread_local_event_buffer_.Get();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2028 if (event_callback) { 2029 if (event_callback) {
2029 event_callback(offset_event_timestamp, 2030 event_callback(offset_event_timestamp,
2030 phase == TRACE_EVENT_PHASE_COMPLETE ? 2031 phase == TRACE_EVENT_PHASE_COMPLETE ?
2031 TRACE_EVENT_PHASE_BEGIN : phase, 2032 TRACE_EVENT_PHASE_BEGIN : phase,
2032 category_group_enabled, name, id, 2033 category_group_enabled, name, id,
2033 num_args, arg_names, arg_types, arg_values, 2034 num_args, arg_names, arg_types, arg_values,
2034 flags); 2035 flags);
2035 } 2036 }
2036 } 2037 }
2037 2038
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).
2041 if (thread_local_event_buffer) 2039 if (thread_local_event_buffer)
2042 thread_local_event_buffer->ReportOverhead(now, thread_now); 2040 thread_local_event_buffer->ReportOverhead(now, thread_now);
2043 2041
2044 return handle; 2042 return handle;
2045 } 2043 }
2046 2044
2047 // May be called when a COMPELETE event ends and the unfinished event has been 2045 // May be called when a COMPELETE event ends and the unfinished event has been
2048 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). 2046 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL).
2049 std::string TraceLog::EventToConsoleMessage(unsigned char phase, 2047 std::string TraceLog::EventToConsoleMessage(unsigned char phase,
2050 const TimeTicks& timestamp, 2048 const TimeTicks& timestamp,
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
2590 } 2588 }
2591 2589
2592 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 2590 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
2593 if (*category_group_enabled_) { 2591 if (*category_group_enabled_) {
2594 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, 2592 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_,
2595 name_, event_handle_); 2593 name_, event_handle_);
2596 } 2594 }
2597 } 2595 }
2598 2596
2599 } // namespace trace_event_internal 2597 } // namespace trace_event_internal
OLDNEW
« no previous file with comments | « base/trace_event/trace_event.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698