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/debug/trace_event_impl.h" | 5 #include "base/debug/trace_event_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 int thread_id, | 1054 int thread_id, |
1055 const TimeTicks& timestamp, | 1055 const TimeTicks& timestamp, |
1056 int num_args, | 1056 int num_args, |
1057 const char** arg_names, | 1057 const char** arg_names, |
1058 const unsigned char* arg_types, | 1058 const unsigned char* arg_types, |
1059 const unsigned long long* arg_values, | 1059 const unsigned long long* arg_values, |
1060 scoped_ptr<ConvertableToTraceFormat> convertable_values[], | 1060 scoped_ptr<ConvertableToTraceFormat> convertable_values[], |
1061 unsigned char flags) { | 1061 unsigned char flags) { |
1062 DCHECK(name); | 1062 DCHECK(name); |
1063 | 1063 |
| 1064 TimeDelta duration; |
| 1065 if (phase == TRACE_EVENT_PHASE_END && trace_options_ & ECHO_TO_STDERR) { |
| 1066 duration = timestamp - thread_event_start_times_[thread_id].back(); |
| 1067 thread_event_start_times_[thread_id].pop_back(); |
| 1068 } |
| 1069 |
1064 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) | 1070 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) |
1065 id ^= process_id_hash_; | 1071 id ^= process_id_hash_; |
1066 | 1072 |
1067 #if defined(OS_ANDROID) | 1073 #if defined(OS_ANDROID) |
1068 SendToATrace(phase, GetCategoryGroupName(category_group_enabled), name, id, | 1074 SendToATrace(phase, GetCategoryGroupName(category_group_enabled), name, id, |
1069 num_args, arg_names, arg_types, arg_values, flags); | 1075 num_args, arg_names, arg_types, arg_values, flags); |
1070 #endif | 1076 #endif |
1071 | 1077 |
1072 TimeTicks now = timestamp - time_offset_; | 1078 TimeTicks now = timestamp - time_offset_; |
1073 EventCallback event_callback_copy; | 1079 EventCallback event_callback_copy; |
(...skipping 30 matching lines...) Expand all Loading... |
1104 bool found = std::find(existing_names.begin(), | 1110 bool found = std::find(existing_names.begin(), |
1105 existing_names.end(), | 1111 existing_names.end(), |
1106 new_name) != existing_names.end(); | 1112 new_name) != existing_names.end(); |
1107 if (!found) { | 1113 if (!found) { |
1108 existing_name->second.push_back(','); | 1114 existing_name->second.push_back(','); |
1109 existing_name->second.append(new_name); | 1115 existing_name->second.append(new_name); |
1110 } | 1116 } |
1111 } | 1117 } |
1112 } | 1118 } |
1113 | 1119 |
| 1120 if (trace_options_ & ECHO_TO_STDERR) { |
| 1121 std::string thread_name = thread_names_[thread_id]; |
| 1122 if (thread_colors_.find(thread_name) == thread_colors_.end()) |
| 1123 thread_colors_[thread_name] = (thread_colors_.size() % 6) + 1; |
| 1124 |
| 1125 fprintf(stderr, |
| 1126 "TraceLog (%lu) %s:", |
| 1127 timestamp.ToInternalValue(), |
| 1128 thread_name.c_str()); |
| 1129 |
| 1130 // Set the text color. With magic. |
| 1131 fprintf(stderr, "\e[0;3%dm", thread_colors_[thread_name]); |
| 1132 |
| 1133 size_t depth = 0; |
| 1134 if (thread_event_start_times_.find(thread_id) != |
| 1135 thread_event_start_times_.end()) |
| 1136 depth = thread_event_start_times_[thread_id].size(); |
| 1137 |
| 1138 for (size_t i = 0; i < depth; ++i) |
| 1139 fprintf(stderr, "| "); |
| 1140 |
| 1141 fprintf(stderr, "'%c', %s", phase, name); |
| 1142 |
| 1143 if (phase == TRACE_EVENT_PHASE_END) |
| 1144 fprintf(stderr, " (%.3f ms)", duration.InMillisecondsF()); |
| 1145 |
| 1146 // Resets the text color. |
| 1147 fprintf(stderr, "\n\e[0;m"); |
| 1148 } |
| 1149 |
1114 logged_events_->AddEvent(TraceEvent(thread_id, | 1150 logged_events_->AddEvent(TraceEvent(thread_id, |
1115 now, phase, category_group_enabled, name, id, | 1151 now, phase, category_group_enabled, name, id, |
1116 num_args, arg_names, arg_types, arg_values, | 1152 num_args, arg_names, arg_types, arg_values, |
1117 convertable_values, flags)); | 1153 convertable_values, flags)); |
1118 | 1154 |
1119 if (logged_events_->IsFull()) | 1155 if (logged_events_->IsFull()) |
1120 notifier.AddNotificationWhileLocked(TRACE_BUFFER_FULL); | 1156 notifier.AddNotificationWhileLocked(TRACE_BUFFER_FULL); |
1121 | 1157 |
1122 if (watch_category_ == category_group_enabled && watch_event_name_ == name) | 1158 if (watch_category_ == category_group_enabled && watch_event_name_ == name) |
1123 notifier.AddNotificationWhileLocked(EVENT_WATCH_NOTIFICATION); | 1159 notifier.AddNotificationWhileLocked(EVENT_WATCH_NOTIFICATION); |
1124 | 1160 |
1125 event_callback_copy = event_callback_; | 1161 event_callback_copy = event_callback_; |
1126 } // release lock | 1162 } // release lock |
1127 | 1163 |
| 1164 if (phase == TRACE_EVENT_PHASE_BEGIN && trace_options_ & ECHO_TO_STDERR) |
| 1165 thread_event_start_times_[thread_id].push_back(timestamp); |
| 1166 |
1128 notifier.SendNotificationIfAny(); | 1167 notifier.SendNotificationIfAny(); |
1129 if (event_callback_copy != NULL) { | 1168 if (event_callback_copy != NULL) { |
1130 event_callback_copy(phase, category_group_enabled, name, id, | 1169 event_callback_copy(phase, category_group_enabled, name, id, |
1131 num_args, arg_names, arg_types, arg_values, | 1170 num_args, arg_names, arg_types, arg_values, |
1132 flags); | 1171 flags); |
1133 } | 1172 } |
1134 } | 1173 } |
1135 | 1174 |
1136 void TraceLog::AddTraceEventEtw(char phase, | 1175 void TraceLog::AddTraceEventEtw(char phase, |
1137 const char* name, | 1176 const char* name, |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 NULL, // arg_names | 1458 NULL, // arg_names |
1420 NULL, // arg_types | 1459 NULL, // arg_types |
1421 NULL, // arg_values | 1460 NULL, // arg_values |
1422 NULL, // convertable values | 1461 NULL, // convertable values |
1423 TRACE_EVENT_FLAG_NONE); // flags | 1462 TRACE_EVENT_FLAG_NONE); // flags |
1424 } | 1463 } |
1425 } | 1464 } |
1426 | 1465 |
1427 } // namespace trace_event_internal | 1466 } // namespace trace_event_internal |
1428 | 1467 |
OLD | NEW |