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_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 6 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ |
7 #define BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 7 #define BASE_TRACE_EVENT_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. | 541 // the end of this unsuccessful flush. Flush does the serialization |
| 542 // on the same thread if the caller doesn't set use_worker_thread explicitly. |
542 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&, | 543 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&, |
543 bool has_more_events)> OutputCallback; | 544 bool has_more_events)> OutputCallback; |
544 void Flush(const OutputCallback& cb); | 545 void Flush(const OutputCallback& cb, bool use_worker_thread = false); |
545 void FlushButLeaveBufferIntact(const OutputCallback& flush_output_callback); | 546 void FlushButLeaveBufferIntact(const OutputCallback& flush_output_callback); |
546 | 547 |
547 // Called by TRACE_EVENT* macros, don't call this directly. | 548 // Called by TRACE_EVENT* macros, don't call this directly. |
548 // The name parameter is a category group for example: | 549 // The name parameter is a category group for example: |
549 // TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent") | 550 // TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent") |
550 static const unsigned char* GetCategoryGroupEnabled(const char* name); | 551 static const unsigned char* GetCategoryGroupEnabled(const char* name); |
551 static const char* GetCategoryGroupName( | 552 static const char* GetCategoryGroupName( |
552 const unsigned char* category_group_enabled); | 553 const unsigned char* category_group_enabled); |
553 | 554 |
554 // Called by TRACE_EVENT* macros, don't call this directly. | 555 // Called by TRACE_EVENT* macros, don't call this directly. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 bool check_buffer_is_full); | 704 bool check_buffer_is_full); |
704 void CheckIfBufferIsFullWhileLocked(); | 705 void CheckIfBufferIsFullWhileLocked(); |
705 void SetDisabledWhileLocked(); | 706 void SetDisabledWhileLocked(); |
706 | 707 |
707 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, | 708 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, |
708 OptionalAutoLock* lock); | 709 OptionalAutoLock* lock); |
709 | 710 |
710 // |generation| is used in the following callbacks to check if the callback | 711 // |generation| is used in the following callbacks to check if the callback |
711 // is called for the flush of the current |logged_events_|. | 712 // is called for the flush of the current |logged_events_|. |
712 void FlushCurrentThread(int generation); | 713 void FlushCurrentThread(int generation); |
713 void ConvertTraceEventsToTraceFormat(scoped_ptr<TraceBuffer> logged_events, | 714 // Usually it runs on a different thread. |
| 715 static void ConvertTraceEventsToTraceFormat( |
| 716 scoped_ptr<TraceBuffer> logged_events, |
714 const TraceLog::OutputCallback& flush_output_callback); | 717 const TraceLog::OutputCallback& flush_output_callback); |
715 void FinishFlush(int generation); | 718 void FinishFlush(int generation); |
716 void OnFlushTimeout(int generation); | 719 void OnFlushTimeout(int generation); |
717 | 720 |
718 int generation() const { | 721 int generation() const { |
719 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); | 722 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); |
720 } | 723 } |
721 bool CheckGeneration(int generation) const { | 724 bool CheckGeneration(int generation) const { |
722 return generation == this->generation(); | 725 return generation == this->generation(); |
723 } | 726 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 | 799 |
797 // For events which can't be added into the thread local buffer, e.g. events | 800 // For events which can't be added into the thread local buffer, e.g. events |
798 // from threads without a message loop. | 801 // from threads without a message loop. |
799 scoped_ptr<TraceBufferChunk> thread_shared_chunk_; | 802 scoped_ptr<TraceBufferChunk> thread_shared_chunk_; |
800 size_t thread_shared_chunk_index_; | 803 size_t thread_shared_chunk_index_; |
801 | 804 |
802 // Set when asynchronous Flush is in progress. | 805 // Set when asynchronous Flush is in progress. |
803 OutputCallback flush_output_callback_; | 806 OutputCallback flush_output_callback_; |
804 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; | 807 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; |
805 subtle::AtomicWord generation_; | 808 subtle::AtomicWord generation_; |
| 809 bool use_worker_thread_; |
806 | 810 |
807 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 811 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
808 }; | 812 }; |
809 | 813 |
810 } // namespace trace_event | 814 } // namespace trace_event |
811 } // namespace base | 815 } // namespace base |
812 | 816 |
813 // TODO(ssid): remove these aliases after the tracing clients are moved to the | 817 // TODO(ssid): remove these aliases after the tracing clients are moved to the |
814 // new trace_event namespace. See crbug.com/451032. ETA: March 2015. | 818 // new trace_event namespace. See crbug.com/451032. ETA: March 2015. |
815 namespace base { | 819 namespace base { |
816 namespace debug { | 820 namespace debug { |
817 using base::trace_event::CategoryFilter; | 821 using base::trace_event::CategoryFilter; |
818 using base::trace_event::ConvertableToTraceFormat; | 822 using base::trace_event::ConvertableToTraceFormat; |
819 using base::trace_event::RECORD_UNTIL_FULL; | 823 using base::trace_event::RECORD_UNTIL_FULL; |
820 using base::trace_event::RECORD_CONTINUOUSLY; | 824 using base::trace_event::RECORD_CONTINUOUSLY; |
821 using base::trace_event::RECORD_AS_MUCH_AS_POSSIBLE; | 825 using base::trace_event::RECORD_AS_MUCH_AS_POSSIBLE; |
822 using base::trace_event::TraceEventHandle; | 826 using base::trace_event::TraceEventHandle; |
823 using base::trace_event::TraceLog; | 827 using base::trace_event::TraceLog; |
824 using base::trace_event::TraceLogStatus; | 828 using base::trace_event::TraceLogStatus; |
825 using base::trace_event::TraceOptions; | 829 using base::trace_event::TraceOptions; |
826 using base::trace_event::TraceResultBuffer; | 830 using base::trace_event::TraceResultBuffer; |
827 } // namespace debug | 831 } // namespace debug |
828 } // namespace base | 832 } // namespace base |
829 | 833 |
830 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 834 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ |
OLD | NEW |