| 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 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 flush_message_loop_proxy_->PostDelayedTask( | 1728 flush_message_loop_proxy_->PostDelayedTask( |
| 1729 FROM_HERE, | 1729 FROM_HERE, |
| 1730 Bind(&TraceLog::OnFlushTimeout, Unretained(this), generation), | 1730 Bind(&TraceLog::OnFlushTimeout, Unretained(this), generation), |
| 1731 TimeDelta::FromMilliseconds(kThreadFlushTimeoutMs)); | 1731 TimeDelta::FromMilliseconds(kThreadFlushTimeoutMs)); |
| 1732 return; | 1732 return; |
| 1733 } | 1733 } |
| 1734 | 1734 |
| 1735 FinishFlush(generation); | 1735 FinishFlush(generation); |
| 1736 } | 1736 } |
| 1737 | 1737 |
| 1738 |
| 1738 void TraceLog::ConvertTraceEventsToTraceFormat( | 1739 void TraceLog::ConvertTraceEventsToTraceFormat( |
| 1739 scoped_ptr<TraceBuffer> logged_events, | 1740 scoped_ptr<TraceBuffer> logged_events, |
| 1740 const TraceLog::OutputCallback& flush_output_callback) { | 1741 const TraceLog::OutputCallback& flush_output_callback) { |
| 1741 | 1742 |
| 1742 if (flush_output_callback.is_null()) | 1743 if (flush_output_callback.is_null()) |
| 1743 return; | 1744 return; |
| 1744 | 1745 |
| 1745 // The callback need to be called at least once even if there is no events | 1746 // The callback needs to be called at least once even if there is no events to |
| 1746 // to let the caller know the completion of flush. | 1747 // let the caller know the completion of flush. |
| 1747 bool has_more_events = true; | 1748 bool has_more_events = true; |
| 1749 |
| 1748 do { | 1750 do { |
| 1749 scoped_refptr<RefCountedString> json_events_str_ptr = | 1751 scoped_refptr<RefCountedString> json_events_str_ptr = |
| 1750 new RefCountedString(); | 1752 new RefCountedString(); |
| 1751 | 1753 |
| 1752 for (size_t i = 0; i < kTraceEventBatchChunks; ++i) { | 1754 for (size_t i = 0; i < kTraceEventBatchChunks; ++i) { |
| 1753 const TraceBufferChunk* chunk = logged_events->NextChunk(); | 1755 const TraceBufferChunk* chunk = logged_events->NextChunk(); |
| 1754 if (!chunk) { | 1756 if (!chunk) { |
| 1755 has_more_events = false; | 1757 has_more_events = false; |
| 1756 break; | 1758 break; |
| 1757 } | 1759 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1879 convertable_values, flags); | 1881 convertable_values, flags); |
| 1880 } | 1882 } |
| 1881 | 1883 |
| 1882 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( | 1884 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( |
| 1883 char phase, | 1885 char phase, |
| 1884 const unsigned char* category_group_enabled, | 1886 const unsigned char* category_group_enabled, |
| 1885 const char* name, | 1887 const char* name, |
| 1886 unsigned long long id, | 1888 unsigned long long id, |
| 1887 int thread_id, | 1889 int thread_id, |
| 1888 const TimeTicks& timestamp, | 1890 const TimeTicks& timestamp, |
| 1891 const TimeTicks& thread_time, |
| 1892 int num_args, |
| 1893 const char** arg_names, |
| 1894 const unsigned char* arg_types, |
| 1895 const unsigned long long* arg_values, |
| 1896 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
| 1897 unsigned char flags) { |
| 1898 return AddTraceEventInternal( |
| 1899 phase, category_group_enabled, name, id, thread_id, timestamp, |
| 1900 thread_time, num_args, arg_names, arg_types, arg_values, |
| 1901 convertable_values, flags); |
| 1902 } |
| 1903 |
| 1904 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( |
| 1905 char phase, |
| 1906 const unsigned char* category_group_enabled, |
| 1907 const char* name, |
| 1908 unsigned long long id, |
| 1909 int thread_id, |
| 1910 const TimeTicks& timestamp, |
| 1889 int num_args, | 1911 int num_args, |
| 1890 const char** arg_names, | 1912 const char** arg_names, |
| 1891 const unsigned char* arg_types, | 1913 const unsigned char* arg_types, |
| 1914 const unsigned long long* arg_values, |
| 1915 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
| 1916 unsigned char flags) { |
| 1917 return AddTraceEventWithThreadIdAndTimestamp( |
| 1918 phase, category_group_enabled, name, id, thread_id, timestamp, |
| 1919 ThreadNow(), num_args, arg_names, arg_types, arg_values, |
| 1920 convertable_values, flags); |
| 1921 } |
| 1922 |
| 1923 TraceEventHandle TraceLog::AddTraceEventInternal( |
| 1924 char phase, |
| 1925 const unsigned char* category_group_enabled, |
| 1926 const char* name, |
| 1927 unsigned long long id, |
| 1928 int thread_id, |
| 1929 const TimeTicks& timestamp, |
| 1930 const TimeTicks& thread_time, |
| 1931 int num_args, |
| 1932 const char** arg_names, |
| 1933 const unsigned char* arg_types, |
| 1892 const unsigned long long* arg_values, | 1934 const unsigned long long* arg_values, |
| 1893 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 1935 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
| 1894 unsigned char flags) { | 1936 unsigned char flags) { |
| 1895 TraceEventHandle handle = { 0, 0, 0 }; | 1937 TraceEventHandle handle = { 0, 0, 0 }; |
| 1896 if (!*category_group_enabled) | 1938 if (!*category_group_enabled) |
| 1897 return handle; | 1939 return handle; |
| 1898 | 1940 |
| 1899 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when | 1941 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when |
| 1900 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> | 1942 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> |
| 1901 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... | 1943 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2027 event_callback(offset_event_timestamp, | 2069 event_callback(offset_event_timestamp, |
| 2028 phase == TRACE_EVENT_PHASE_COMPLETE ? | 2070 phase == TRACE_EVENT_PHASE_COMPLETE ? |
| 2029 TRACE_EVENT_PHASE_BEGIN : phase, | 2071 TRACE_EVENT_PHASE_BEGIN : phase, |
| 2030 category_group_enabled, name, id, | 2072 category_group_enabled, name, id, |
| 2031 num_args, arg_names, arg_types, arg_values, | 2073 num_args, arg_names, arg_types, arg_values, |
| 2032 flags); | 2074 flags); |
| 2033 } | 2075 } |
| 2034 } | 2076 } |
| 2035 | 2077 |
| 2036 if (thread_local_event_buffer) | 2078 if (thread_local_event_buffer) |
| 2037 thread_local_event_buffer->ReportOverhead(now, thread_now); | 2079 thread_local_event_buffer->ReportOverhead(now, thread_time); |
| 2038 | 2080 |
| 2039 return handle; | 2081 return handle; |
| 2040 } | 2082 } |
| 2041 | 2083 |
| 2042 // May be called when a COMPELETE event ends and the unfinished event has been | 2084 // 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). | 2085 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). |
| 2044 std::string TraceLog::EventToConsoleMessage(unsigned char phase, | 2086 std::string TraceLog::EventToConsoleMessage(unsigned char phase, |
| 2045 const TimeTicks& timestamp, | 2087 const TimeTicks& timestamp, |
| 2046 TraceEvent* trace_event) { | 2088 TraceEvent* trace_event) { |
| 2047 AutoLock thread_info_lock(thread_info_lock_); | 2089 AutoLock thread_info_lock(thread_info_lock_); |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2602 } | 2644 } |
| 2603 | 2645 |
| 2604 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2646 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
| 2605 if (*category_group_enabled_) { | 2647 if (*category_group_enabled_) { |
| 2606 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2648 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
| 2607 name_, event_handle_); | 2649 name_, event_handle_); |
| 2608 } | 2650 } |
| 2609 } | 2651 } |
| 2610 | 2652 |
| 2611 } // namespace trace_event_internal | 2653 } // namespace trace_event_internal |
| OLD | NEW |