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

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

Issue 874543003: Add support for TraceEvent before the native library is loaded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 9 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
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 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 flush_message_loop_proxy_->PostDelayedTask( 1731 flush_message_loop_proxy_->PostDelayedTask(
1732 FROM_HERE, 1732 FROM_HERE,
1733 Bind(&TraceLog::OnFlushTimeout, Unretained(this), generation), 1733 Bind(&TraceLog::OnFlushTimeout, Unretained(this), generation),
1734 TimeDelta::FromMilliseconds(kThreadFlushTimeoutMs)); 1734 TimeDelta::FromMilliseconds(kThreadFlushTimeoutMs));
1735 return; 1735 return;
1736 } 1736 }
1737 1737
1738 FinishFlush(generation); 1738 FinishFlush(generation);
1739 } 1739 }
1740 1740
1741
1741 void TraceLog::ConvertTraceEventsToTraceFormat( 1742 void TraceLog::ConvertTraceEventsToTraceFormat(
1742 scoped_ptr<TraceBuffer> logged_events, 1743 scoped_ptr<TraceBuffer> logged_events,
1743 const TraceLog::OutputCallback& flush_output_callback) { 1744 const TraceLog::OutputCallback& flush_output_callback) {
1744 1745
1745 if (flush_output_callback.is_null()) 1746 if (flush_output_callback.is_null())
1746 return; 1747 return;
1747 1748
1748 // The callback need to be called at least once even if there is no events 1749 // The callback needs to be called at least once even if there is no events to
1749 // to let the caller know the completion of flush. 1750 // let the caller know the completion of flush.
1750 bool has_more_events = true; 1751 bool has_more_events = true;
1752
1751 do { 1753 do {
1752 scoped_refptr<RefCountedString> json_events_str_ptr = 1754 scoped_refptr<RefCountedString> json_events_str_ptr =
1753 new RefCountedString(); 1755 new RefCountedString();
1754 1756
1755 for (size_t i = 0; i < kTraceEventBatchChunks; ++i) { 1757 for (size_t i = 0; i < kTraceEventBatchChunks; ++i) {
1756 const TraceBufferChunk* chunk = logged_events->NextChunk(); 1758 const TraceBufferChunk* chunk = logged_events->NextChunk();
1757 if (!chunk) { 1759 if (!chunk) {
1758 has_more_events = false; 1760 has_more_events = false;
1759 break; 1761 break;
1760 } 1762 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 convertable_values, flags); 1884 convertable_values, flags);
1883 } 1885 }
1884 1886
1885 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( 1887 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
1886 char phase, 1888 char phase,
1887 const unsigned char* category_group_enabled, 1889 const unsigned char* category_group_enabled,
1888 const char* name, 1890 const char* name,
1889 unsigned long long id, 1891 unsigned long long id,
1890 int thread_id, 1892 int thread_id,
1891 const TimeTicks& timestamp, 1893 const TimeTicks& timestamp,
1894 const TimeTicks& thread_time,
1895 int num_args,
1896 const char** arg_names,
1897 const unsigned char* arg_types,
1898 const unsigned long long* arg_values,
1899 const scoped_refptr<ConvertableToTraceFormat>* convertable_values,
1900 unsigned char flags) {
1901 return AddTraceEventInternal(
1902 phase, category_group_enabled, name, id, thread_id, timestamp,
1903 thread_time, num_args, arg_names, arg_types, arg_values,
1904 convertable_values, flags);
1905 }
1906
1907 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
1908 char phase,
1909 const unsigned char* category_group_enabled,
1910 const char* name,
1911 unsigned long long id,
1912 int thread_id,
1913 const TimeTicks& timestamp,
1892 int num_args, 1914 int num_args,
1893 const char** arg_names, 1915 const char** arg_names,
1894 const unsigned char* arg_types, 1916 const unsigned char* arg_types,
1917 const unsigned long long* arg_values,
1918 const scoped_refptr<ConvertableToTraceFormat>* convertable_values,
1919 unsigned char flags) {
1920 return AddTraceEventWithThreadIdAndTimestamp(
1921 phase, category_group_enabled, name, id, thread_id, timestamp,
1922 ThreadNow(), num_args, arg_names, arg_types, arg_values,
1923 convertable_values, flags);
1924 }
1925
1926 TraceEventHandle TraceLog::AddTraceEventInternal(
1927 char phase,
1928 const unsigned char* category_group_enabled,
1929 const char* name,
1930 unsigned long long id,
1931 int thread_id,
1932 const TimeTicks& timestamp,
1933 const TimeTicks& thread_time,
1934 int num_args,
1935 const char** arg_names,
1936 const unsigned char* arg_types,
1895 const unsigned long long* arg_values, 1937 const unsigned long long* arg_values,
1896 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, 1938 const scoped_refptr<ConvertableToTraceFormat>* convertable_values,
1897 unsigned char flags) { 1939 unsigned char flags) {
1898 TraceEventHandle handle = { 0, 0, 0 }; 1940 TraceEventHandle handle = { 0, 0, 0 };
1899 if (!*category_group_enabled) 1941 if (!*category_group_enabled)
1900 return handle; 1942 return handle;
1901 1943
1902 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when 1944 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when
1903 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> 1945 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) ->
1904 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... 1946 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ...
1905 if (thread_is_in_trace_event_.Get()) 1947 if (thread_is_in_trace_event_.Get())
1906 return handle; 1948 return handle;
1907 1949
1908 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_); 1950 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_);
1909 1951
1910 DCHECK(name); 1952 DCHECK(name);
1911 DCHECK(!timestamp.is_null()); 1953 DCHECK(!timestamp.is_null());
1912 1954
1913 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) 1955 if (flags & TRACE_EVENT_FLAG_MANGLE_ID)
1914 id ^= process_id_hash_; 1956 id ^= process_id_hash_;
1915 1957
1916 TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp); 1958 TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp);
1917 TimeTicks now = flags & TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP ? 1959 TimeTicks now = flags & TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP ?
1918 OffsetNow() : offset_event_timestamp; 1960 OffsetNow() : offset_event_timestamp;
1919 TimeTicks thread_now = ThreadNow(); 1961 TimeTicks thread_now = ThreadNow();
dsinclair 2015/03/16 14:41:23 Can this be removed and we just use thread_time?
Benoit L 2015/03/19 16:50:47 I'm not sure that I understand what you mean here.
dsinclair 2015/03/19 18:35:32 Right, but we've added another TimeTicks called th
1920 1962
1921 ThreadLocalEventBuffer* thread_local_event_buffer = NULL; 1963 ThreadLocalEventBuffer* thread_local_event_buffer = NULL;
1922 // A ThreadLocalEventBuffer needs the message loop 1964 // A ThreadLocalEventBuffer needs the message loop
1923 // - to know when the thread exits; 1965 // - to know when the thread exits;
1924 // - to handle the final flush. 1966 // - to handle the final flush.
1925 // For a thread without a message loop or the message loop may be blocked, the 1967 // For a thread without a message loop or the message loop may be blocked, the
1926 // trace events will be added into the main buffer directly. 1968 // trace events will be added into the main buffer directly.
1927 if (!thread_blocks_message_loop_.Get() && MessageLoop::current()) { 1969 if (!thread_blocks_message_loop_.Get() && MessageLoop::current()) {
1928 thread_local_event_buffer = thread_local_event_buffer_.Get(); 1970 thread_local_event_buffer = thread_local_event_buffer_.Get();
1929 if (thread_local_event_buffer && 1971 if (thread_local_event_buffer &&
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 event_callback(offset_event_timestamp, 2072 event_callback(offset_event_timestamp,
2031 phase == TRACE_EVENT_PHASE_COMPLETE ? 2073 phase == TRACE_EVENT_PHASE_COMPLETE ?
2032 TRACE_EVENT_PHASE_BEGIN : phase, 2074 TRACE_EVENT_PHASE_BEGIN : phase,
2033 category_group_enabled, name, id, 2075 category_group_enabled, name, id,
2034 num_args, arg_names, arg_types, arg_values, 2076 num_args, arg_names, arg_types, arg_values,
2035 flags); 2077 flags);
2036 } 2078 }
2037 } 2079 }
2038 2080
2039 if (thread_local_event_buffer) 2081 if (thread_local_event_buffer)
2040 thread_local_event_buffer->ReportOverhead(now, thread_now); 2082 thread_local_event_buffer->ReportOverhead(now, thread_time);
2041 2083
2042 return handle; 2084 return handle;
2043 } 2085 }
2044 2086
2045 // May be called when a COMPELETE event ends and the unfinished event has been 2087 // May be called when a COMPELETE event ends and the unfinished event has been
2046 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). 2088 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL).
2047 std::string TraceLog::EventToConsoleMessage(unsigned char phase, 2089 std::string TraceLog::EventToConsoleMessage(unsigned char phase,
2048 const TimeTicks& timestamp, 2090 const TimeTicks& timestamp,
2049 TraceEvent* trace_event) { 2091 TraceEvent* trace_event) {
2050 AutoLock thread_info_lock(thread_info_lock_); 2092 AutoLock thread_info_lock(thread_info_lock_);
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
2588 } 2630 }
2589 2631
2590 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 2632 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
2591 if (*category_group_enabled_) { 2633 if (*category_group_enabled_) {
2592 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, 2634 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_,
2593 name_, event_handle_); 2635 name_, event_handle_);
2594 } 2636 }
2595 } 2637 }
2596 2638
2597 } // namespace trace_event_internal 2639 } // namespace trace_event_internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698