Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: base/debug/trace_event_impl.cc

Issue 14474006: Add a command line flag for dumping trace events to VLOG (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/debug/trace_event_impl.h ('k') | cc/base/switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 return logged_events_.size(); 221 return logged_events_.size();
222 } 222 }
223 223
224 private: 224 private:
225 size_t current_iteration_index_; 225 size_t current_iteration_index_;
226 std::vector<TraceEvent> logged_events_; 226 std::vector<TraceEvent> logged_events_;
227 227
228 DISALLOW_COPY_AND_ASSIGN(TraceBufferVector); 228 DISALLOW_COPY_AND_ASSIGN(TraceBufferVector);
229 }; 229 };
230 230
231 class TraceBufferDiscardsEvents : public TraceBuffer {
232 public:
233 virtual ~TraceBufferDiscardsEvents() { }
234
235 virtual void AddEvent(const TraceEvent& event) { }
236 virtual bool HasMoreEvents() const { return false; }
237
238 virtual const TraceEvent& NextEvent() {
239 NOTREACHED();
240 return *static_cast<TraceEvent*>(NULL);
241 }
242
243 virtual bool IsFull() const { return false; }
244
245 virtual size_t CountEnabledByName(const unsigned char* category,
246 const std::string& event_name) const {
247 return 0;
248 }
249
250 virtual size_t Size() const { return 0; }
251
252 virtual const TraceEvent& GetEventAt(size_t index) const {
253 NOTREACHED();
254 return *static_cast<TraceEvent*>(NULL);
255 }
256 };
257
231 //////////////////////////////////////////////////////////////////////////////// 258 ////////////////////////////////////////////////////////////////////////////////
232 // 259 //
233 // TraceEvent 260 // TraceEvent
234 // 261 //
235 //////////////////////////////////////////////////////////////////////////////// 262 ////////////////////////////////////////////////////////////////////////////////
236 263
237 namespace { 264 namespace {
238 265
239 size_t GetAllocLength(const char* str) { return str ? strlen(str) + 1 : 0; } 266 size_t GetAllocLength(const char* str) { return str ? strlen(str) + 1 : 0; }
240 267
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 942
916 void TraceLog::SetNotificationCallback( 943 void TraceLog::SetNotificationCallback(
917 const TraceLog::NotificationCallback& cb) { 944 const TraceLog::NotificationCallback& cb) {
918 AutoLock lock(lock_); 945 AutoLock lock(lock_);
919 notification_callback_ = cb; 946 notification_callback_ = cb;
920 } 947 }
921 948
922 TraceBuffer* TraceLog::GetTraceBuffer() { 949 TraceBuffer* TraceLog::GetTraceBuffer() {
923 if (trace_options_ & RECORD_CONTINUOUSLY) 950 if (trace_options_ & RECORD_CONTINUOUSLY)
924 return new TraceBufferRingBuffer(); 951 return new TraceBufferRingBuffer();
952 else if (trace_options_ & ECHO_TO_VLOG)
953 return new TraceBufferDiscardsEvents();
925 return new TraceBufferVector(); 954 return new TraceBufferVector();
926 } 955 }
927 956
928 void TraceLog::SetEventCallback(EventCallback cb) { 957 void TraceLog::SetEventCallback(EventCallback cb) {
929 AutoLock lock(lock_); 958 AutoLock lock(lock_);
930 event_callback_ = cb; 959 event_callback_ = cb;
931 }; 960 };
932 961
933 void TraceLog::Flush(const TraceLog::OutputCallback& cb) { 962 void TraceLog::Flush(const TraceLog::OutputCallback& cb) {
934 scoped_ptr<TraceBuffer> previous_logged_events; 963 scoped_ptr<TraceBuffer> previous_logged_events;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 unsigned long long id, 1009 unsigned long long id,
981 int thread_id, 1010 int thread_id,
982 const TimeTicks& timestamp, 1011 const TimeTicks& timestamp,
983 int num_args, 1012 int num_args,
984 const char** arg_names, 1013 const char** arg_names,
985 const unsigned char* arg_types, 1014 const unsigned char* arg_types,
986 const unsigned long long* arg_values, 1015 const unsigned long long* arg_values,
987 unsigned char flags) { 1016 unsigned char flags) {
988 DCHECK(name); 1017 DCHECK(name);
989 1018
1019 TimeDelta duration;
1020 if (phase == TRACE_EVENT_PHASE_END && trace_options_ & ECHO_TO_VLOG) {
1021 duration = timestamp - thread_event_start_times_[thread_id].top();
1022 thread_event_start_times_[thread_id].pop();
1023 }
1024
990 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) 1025 if (flags & TRACE_EVENT_FLAG_MANGLE_ID)
991 id ^= process_id_hash_; 1026 id ^= process_id_hash_;
992 1027
993 #if defined(OS_ANDROID) 1028 #if defined(OS_ANDROID)
994 SendToATrace(phase, GetCategoryGroupName(category_group_enabled), name, id, 1029 SendToATrace(phase, GetCategoryGroupName(category_group_enabled), name, id,
995 num_args, arg_names, arg_types, arg_values, flags); 1030 num_args, arg_names, arg_types, arg_values, flags);
996 #endif 1031 #endif
997 1032
998 TimeTicks now = timestamp - time_offset_; 1033 TimeTicks now = timestamp - time_offset_;
999 EventCallback event_callback_copy; 1034 EventCallback event_callback_copy;
(...skipping 30 matching lines...) Expand all
1030 bool found = std::find(existing_names.begin(), 1065 bool found = std::find(existing_names.begin(),
1031 existing_names.end(), 1066 existing_names.end(),
1032 new_name) != existing_names.end(); 1067 new_name) != existing_names.end();
1033 if (!found) { 1068 if (!found) {
1034 existing_name->second.push_back(','); 1069 existing_name->second.push_back(',');
1035 existing_name->second.append(new_name); 1070 existing_name->second.append(new_name);
1036 } 1071 }
1037 } 1072 }
1038 } 1073 }
1039 1074
1075 if (trace_options_ & ECHO_TO_VLOG) {
1076 std::string thread_name = thread_names_[thread_id];
1077 if (thread_colors_.find(thread_name) == thread_colors_.end())
1078 thread_colors_[thread_name] = (thread_colors_.size() % 6) + 1;
1079
1080 std::ostringstream log;
1081 log << base::StringPrintf("%s: \e[0;3%dm",
1082 thread_name.c_str(),
1083 thread_colors_[thread_name]);
1084
1085 size_t depth = 0;
1086 if (thread_event_start_times_.find(thread_id) !=
1087 thread_event_start_times_.end())
1088 depth = thread_event_start_times_[thread_id].size();
1089
1090 for (size_t i = 0; i < depth; ++i)
1091 log << "| ";
1092
1093 log << base::StringPrintf("'%c', %s", phase, name);
1094
1095 if (phase == TRACE_EVENT_PHASE_END)
1096 log << base::StringPrintf(" (%.3f ms)", duration.InMillisecondsF());
1097
1098 VLOG(0) << log.str() << "\e[0;m";
1099 }
1100
1040 logged_events_->AddEvent(TraceEvent(thread_id, 1101 logged_events_->AddEvent(TraceEvent(thread_id,
1041 now, phase, category_group_enabled, name, id, 1102 now, phase, category_group_enabled, name, id,
1042 num_args, arg_names, arg_types, arg_values, 1103 num_args, arg_names, arg_types, arg_values,
1043 flags)); 1104 flags));
1044 1105
1045 if (logged_events_->IsFull()) 1106 if (logged_events_->IsFull())
1046 notifier.AddNotificationWhileLocked(TRACE_BUFFER_FULL); 1107 notifier.AddNotificationWhileLocked(TRACE_BUFFER_FULL);
1047 1108
1048 if (watch_category_ == category_group_enabled && watch_event_name_ == name) 1109 if (watch_category_ == category_group_enabled && watch_event_name_ == name)
1049 notifier.AddNotificationWhileLocked(EVENT_WATCH_NOTIFICATION); 1110 notifier.AddNotificationWhileLocked(EVENT_WATCH_NOTIFICATION);
1050 1111
1051 event_callback_copy = event_callback_; 1112 event_callback_copy = event_callback_;
1052 } // release lock 1113 } // release lock
1053 1114
1115 if (phase == TRACE_EVENT_PHASE_BEGIN && trace_options_ & ECHO_TO_VLOG)
1116 thread_event_start_times_[thread_id].push(timestamp);
1117
1054 notifier.SendNotificationIfAny(); 1118 notifier.SendNotificationIfAny();
1055 if (event_callback_copy != NULL) { 1119 if (event_callback_copy != NULL) {
1056 event_callback_copy(phase, category_group_enabled, name, id, 1120 event_callback_copy(phase, category_group_enabled, name, id,
1057 num_args, arg_names, arg_types, arg_values, 1121 num_args, arg_names, arg_types, arg_values,
1058 flags); 1122 flags);
1059 } 1123 }
1060 } 1124 }
1061 1125
1062 void TraceLog::AddTraceEventEtw(char phase, 1126 void TraceLog::AddTraceEventEtw(char phase,
1063 const char* name, 1127 const char* name,
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 0, // num_args 1407 0, // num_args
1344 NULL, // arg_names 1408 NULL, // arg_names
1345 NULL, // arg_types 1409 NULL, // arg_types
1346 NULL, // arg_values 1410 NULL, // arg_values
1347 TRACE_EVENT_FLAG_NONE); // flags 1411 TRACE_EVENT_FLAG_NONE); // flags
1348 } 1412 }
1349 } 1413 }
1350 1414
1351 } // namespace trace_event_internal 1415 } // namespace trace_event_internal
1352 1416
OLDNEW
« no previous file with comments | « base/debug/trace_event_impl.h ('k') | cc/base/switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698