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 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include "base/debug/trace_event_win.h" | 10 #include "base/debug/trace_event_win.h" |
11 #endif | 11 #endif |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "base/threading/thread_local.h" | 16 #include "base/threading/thread_local.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/time.h" | 19 #include "base/time.h" |
20 | 20 |
21 #define USE_UNRELIABLE_NOW | 21 #define USE_UNRELIABLE_NOW |
22 | 22 |
| 23 class DeleteTraceLogForTesting { |
| 24 public: |
| 25 static void Delete() { |
| 26 Singleton<base::debug::TraceLog, |
| 27 StaticMemorySingletonTraits<base::debug::TraceLog> >::OnExit(0); |
| 28 } |
| 29 }; |
| 30 |
23 namespace base { | 31 namespace base { |
24 namespace debug { | 32 namespace debug { |
25 | 33 |
26 // Controls the number of trace events we will buffer in-memory | 34 // Controls the number of trace events we will buffer in-memory |
27 // before throwing them away. | 35 // before throwing them away. |
28 const size_t kTraceEventBufferSize = 500000; | 36 const size_t kTraceEventBufferSize = 500000; |
29 const size_t kTraceEventBatchSize = 1000; | 37 const size_t kTraceEventBatchSize = 1000; |
30 | 38 |
31 #define TRACE_EVENT_MAX_CATEGORIES 100 | 39 #define TRACE_EVENT_MAX_CATEGORIES 100 |
32 | 40 |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 output_callback_copy = output_callback_; | 411 output_callback_copy = output_callback_; |
404 } // release lock | 412 } // release lock |
405 | 413 |
406 if (output_callback_copy.is_null()) | 414 if (output_callback_copy.is_null()) |
407 return; | 415 return; |
408 | 416 |
409 for (size_t i = 0; | 417 for (size_t i = 0; |
410 i < previous_logged_events.size(); | 418 i < previous_logged_events.size(); |
411 i += kTraceEventBatchSize) { | 419 i += kTraceEventBatchSize) { |
412 scoped_refptr<RefCountedString> json_events_str_ptr = | 420 scoped_refptr<RefCountedString> json_events_str_ptr = |
413 new RefCountedString(); | 421 new RefCountedString(); |
414 TraceEvent::AppendEventsAsJSON(previous_logged_events, | 422 TraceEvent::AppendEventsAsJSON(previous_logged_events, |
415 i, | 423 i, |
416 kTraceEventBatchSize, | 424 kTraceEventBatchSize, |
417 &(json_events_str_ptr->data)); | 425 &(json_events_str_ptr->data)); |
418 output_callback_copy.Run(json_events_str_ptr); | 426 output_callback_copy.Run(json_events_str_ptr); |
419 } | 427 } |
420 } | 428 } |
421 | 429 |
422 int TraceLog::AddTraceEvent(TraceEventPhase phase, | 430 int TraceLog::AddTraceEvent(TraceEventPhase phase, |
423 const TraceCategory* category, | 431 const TraceCategory* category, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 TraceEvent(static_cast<unsigned long>(base::GetCurrentProcId()), | 548 TraceEvent(static_cast<unsigned long>(base::GetCurrentProcId()), |
541 it->first, | 549 it->first, |
542 TimeTicks(), base::debug::TRACE_EVENT_PHASE_METADATA, | 550 TimeTicks(), base::debug::TRACE_EVENT_PHASE_METADATA, |
543 g_category_metadata, "thread_name", | 551 g_category_metadata, "thread_name", |
544 "name", it->second, | 552 "name", it->second, |
545 NULL, 0, | 553 NULL, 0, |
546 false)); | 554 false)); |
547 } | 555 } |
548 } | 556 } |
549 | 557 |
| 558 void TraceLog::DeleteForTesting() { |
| 559 DeleteTraceLogForTesting::Delete(); |
| 560 } |
| 561 |
550 void TraceLog::Resurrect() { | 562 void TraceLog::Resurrect() { |
551 StaticMemorySingletonTraits<TraceLog>::Resurrect(); | 563 StaticMemorySingletonTraits<TraceLog>::Resurrect(); |
552 } | 564 } |
553 | 565 |
554 namespace internal { | 566 namespace internal { |
555 | 567 |
556 void TraceEndOnScopeClose::Initialize(const TraceCategory* category, | 568 void TraceEndOnScopeClose::Initialize(const TraceCategory* category, |
557 const char* name) { | 569 const char* name) { |
558 data_.category = category; | 570 data_.category = category; |
559 data_.name = name; | 571 data_.name = name; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 NULL, 0, NULL, 0, | 605 NULL, 0, NULL, 0, |
594 p_data_->threshold_begin_id, p_data_->threshold, | 606 p_data_->threshold_begin_id, p_data_->threshold, |
595 TraceLog::EVENT_FLAG_NONE); | 607 TraceLog::EVENT_FLAG_NONE); |
596 } | 608 } |
597 } | 609 } |
598 | 610 |
599 } // namespace internal | 611 } // namespace internal |
600 | 612 |
601 } // namespace debug | 613 } // namespace debug |
602 } // namespace base | 614 } // namespace base |
OLD | NEW |