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 | 5 |
6 #ifndef BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 6 #ifndef BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
7 #define BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 7 #define BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
8 | 8 |
9 #include <stack> | 9 #include <stack> |
10 #include <string> | 10 #include <string> |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 void SetEventCallbackDisabled(); | 531 void SetEventCallbackDisabled(); |
532 | 532 |
533 // Flush all collected events to the given output callback. The callback will | 533 // Flush all collected events to the given output callback. The callback will |
534 // be called one or more times either synchronously or asynchronously from | 534 // be called one or more times either synchronously or asynchronously from |
535 // the current thread with IPC-bite-size chunks. The string format is | 535 // the current thread with IPC-bite-size chunks. The string format is |
536 // undefined. Use TraceResultBuffer to convert one or more trace strings to | 536 // undefined. Use TraceResultBuffer to convert one or more trace strings to |
537 // JSON. The callback can be null if the caller doesn't want any data. | 537 // JSON. The callback can be null if the caller doesn't want any data. |
538 // Due to the implementation of thread-local buffers, flush can't be | 538 // Due to the implementation of thread-local buffers, flush can't be |
539 // done when tracing is enabled. If called when tracing is enabled, the | 539 // done when tracing is enabled. If called when tracing is enabled, the |
540 // callback will be called directly with (empty_string, false) to indicate | 540 // callback will be called directly with (empty_string, false) to indicate |
541 // the end of this unsuccessful flush. Flush does the serialization | 541 // the end of this unsuccessful flush. |
542 // on the same thread if the caller doesn't set use_worker_thread explicitly. | |
543 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&, | 542 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&, |
544 bool has_more_events)> OutputCallback; | 543 bool has_more_events)> OutputCallback; |
545 void Flush(const OutputCallback& cb, bool use_worker_thread = false); | 544 void Flush(const OutputCallback& cb); |
546 void FlushButLeaveBufferIntact(const OutputCallback& flush_output_callback); | 545 void FlushButLeaveBufferIntact(const OutputCallback& flush_output_callback); |
547 | 546 |
548 // Called by TRACE_EVENT* macros, don't call this directly. | 547 // Called by TRACE_EVENT* macros, don't call this directly. |
549 // The name parameter is a category group for example: | 548 // The name parameter is a category group for example: |
550 // TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent") | 549 // TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent") |
551 static const unsigned char* GetCategoryGroupEnabled(const char* name); | 550 static const unsigned char* GetCategoryGroupEnabled(const char* name); |
552 static const char* GetCategoryGroupName( | 551 static const char* GetCategoryGroupName( |
553 const unsigned char* category_group_enabled); | 552 const unsigned char* category_group_enabled); |
554 | 553 |
555 // Called by TRACE_EVENT* macros, don't call this directly. | 554 // Called by TRACE_EVENT* macros, don't call this directly. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 bool check_buffer_is_full); | 703 bool check_buffer_is_full); |
705 void CheckIfBufferIsFullWhileLocked(); | 704 void CheckIfBufferIsFullWhileLocked(); |
706 void SetDisabledWhileLocked(); | 705 void SetDisabledWhileLocked(); |
707 | 706 |
708 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, | 707 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, |
709 OptionalAutoLock* lock); | 708 OptionalAutoLock* lock); |
710 | 709 |
711 // |generation| is used in the following callbacks to check if the callback | 710 // |generation| is used in the following callbacks to check if the callback |
712 // is called for the flush of the current |logged_events_|. | 711 // is called for the flush of the current |logged_events_|. |
713 void FlushCurrentThread(int generation); | 712 void FlushCurrentThread(int generation); |
714 // Usually it runs on a different thread. | 713 void ConvertTraceEventsToTraceFormat(scoped_ptr<TraceBuffer> logged_events, |
715 static void ConvertTraceEventsToTraceFormat( | |
716 scoped_ptr<TraceBuffer> logged_events, | |
717 const TraceLog::OutputCallback& flush_output_callback); | 714 const TraceLog::OutputCallback& flush_output_callback); |
718 void FinishFlush(int generation); | 715 void FinishFlush(int generation); |
719 void OnFlushTimeout(int generation); | 716 void OnFlushTimeout(int generation); |
720 | 717 |
721 int generation() const { | 718 int generation() const { |
722 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); | 719 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); |
723 } | 720 } |
724 bool CheckGeneration(int generation) const { | 721 bool CheckGeneration(int generation) const { |
725 return generation == this->generation(); | 722 return generation == this->generation(); |
726 } | 723 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 | 797 |
801 // For events which can't be added into the thread local buffer, e.g. events | 798 // For events which can't be added into the thread local buffer, e.g. events |
802 // from threads without a message loop. | 799 // from threads without a message loop. |
803 scoped_ptr<TraceBufferChunk> thread_shared_chunk_; | 800 scoped_ptr<TraceBufferChunk> thread_shared_chunk_; |
804 size_t thread_shared_chunk_index_; | 801 size_t thread_shared_chunk_index_; |
805 | 802 |
806 // Set when asynchronous Flush is in progress. | 803 // Set when asynchronous Flush is in progress. |
807 OutputCallback flush_output_callback_; | 804 OutputCallback flush_output_callback_; |
808 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; | 805 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; |
809 subtle::AtomicWord generation_; | 806 subtle::AtomicWord generation_; |
810 bool use_worker_thread_; | |
811 | 807 |
812 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 808 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
813 }; | 809 }; |
814 | 810 |
815 } // namespace debug | 811 } // namespace debug |
816 } // namespace base | 812 } // namespace base |
817 | 813 |
818 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 814 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
OLD | NEW |