| 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 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "base/sys_info.h" | 29 #include "base/sys_info.h" |
| 30 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 30 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 31 #include "base/thread_task_runner_handle.h" | 31 #include "base/thread_task_runner_handle.h" |
| 32 #include "base/threading/platform_thread.h" | 32 #include "base/threading/platform_thread.h" |
| 33 #include "base/threading/thread_id_name_manager.h" | 33 #include "base/threading/thread_id_name_manager.h" |
| 34 #include "base/threading/worker_pool.h" | 34 #include "base/threading/worker_pool.h" |
| 35 #include "base/time/time.h" | 35 #include "base/time/time.h" |
| 36 #include "base/trace_event/trace_event.h" | 36 #include "base/trace_event/trace_event.h" |
| 37 #include "base/trace_event/trace_event_synthetic_delay.h" | 37 #include "base/trace_event/trace_event_synthetic_delay.h" |
| 38 | 38 |
| 39 #if defined(OS_WIN) | |
| 40 #include "base/trace_event/trace_event_etw_export_win.h" | |
| 41 #include "base/trace_event/trace_event_win.h" | |
| 42 #endif | |
| 43 | |
| 44 class DeleteTraceLogForTesting { | 39 class DeleteTraceLogForTesting { |
| 45 public: | 40 public: |
| 46 static void Delete() { | 41 static void Delete() { |
| 47 Singleton<base::trace_event::TraceLog, | 42 Singleton<base::trace_event::TraceLog, |
| 48 LeakySingletonTraits<base::trace_event::TraceLog>>::OnExit(0); | 43 LeakySingletonTraits<base::trace_event::TraceLog>>::OnExit(0); |
| 49 } | 44 } |
| 50 }; | 45 }; |
| 51 | 46 |
| 52 // The thread buckets for the sampling profiler. | 47 // The thread buckets for the sampling profiler. |
| 53 BASE_EXPORT TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; | 48 BASE_EXPORT TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; |
| (...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 const char* category_group = g_category_groups[category_index]; | 1226 const char* category_group = g_category_groups[category_index]; |
| 1232 if (mode_ == RECORDING_MODE && | 1227 if (mode_ == RECORDING_MODE && |
| 1233 trace_config_.IsCategoryGroupEnabled(category_group)) | 1228 trace_config_.IsCategoryGroupEnabled(category_group)) |
| 1234 enabled_flag |= ENABLED_FOR_RECORDING; | 1229 enabled_flag |= ENABLED_FOR_RECORDING; |
| 1235 else if (mode_ == MONITORING_MODE && | 1230 else if (mode_ == MONITORING_MODE && |
| 1236 trace_config_.IsCategoryGroupEnabled(category_group)) | 1231 trace_config_.IsCategoryGroupEnabled(category_group)) |
| 1237 enabled_flag |= ENABLED_FOR_MONITORING; | 1232 enabled_flag |= ENABLED_FOR_MONITORING; |
| 1238 if (event_callback_ && | 1233 if (event_callback_ && |
| 1239 event_callback_trace_config_.IsCategoryGroupEnabled(category_group)) | 1234 event_callback_trace_config_.IsCategoryGroupEnabled(category_group)) |
| 1240 enabled_flag |= ENABLED_FOR_EVENT_CALLBACK; | 1235 enabled_flag |= ENABLED_FOR_EVENT_CALLBACK; |
| 1241 #if defined(OS_WIN) | |
| 1242 if (base::trace_event::TraceEventETWExport::isETWExportEnabled()) | |
| 1243 enabled_flag |= ENABLED_FOR_ETW_EXPORT; | |
| 1244 #endif | |
| 1245 | |
| 1246 g_category_group_enabled[category_index] = enabled_flag; | 1236 g_category_group_enabled[category_index] = enabled_flag; |
| 1247 } | 1237 } |
| 1248 | 1238 |
| 1249 void TraceLog::UpdateCategoryGroupEnabledFlags() { | 1239 void TraceLog::UpdateCategoryGroupEnabledFlags() { |
| 1250 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index); | 1240 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index); |
| 1251 for (size_t i = 0; i < category_index; i++) | 1241 for (size_t i = 0; i < category_index; i++) |
| 1252 UpdateCategoryGroupEnabledFlag(i); | 1242 UpdateCategoryGroupEnabledFlag(i); |
| 1253 } | 1243 } |
| 1254 | 1244 |
| 1255 void TraceLog::UpdateSyntheticDelaysFromTraceConfig() { | 1245 void TraceLog::UpdateSyntheticDelaysFromTraceConfig() { |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1934 new_name) != existing_names.end(); | 1924 new_name) != existing_names.end(); |
| 1935 if (!found) { | 1925 if (!found) { |
| 1936 if (existing_names.size()) | 1926 if (existing_names.size()) |
| 1937 existing_name->second.push_back(','); | 1927 existing_name->second.push_back(','); |
| 1938 existing_name->second.append(new_name); | 1928 existing_name->second.append(new_name); |
| 1939 } | 1929 } |
| 1940 } | 1930 } |
| 1941 } | 1931 } |
| 1942 } | 1932 } |
| 1943 | 1933 |
| 1944 #if defined(OS_WIN) | |
| 1945 // This is done sooner rather than later, to avoid creating the event and | |
| 1946 // acquiring the lock, which is not needed for ETW as it's already threadsafe. | |
| 1947 if (*category_group_enabled & ENABLED_FOR_ETW_EXPORT) | |
| 1948 TraceEventETWExport::AddEvent(phase, category_group_enabled, name, id, | |
| 1949 num_args, arg_names, arg_types, arg_values, | |
| 1950 convertable_values); | |
| 1951 #endif // OS_WIN | |
| 1952 | |
| 1953 std::string console_message; | 1934 std::string console_message; |
| 1954 if (*category_group_enabled & | 1935 if (*category_group_enabled & |
| 1955 (ENABLED_FOR_RECORDING | ENABLED_FOR_MONITORING)) { | 1936 (ENABLED_FOR_RECORDING | ENABLED_FOR_MONITORING)) { |
| 1956 OptionalAutoLock lock(&lock_); | 1937 OptionalAutoLock lock(&lock_); |
| 1957 | 1938 |
| 1958 TraceEvent* trace_event = NULL; | 1939 TraceEvent* trace_event = NULL; |
| 1959 if (thread_local_event_buffer) { | 1940 if (thread_local_event_buffer) { |
| 1960 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); | 1941 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); |
| 1961 } else { | 1942 } else { |
| 1962 lock.EnsureAcquired(); | 1943 lock.EnsureAcquired(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2064 if (phase == TRACE_EVENT_PHASE_BEGIN) | 2045 if (phase == TRACE_EVENT_PHASE_BEGIN) |
| 2065 thread_event_start_times_[thread_id].push(timestamp); | 2046 thread_event_start_times_[thread_id].push(timestamp); |
| 2066 | 2047 |
| 2067 return log.str(); | 2048 return log.str(); |
| 2068 } | 2049 } |
| 2069 | 2050 |
| 2070 void TraceLog::AddTraceEventEtw(char phase, | 2051 void TraceLog::AddTraceEventEtw(char phase, |
| 2071 const char* name, | 2052 const char* name, |
| 2072 const void* id, | 2053 const void* id, |
| 2073 const char* extra) { | 2054 const char* extra) { |
| 2074 #if defined(OS_WIN) | |
| 2075 TraceEventETWProvider::Trace(name, phase, id, extra); | |
| 2076 #endif | |
| 2077 INTERNAL_TRACE_EVENT_ADD(phase, "ETW Trace Event", name, | 2055 INTERNAL_TRACE_EVENT_ADD(phase, "ETW Trace Event", name, |
| 2078 TRACE_EVENT_FLAG_COPY, "id", id, "extra", extra); | 2056 TRACE_EVENT_FLAG_COPY, "id", id, "extra", extra); |
| 2079 } | 2057 } |
| 2080 | 2058 |
| 2081 void TraceLog::AddTraceEventEtw(char phase, | 2059 void TraceLog::AddTraceEventEtw(char phase, |
| 2082 const char* name, | 2060 const char* name, |
| 2083 const void* id, | 2061 const void* id, |
| 2084 const std::string& extra) { | 2062 const std::string& extra) { |
| 2085 #if defined(OS_WIN) | 2063 INTERNAL_TRACE_EVENT_ADD(phase, "ETW Trace Event", name, |
| 2086 TraceEventETWProvider::Trace(name, phase, id, extra); | |
| 2087 #endif | |
| 2088 INTERNAL_TRACE_EVENT_ADD(phase, "ETW Trace Event", name, | |
| 2089 TRACE_EVENT_FLAG_COPY, "id", id, "extra", extra); | 2064 TRACE_EVENT_FLAG_COPY, "id", id, "extra", extra); |
| 2090 } | 2065 } |
| 2091 | 2066 |
| 2092 void TraceLog::UpdateTraceEventDuration( | 2067 void TraceLog::UpdateTraceEventDuration( |
| 2093 const unsigned char* category_group_enabled, | 2068 const unsigned char* category_group_enabled, |
| 2094 const char* name, | 2069 const char* name, |
| 2095 TraceEventHandle handle) { | 2070 TraceEventHandle handle) { |
| 2096 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when | 2071 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when |
| 2097 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> | 2072 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> |
| 2098 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... | 2073 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2359 } | 2334 } |
| 2360 | 2335 |
| 2361 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2336 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
| 2362 if (*category_group_enabled_) { | 2337 if (*category_group_enabled_) { |
| 2363 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2338 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
| 2364 name_, event_handle_); | 2339 name_, event_handle_); |
| 2365 } | 2340 } |
| 2366 } | 2341 } |
| 2367 | 2342 |
| 2368 } // namespace trace_event_internal | 2343 } // namespace trace_event_internal |
| OLD | NEW |