OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "base/debug/trace_event.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include "base/debug/trace_event_win.h" | 8 #include "base/debug/trace_event_win.h" |
9 #endif | 9 #endif |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 namespace { | 97 namespace { |
98 | 98 |
99 const char* GetPhaseStr(TraceEventPhase phase) { | 99 const char* GetPhaseStr(TraceEventPhase phase) { |
100 switch(phase) { | 100 switch(phase) { |
101 case TRACE_EVENT_PHASE_BEGIN: | 101 case TRACE_EVENT_PHASE_BEGIN: |
102 return "B"; | 102 return "B"; |
103 case TRACE_EVENT_PHASE_INSTANT: | 103 case TRACE_EVENT_PHASE_INSTANT: |
104 return "I"; | 104 return "I"; |
105 case TRACE_EVENT_PHASE_END: | 105 case TRACE_EVENT_PHASE_END: |
106 return "E"; | 106 return "E"; |
107 case TRACE_EVENT_PHASE_METADATA: | |
108 return "M"; | |
107 default: | 109 default: |
108 NOTREACHED() << "Invalid phase argument"; | 110 NOTREACHED() << "Invalid phase argument"; |
109 return "?"; | 111 return "?"; |
110 } | 112 } |
111 } | 113 } |
112 | 114 |
113 size_t GetAllocLength(const char* str) { return str ? strlen(str) + 1 : 0; } | 115 size_t GetAllocLength(const char* str) { return str ? strlen(str) + 1 : 0; } |
114 | 116 |
115 // Copies |*member| into |*buffer|, sets |*member| to point to this new | 117 // Copies |*member| into |*buffer|, sets |*member| to point to this new |
116 // location, and then advances |*buffer| by the amount written. | 118 // location, and then advances |*buffer| by the amount written. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 if (enabled == enabled_) | 290 if (enabled == enabled_) |
289 return; | 291 return; |
290 logged_events_.reserve(1024); | 292 logged_events_.reserve(1024); |
291 enabled_ = enabled; | 293 enabled_ = enabled; |
292 for (int i = 0; i < g_category_index; i++) { | 294 for (int i = 0; i < g_category_index; i++) { |
293 //TODO(scheib): If changed to enable specific categories instead of all | 295 //TODO(scheib): If changed to enable specific categories instead of all |
294 // check GetCategoryInternal creation code that users TraceLog::enabled_ | 296 // check GetCategoryInternal creation code that users TraceLog::enabled_ |
295 g_categories[i].enabled = enabled; | 297 g_categories[i].enabled = enabled; |
296 } | 298 } |
297 } // release lock | 299 } // release lock |
298 if (!enabled) | 300 if (!enabled) { |
301 AddCurrentMetadataEvents(); | |
299 Flush(); | 302 Flush(); |
303 } | |
300 } | 304 } |
301 | 305 |
302 float TraceLog::GetBufferPercentFull() const { | 306 float TraceLog::GetBufferPercentFull() const { |
303 return (float)((double)logged_events_.size()/(double)kTraceEventBufferSize); | 307 return (float)((double)logged_events_.size()/(double)kTraceEventBufferSize); |
304 } | 308 } |
305 | 309 |
306 void TraceLog::SetOutputCallback(const TraceLog::OutputCallback& cb) { | 310 void TraceLog::SetOutputCallback(const TraceLog::OutputCallback& cb) { |
307 AutoLock lock(lock_); | 311 AutoLock lock(lock_); |
308 output_callback_ = cb; | 312 output_callback_ = cb; |
309 logged_events_.clear(); | 313 logged_events_.clear(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 TraceLog* tracelog = TraceLog::GetInstance(); | 416 TraceLog* tracelog = TraceLog::GetInstance(); |
413 if (!tracelog) | 417 if (!tracelog) |
414 return; | 418 return; |
415 tracelog->AddTraceEvent(phase, category, name, | 419 tracelog->AddTraceEvent(phase, category, name, |
416 "id", id, | 420 "id", id, |
417 "extra", extra ? extra : "", | 421 "extra", extra ? extra : "", |
418 -1, 0, false); | 422 -1, 0, false); |
419 } | 423 } |
420 } | 424 } |
421 | 425 |
426 void TraceLog::SetCurrentThreadName(const char* name) { | |
427 AutoLock lock(lock_); | |
428 thread_names_[PlatformThread::CurrentId()] = name; | |
429 } | |
430 | |
431 void TraceLog::AddCurrentMetadataEvents() { | |
432 const TraceCategory* metadata_category = GetCategoryInternal("__metadata"); | |
joth
2011/07/26 09:53:17
static const?
| |
433 #ifdef USE_UNRELIABLE_NOW | |
434 TimeTicks now = TimeTicks::HighResNow(); | |
jbates
2011/07/26 20:57:00
can we replace the timestamp with 0 for metadata e
| |
435 #else | |
436 TimeTicks now = TimeTicks::Now(); | |
437 #endif | |
438 for(base::hash_map<PlatformThreadId, std::string>::iterator it = | |
439 thread_names_.begin(); | |
440 it != thread_names_.end(); | |
441 it++) { | |
442 logged_events_.push_back( | |
443 TraceEvent(static_cast<unsigned long>(base::GetCurrentProcId()), | |
444 it->first, | |
445 now, base::debug::TRACE_EVENT_PHASE_METADATA, | |
446 metadata_category, "thread_name", | |
447 "name", it->second.c_str(), | |
448 NULL, 0, | |
449 true)); | |
joth
2011/07/26 09:53:17
you can pass false here. (The only thing that need
| |
450 } | |
451 } | |
452 | |
422 void TraceLog::Resurrect() { | 453 void TraceLog::Resurrect() { |
423 StaticMemorySingletonTraits<TraceLog>::Resurrect(); | 454 StaticMemorySingletonTraits<TraceLog>::Resurrect(); |
424 } | 455 } |
425 | 456 |
426 namespace internal { | 457 namespace internal { |
427 | 458 |
428 void TraceEndOnScopeClose::Initialize(const TraceCategory* category, | 459 void TraceEndOnScopeClose::Initialize(const TraceCategory* category, |
429 const char* name) { | 460 const char* name) { |
430 data_.category = category; | 461 data_.category = category; |
431 data_.name = name; | 462 data_.name = name; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 p_data_->name, | 495 p_data_->name, |
465 NULL, 0, NULL, 0, | 496 NULL, 0, NULL, 0, |
466 p_data_->threshold_begin_id, p_data_->threshold, false); | 497 p_data_->threshold_begin_id, p_data_->threshold, false); |
467 } | 498 } |
468 } | 499 } |
469 | 500 |
470 } // namespace internal | 501 } // namespace internal |
471 | 502 |
472 } // namespace debug | 503 } // namespace debug |
473 } // namespace base | 504 } // namespace base |
OLD | NEW |