OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_log.h" | 5 #include "base/trace_event/trace_log.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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 const T& value) { | 130 const T& value) { |
131 if (!trace_event) | 131 if (!trace_event) |
132 return; | 132 return; |
133 | 133 |
134 int num_args = 1; | 134 int num_args = 1; |
135 unsigned char arg_type; | 135 unsigned char arg_type; |
136 unsigned long long arg_value; | 136 unsigned long long arg_value; |
137 ::trace_event_internal::SetTraceValue(value, &arg_type, &arg_value); | 137 ::trace_event_internal::SetTraceValue(value, &arg_type, &arg_value); |
138 trace_event->Initialize( | 138 trace_event->Initialize( |
139 thread_id, | 139 thread_id, |
140 TraceTicks(), | 140 TimeTicks(), |
141 ThreadTicks(), | 141 ThreadTicks(), |
142 TRACE_EVENT_PHASE_METADATA, | 142 TRACE_EVENT_PHASE_METADATA, |
143 &g_category_group_enabled[g_category_metadata], | 143 &g_category_group_enabled[g_category_metadata], |
144 metadata_name, | 144 metadata_name, |
145 trace_event_internal::kNoId, // id | 145 trace_event_internal::kNoId, // id |
146 trace_event_internal::kNoId, // context_id | 146 trace_event_internal::kNoId, // context_id |
147 trace_event_internal::kNoId, // bind_id | 147 trace_event_internal::kNoId, // bind_id |
148 num_args, | 148 num_args, |
149 &arg_name, | 149 &arg_name, |
150 &arg_type, | 150 &arg_type, |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 const unsigned char* category_group_enabled, | 1072 const unsigned char* category_group_enabled, |
1073 const char* name, | 1073 const char* name, |
1074 unsigned long long id, | 1074 unsigned long long id, |
1075 int num_args, | 1075 int num_args, |
1076 const char** arg_names, | 1076 const char** arg_names, |
1077 const unsigned char* arg_types, | 1077 const unsigned char* arg_types, |
1078 const unsigned long long* arg_values, | 1078 const unsigned long long* arg_values, |
1079 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 1079 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
1080 unsigned int flags) { | 1080 unsigned int flags) { |
1081 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); | 1081 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); |
1082 base::TraceTicks now = base::TraceTicks::Now(); | 1082 base::TimeTicks now = base::TimeTicks::Now(); |
1083 return AddTraceEventWithThreadIdAndTimestamp( | 1083 return AddTraceEventWithThreadIdAndTimestamp( |
1084 phase, | 1084 phase, |
1085 category_group_enabled, | 1085 category_group_enabled, |
1086 name, | 1086 name, |
1087 id, | 1087 id, |
1088 trace_event_internal::kNoId, // context_id | 1088 trace_event_internal::kNoId, // context_id |
1089 trace_event_internal::kNoId, // bind_id | 1089 trace_event_internal::kNoId, // bind_id |
1090 thread_id, | 1090 thread_id, |
1091 now, | 1091 now, |
1092 num_args, | 1092 num_args, |
(...skipping 10 matching lines...) Expand all Loading... |
1103 const char* name, | 1103 const char* name, |
1104 unsigned long long id, | 1104 unsigned long long id, |
1105 unsigned long long context_id, | 1105 unsigned long long context_id, |
1106 int num_args, | 1106 int num_args, |
1107 const char** arg_names, | 1107 const char** arg_names, |
1108 const unsigned char* arg_types, | 1108 const unsigned char* arg_types, |
1109 const unsigned long long* arg_values, | 1109 const unsigned long long* arg_values, |
1110 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 1110 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
1111 unsigned int flags) { | 1111 unsigned int flags) { |
1112 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); | 1112 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); |
1113 base::TraceTicks now = base::TraceTicks::Now(); | 1113 base::TimeTicks now = base::TimeTicks::Now(); |
1114 return AddTraceEventWithThreadIdAndTimestamp( | 1114 return AddTraceEventWithThreadIdAndTimestamp( |
1115 phase, | 1115 phase, |
1116 category_group_enabled, | 1116 category_group_enabled, |
1117 name, | 1117 name, |
1118 id, | 1118 id, |
1119 context_id, | 1119 context_id, |
1120 trace_event_internal::kNoId, // bind_id | 1120 trace_event_internal::kNoId, // bind_id |
1121 thread_id, | 1121 thread_id, |
1122 now, | 1122 now, |
1123 num_args, | 1123 num_args, |
1124 arg_names, | 1124 arg_names, |
1125 arg_types, | 1125 arg_types, |
1126 arg_values, | 1126 arg_values, |
1127 convertable_values, | 1127 convertable_values, |
1128 flags | TRACE_EVENT_FLAG_HAS_CONTEXT_ID); | 1128 flags | TRACE_EVENT_FLAG_HAS_CONTEXT_ID); |
1129 } | 1129 } |
1130 | 1130 |
1131 // Handle legacy calls to AddTraceEventWithThreadIdAndTimestamp | 1131 // Handle legacy calls to AddTraceEventWithThreadIdAndTimestamp |
1132 // with kNoId as bind_id | 1132 // with kNoId as bind_id |
1133 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( | 1133 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( |
1134 char phase, | 1134 char phase, |
1135 const unsigned char* category_group_enabled, | 1135 const unsigned char* category_group_enabled, |
1136 const char* name, | 1136 const char* name, |
1137 unsigned long long id, | 1137 unsigned long long id, |
1138 unsigned long long context_id, | 1138 unsigned long long context_id, |
1139 int thread_id, | 1139 int thread_id, |
1140 const TraceTicks& timestamp, | 1140 const TimeTicks& timestamp, |
1141 int num_args, | 1141 int num_args, |
1142 const char** arg_names, | 1142 const char** arg_names, |
1143 const unsigned char* arg_types, | 1143 const unsigned char* arg_types, |
1144 const unsigned long long* arg_values, | 1144 const unsigned long long* arg_values, |
1145 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 1145 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
1146 unsigned int flags) { | 1146 unsigned int flags) { |
1147 return AddTraceEventWithThreadIdAndTimestamp( | 1147 return AddTraceEventWithThreadIdAndTimestamp( |
1148 phase, | 1148 phase, |
1149 category_group_enabled, | 1149 category_group_enabled, |
1150 name, | 1150 name, |
(...skipping 11 matching lines...) Expand all Loading... |
1162 } | 1162 } |
1163 | 1163 |
1164 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( | 1164 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( |
1165 char phase, | 1165 char phase, |
1166 const unsigned char* category_group_enabled, | 1166 const unsigned char* category_group_enabled, |
1167 const char* name, | 1167 const char* name, |
1168 unsigned long long id, | 1168 unsigned long long id, |
1169 unsigned long long context_id, | 1169 unsigned long long context_id, |
1170 unsigned long long bind_id, | 1170 unsigned long long bind_id, |
1171 int thread_id, | 1171 int thread_id, |
1172 const TraceTicks& timestamp, | 1172 const TimeTicks& timestamp, |
1173 int num_args, | 1173 int num_args, |
1174 const char** arg_names, | 1174 const char** arg_names, |
1175 const unsigned char* arg_types, | 1175 const unsigned char* arg_types, |
1176 const unsigned long long* arg_values, | 1176 const unsigned long long* arg_values, |
1177 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 1177 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
1178 unsigned int flags) { | 1178 unsigned int flags) { |
1179 TraceEventHandle handle = {0, 0, 0}; | 1179 TraceEventHandle handle = {0, 0, 0}; |
1180 if (!*category_group_enabled) | 1180 if (!*category_group_enabled) |
1181 return handle; | 1181 return handle; |
1182 | 1182 |
1183 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when | 1183 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when |
1184 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> | 1184 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> |
1185 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... | 1185 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... |
1186 if (thread_is_in_trace_event_.Get()) | 1186 if (thread_is_in_trace_event_.Get()) |
1187 return handle; | 1187 return handle; |
1188 | 1188 |
1189 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_); | 1189 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_); |
1190 | 1190 |
1191 DCHECK(name); | 1191 DCHECK(name); |
1192 DCHECK(!timestamp.is_null()); | 1192 DCHECK(!timestamp.is_null()); |
1193 | 1193 |
1194 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) { | 1194 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) { |
1195 if ((flags & TRACE_EVENT_FLAG_FLOW_IN) || | 1195 if ((flags & TRACE_EVENT_FLAG_FLOW_IN) || |
1196 (flags & TRACE_EVENT_FLAG_FLOW_OUT)) | 1196 (flags & TRACE_EVENT_FLAG_FLOW_OUT)) |
1197 bind_id = MangleEventId(bind_id); | 1197 bind_id = MangleEventId(bind_id); |
1198 id = MangleEventId(id); | 1198 id = MangleEventId(id); |
1199 } | 1199 } |
1200 | 1200 |
1201 TraceTicks offset_event_timestamp = OffsetTimestamp(timestamp); | 1201 TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp); |
1202 ThreadTicks thread_now = ThreadNow(); | 1202 ThreadTicks thread_now = ThreadNow(); |
1203 | 1203 |
1204 // |thread_local_event_buffer_| can be null if the current thread doesn't have | 1204 // |thread_local_event_buffer_| can be null if the current thread doesn't have |
1205 // a message loop or the message loop is blocked. | 1205 // a message loop or the message loop is blocked. |
1206 InitializeThreadLocalEventBufferIfSupported(); | 1206 InitializeThreadLocalEventBufferIfSupported(); |
1207 auto thread_local_event_buffer = thread_local_event_buffer_.Get(); | 1207 auto thread_local_event_buffer = thread_local_event_buffer_.Get(); |
1208 | 1208 |
1209 // Check and update the current thread name only if the event is for the | 1209 // Check and update the current thread name only if the event is for the |
1210 // current thread to avoid locks in most cases. | 1210 // current thread to avoid locks in most cases. |
1211 if (thread_id == static_cast<int>(PlatformThread::CurrentId())) { | 1211 if (thread_id == static_cast<int>(PlatformThread::CurrentId())) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 const char* name, | 1340 const char* name, |
1341 int num_args, | 1341 int num_args, |
1342 const char** arg_names, | 1342 const char** arg_names, |
1343 const unsigned char* arg_types, | 1343 const unsigned char* arg_types, |
1344 const unsigned long long* arg_values, | 1344 const unsigned long long* arg_values, |
1345 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 1345 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
1346 unsigned int flags) { | 1346 unsigned int flags) { |
1347 scoped_ptr<TraceEvent> trace_event(new TraceEvent); | 1347 scoped_ptr<TraceEvent> trace_event(new TraceEvent); |
1348 trace_event->Initialize( | 1348 trace_event->Initialize( |
1349 0, // thread_id | 1349 0, // thread_id |
1350 TraceTicks(), ThreadTicks(), TRACE_EVENT_PHASE_METADATA, | 1350 TimeTicks(), ThreadTicks(), TRACE_EVENT_PHASE_METADATA, |
1351 &g_category_group_enabled[g_category_metadata], name, | 1351 &g_category_group_enabled[g_category_metadata], name, |
1352 trace_event_internal::kNoId, // id | 1352 trace_event_internal::kNoId, // id |
1353 trace_event_internal::kNoId, // context_id | 1353 trace_event_internal::kNoId, // context_id |
1354 trace_event_internal::kNoId, // bind_id | 1354 trace_event_internal::kNoId, // bind_id |
1355 num_args, arg_names, arg_types, arg_values, convertable_values, flags); | 1355 num_args, arg_names, arg_types, arg_values, convertable_values, flags); |
1356 AutoLock lock(lock_); | 1356 AutoLock lock(lock_); |
1357 metadata_events_.push_back(trace_event.Pass()); | 1357 metadata_events_.push_back(trace_event.Pass()); |
1358 } | 1358 } |
1359 | 1359 |
1360 // May be called when a COMPELETE event ends and the unfinished event has been | 1360 // May be called when a COMPELETE event ends and the unfinished event has been |
1361 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). | 1361 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). |
1362 std::string TraceLog::EventToConsoleMessage(unsigned char phase, | 1362 std::string TraceLog::EventToConsoleMessage(unsigned char phase, |
1363 const TraceTicks& timestamp, | 1363 const TimeTicks& timestamp, |
1364 TraceEvent* trace_event) { | 1364 TraceEvent* trace_event) { |
1365 AutoLock thread_info_lock(thread_info_lock_); | 1365 AutoLock thread_info_lock(thread_info_lock_); |
1366 | 1366 |
1367 // The caller should translate TRACE_EVENT_PHASE_COMPLETE to | 1367 // The caller should translate TRACE_EVENT_PHASE_COMPLETE to |
1368 // TRACE_EVENT_PHASE_BEGIN or TRACE_EVENT_END. | 1368 // TRACE_EVENT_PHASE_BEGIN or TRACE_EVENT_END. |
1369 DCHECK(phase != TRACE_EVENT_PHASE_COMPLETE); | 1369 DCHECK(phase != TRACE_EVENT_PHASE_COMPLETE); |
1370 | 1370 |
1371 TimeDelta duration; | 1371 TimeDelta duration; |
1372 int thread_id = | 1372 int thread_id = |
1373 trace_event ? trace_event->thread_id() : PlatformThread::CurrentId(); | 1373 trace_event ? trace_event->thread_id() : PlatformThread::CurrentId(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1411 TraceEventHandle handle) { | 1411 TraceEventHandle handle) { |
1412 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when | 1412 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when |
1413 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> | 1413 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> |
1414 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... | 1414 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... |
1415 if (thread_is_in_trace_event_.Get()) | 1415 if (thread_is_in_trace_event_.Get()) |
1416 return; | 1416 return; |
1417 | 1417 |
1418 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_); | 1418 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_); |
1419 | 1419 |
1420 ThreadTicks thread_now = ThreadNow(); | 1420 ThreadTicks thread_now = ThreadNow(); |
1421 TraceTicks now = OffsetNow(); | 1421 TimeTicks now = OffsetNow(); |
1422 | 1422 |
1423 std::string console_message; | 1423 std::string console_message; |
1424 if (*category_group_enabled & ENABLED_FOR_RECORDING) { | 1424 if (*category_group_enabled & ENABLED_FOR_RECORDING) { |
1425 OptionalAutoLock lock(&lock_); | 1425 OptionalAutoLock lock(&lock_); |
1426 | 1426 |
1427 TraceEvent* trace_event = GetEventByHandleInternal(handle, &lock); | 1427 TraceEvent* trace_event = GetEventByHandleInternal(handle, &lock); |
1428 if (trace_event) { | 1428 if (trace_event) { |
1429 DCHECK(trace_event->phase() == TRACE_EVENT_PHASE_COMPLETE); | 1429 DCHECK(trace_event->phase() == TRACE_EVENT_PHASE_COMPLETE); |
1430 trace_event->UpdateDuration(now, thread_now); | 1430 trace_event->UpdateDuration(now, thread_now); |
1431 #if defined(OS_ANDROID) | 1431 #if defined(OS_ANDROID) |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 name_ = name; | 1707 name_ = name; |
1708 if (*category_group_enabled_) { | 1708 if (*category_group_enabled_) { |
1709 event_handle_ = | 1709 event_handle_ = |
1710 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( | 1710 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
1711 TRACE_EVENT_PHASE_COMPLETE, | 1711 TRACE_EVENT_PHASE_COMPLETE, |
1712 category_group_enabled_, | 1712 category_group_enabled_, |
1713 name, | 1713 name, |
1714 trace_event_internal::kNoId, // id | 1714 trace_event_internal::kNoId, // id |
1715 trace_event_internal::kNoId, // context_id | 1715 trace_event_internal::kNoId, // context_id |
1716 static_cast<int>(base::PlatformThread::CurrentId()), // thread_id | 1716 static_cast<int>(base::PlatformThread::CurrentId()), // thread_id |
1717 base::TraceTicks::Now(), | 1717 base::TimeTicks::Now(), |
1718 trace_event_internal::kZeroNumArgs, | 1718 trace_event_internal::kZeroNumArgs, |
1719 nullptr, | 1719 nullptr, |
1720 nullptr, | 1720 nullptr, |
1721 nullptr, | 1721 nullptr, |
1722 nullptr, | 1722 nullptr, |
1723 TRACE_EVENT_FLAG_NONE); | 1723 TRACE_EVENT_FLAG_NONE); |
1724 } | 1724 } |
1725 } | 1725 } |
1726 | 1726 |
1727 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 1727 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
1728 if (*category_group_enabled_) { | 1728 if (*category_group_enabled_) { |
1729 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, | 1729 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, |
1730 event_handle_); | 1730 event_handle_); |
1731 } | 1731 } |
1732 } | 1732 } |
1733 | 1733 |
1734 } // namespace trace_event_internal | 1734 } // namespace trace_event_internal |
OLD | NEW |