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 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 AddTraceEventInternal( | |
dsinclair
2015/02/09 21:11:20
Instead of adding the Internal version, just have
Benoit L
2015/02/10 15:31:35
Done.
| |
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 | 1953 |
1912 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) | 1954 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) |
1913 id ^= process_id_hash_; | 1955 id ^= process_id_hash_; |
1914 | 1956 |
1915 TimeTicks now = OffsetTimestamp(timestamp); | 1957 TimeTicks now = OffsetTimestamp(timestamp); |
1916 TimeTicks thread_now = ThreadNow(); | |
1917 | 1958 |
1918 ThreadLocalEventBuffer* thread_local_event_buffer = NULL; | 1959 ThreadLocalEventBuffer* thread_local_event_buffer = NULL; |
1919 // A ThreadLocalEventBuffer needs the message loop | 1960 // A ThreadLocalEventBuffer needs the message loop |
1920 // - to know when the thread exits; | 1961 // - to know when the thread exits; |
1921 // - to handle the final flush. | 1962 // - to handle the final flush. |
1922 // For a thread without a message loop or the message loop may be blocked, the | 1963 // 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. | 1964 // trace events will be added into the main buffer directly. |
1924 if (!thread_blocks_message_loop_.Get() && MessageLoop::current()) { | 1965 if (!thread_blocks_message_loop_.Get() && MessageLoop::current()) { |
1925 thread_local_event_buffer = thread_local_event_buffer_.Get(); | 1966 thread_local_event_buffer = thread_local_event_buffer_.Get(); |
1926 if (thread_local_event_buffer && | 1967 if (thread_local_event_buffer && |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1978 | 2019 |
1979 TraceEvent* trace_event = NULL; | 2020 TraceEvent* trace_event = NULL; |
1980 if (thread_local_event_buffer) { | 2021 if (thread_local_event_buffer) { |
1981 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); | 2022 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); |
1982 } else { | 2023 } else { |
1983 lock.EnsureAcquired(); | 2024 lock.EnsureAcquired(); |
1984 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true); | 2025 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true); |
1985 } | 2026 } |
1986 | 2027 |
1987 if (trace_event) { | 2028 if (trace_event) { |
1988 trace_event->Initialize(thread_id, now, thread_now, phase, | 2029 trace_event->Initialize(thread_id, now, thread_time, phase, |
1989 category_group_enabled, name, id, | 2030 category_group_enabled, name, id, |
1990 num_args, arg_names, arg_types, arg_values, | 2031 num_args, arg_names, arg_types, arg_values, |
1991 convertable_values, flags); | 2032 convertable_values, flags); |
1992 | 2033 |
1993 #if defined(OS_ANDROID) | 2034 #if defined(OS_ANDROID) |
1994 trace_event->SendToATrace(); | 2035 trace_event->SendToATrace(); |
1995 #endif | 2036 #endif |
1996 } | 2037 } |
1997 | 2038 |
1998 if (trace_options() & kInternalEchoToConsole) { | 2039 if (trace_options() & kInternalEchoToConsole) { |
(...skipping 28 matching lines...) Expand all Loading... | |
2027 event_callback(now, | 2068 event_callback(now, |
2028 phase == TRACE_EVENT_PHASE_COMPLETE ? | 2069 phase == TRACE_EVENT_PHASE_COMPLETE ? |
2029 TRACE_EVENT_PHASE_BEGIN : phase, | 2070 TRACE_EVENT_PHASE_BEGIN : phase, |
2030 category_group_enabled, name, id, | 2071 category_group_enabled, name, id, |
2031 num_args, arg_names, arg_types, arg_values, | 2072 num_args, arg_names, arg_types, arg_values, |
2032 flags); | 2073 flags); |
2033 } | 2074 } |
2034 } | 2075 } |
2035 | 2076 |
2036 if (thread_local_event_buffer) | 2077 if (thread_local_event_buffer) |
2037 thread_local_event_buffer->ReportOverhead(now, thread_now); | 2078 thread_local_event_buffer->ReportOverhead(now, thread_time); |
2038 | 2079 |
2039 return handle; | 2080 return handle; |
2040 } | 2081 } |
2041 | 2082 |
2042 // May be called when a COMPELETE event ends and the unfinished event has been | 2083 // 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). | 2084 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). |
2044 std::string TraceLog::EventToConsoleMessage(unsigned char phase, | 2085 std::string TraceLog::EventToConsoleMessage(unsigned char phase, |
2045 const TimeTicks& timestamp, | 2086 const TimeTicks& timestamp, |
2046 TraceEvent* trace_event) { | 2087 TraceEvent* trace_event) { |
2047 AutoLock thread_info_lock(thread_info_lock_); | 2088 AutoLock thread_info_lock(thread_info_lock_); |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2585 } | 2626 } |
2586 | 2627 |
2587 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2628 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
2588 if (*category_group_enabled_) { | 2629 if (*category_group_enabled_) { |
2589 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2630 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
2590 name_, event_handle_); | 2631 name_, event_handle_); |
2591 } | 2632 } |
2592 } | 2633 } |
2593 | 2634 |
2594 } // namespace trace_event_internal | 2635 } // namespace trace_event_internal |
OLD | NEW |