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

Side by Side Diff: base/trace_event/trace_event_impl.h

Issue 1124763003: Update from https://crrev.com/327068 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: update nacl, buildtools, fix display_change_notifier_unittest Created 5 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
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 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/atomicops.h" 13 #include "base/atomicops.h"
14 #include "base/base_export.h" 14 #include "base/base_export.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
17 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
18 #include "base/memory/ref_counted_memory.h" 18 #include "base/memory/ref_counted_memory.h"
19 #include "base/memory/scoped_vector.h" 19 #include "base/memory/scoped_vector.h"
20 #include "base/observer_list.h" 20 #include "base/observer_list.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/synchronization/condition_variable.h" 22 #include "base/synchronization/condition_variable.h"
23 #include "base/synchronization/lock.h" 23 #include "base/synchronization/lock.h"
24 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
25 #include "base/threading/thread_local.h" 25 #include "base/threading/thread_local.h"
26 26
27 // Older style trace macros with explicit id and extra data 27 // Older style trace macros with explicit id and extra data
28 // Only these macros result in publishing data to ETW as currently implemented. 28 // Only these macros result in publishing data to ETW as currently implemented.
29 // TODO(georgesak): Update/replace these with new ETW macros.
29 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ 30 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \
30 base::trace_event::TraceLog::AddTraceEventEtw( \ 31 base::trace_event::TraceLog::AddTraceEventEtw( \
31 TRACE_EVENT_PHASE_BEGIN, \ 32 TRACE_EVENT_PHASE_BEGIN, \
32 name, reinterpret_cast<const void*>(id), extra) 33 name, reinterpret_cast<const void*>(id), extra)
33 34
34 #define TRACE_EVENT_END_ETW(name, id, extra) \ 35 #define TRACE_EVENT_END_ETW(name, id, extra) \
35 base::trace_event::TraceLog::AddTraceEventEtw( \ 36 base::trace_event::TraceLog::AddTraceEventEtw( \
36 TRACE_EVENT_PHASE_END, \ 37 TRACE_EVENT_PHASE_END, \
37 name, reinterpret_cast<const void*>(id), extra) 38 name, reinterpret_cast<const void*>(id), extra)
38 39
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 // value with zero or more of the following bits. Used in this class only. 440 // value with zero or more of the following bits. Used in this class only.
440 // The TRACE_EVENT macros should only use the value as a bool. 441 // The TRACE_EVENT macros should only use the value as a bool.
441 // These values must be in sync with macro values in TraceEvent.h in Blink. 442 // These values must be in sync with macro values in TraceEvent.h in Blink.
442 enum CategoryGroupEnabledFlags { 443 enum CategoryGroupEnabledFlags {
443 // Category group enabled for the recording mode. 444 // Category group enabled for the recording mode.
444 ENABLED_FOR_RECORDING = 1 << 0, 445 ENABLED_FOR_RECORDING = 1 << 0,
445 // Category group enabled for the monitoring mode. 446 // Category group enabled for the monitoring mode.
446 ENABLED_FOR_MONITORING = 1 << 1, 447 ENABLED_FOR_MONITORING = 1 << 1,
447 // Category group enabled by SetEventCallbackEnabled(). 448 // Category group enabled by SetEventCallbackEnabled().
448 ENABLED_FOR_EVENT_CALLBACK = 1 << 2, 449 ENABLED_FOR_EVENT_CALLBACK = 1 << 2,
450 // Category group enabled to export events to ETW.
451 ENABLED_FOR_ETW_EXPORT = 1 << 3
449 }; 452 };
450 453
451 static TraceLog* GetInstance(); 454 static TraceLog* GetInstance();
452 455
453 // Get set of known category groups. This can change as new code paths are 456 // Get set of known category groups. This can change as new code paths are
454 // reached. The known category groups are inserted into |category_groups|. 457 // reached. The known category groups are inserted into |category_groups|.
455 void GetKnownCategoryGroups(std::vector<std::string>* category_groups); 458 void GetKnownCategoryGroups(std::vector<std::string>* category_groups);
456 459
457 // Retrieves a copy (for thread-safety) of the current CategoryFilter. 460 // Retrieves a copy (for thread-safety) of the current CategoryFilter.
458 CategoryFilter GetCurrentCategoryFilter(); 461 CategoryFilter GetCurrentCategoryFilter();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 void SetEventCallbackDisabled(); 534 void SetEventCallbackDisabled();
532 535
533 // Flush all collected events to the given output callback. The callback will 536 // Flush all collected events to the given output callback. The callback will
534 // be called one or more times either synchronously or asynchronously from 537 // be called one or more times either synchronously or asynchronously from
535 // the current thread with IPC-bite-size chunks. The string format is 538 // the current thread with IPC-bite-size chunks. The string format is
536 // undefined. Use TraceResultBuffer to convert one or more trace strings to 539 // 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. 540 // 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 541 // 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 542 // done when tracing is enabled. If called when tracing is enabled, the
540 // callback will be called directly with (empty_string, false) to indicate 543 // callback will be called directly with (empty_string, false) to indicate
541 // the end of this unsuccessful flush. 544 // the end of this unsuccessful flush. Flush does the serialization
545 // on the same thread if the caller doesn't set use_worker_thread explicitly.
542 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&, 546 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&,
543 bool has_more_events)> OutputCallback; 547 bool has_more_events)> OutputCallback;
544 void Flush(const OutputCallback& cb); 548 void Flush(const OutputCallback& cb, bool use_worker_thread = false);
545 void FlushButLeaveBufferIntact(const OutputCallback& flush_output_callback); 549 void FlushButLeaveBufferIntact(const OutputCallback& flush_output_callback);
546 550
547 // Called by TRACE_EVENT* macros, don't call this directly. 551 // Called by TRACE_EVENT* macros, don't call this directly.
548 // The name parameter is a category group for example: 552 // The name parameter is a category group for example:
549 // TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent") 553 // TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent")
550 static const unsigned char* GetCategoryGroupEnabled(const char* name); 554 static const unsigned char* GetCategoryGroupEnabled(const char* name);
551 static const char* GetCategoryGroupName( 555 static const char* GetCategoryGroupName(
552 const unsigned char* category_group_enabled); 556 const unsigned char* category_group_enabled);
553 557
554 // Called by TRACE_EVENT* macros, don't call this directly. 558 // Called by TRACE_EVENT* macros, don't call this directly.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 typedef base::Callback<void()> WatchEventCallback; 599 typedef base::Callback<void()> WatchEventCallback;
596 void SetWatchEvent(const std::string& category_name, 600 void SetWatchEvent(const std::string& category_name,
597 const std::string& event_name, 601 const std::string& event_name,
598 const WatchEventCallback& callback); 602 const WatchEventCallback& callback);
599 // Cancel the watch event. If tracing is enabled, this may race with the 603 // Cancel the watch event. If tracing is enabled, this may race with the
600 // watch event notification firing. 604 // watch event notification firing.
601 void CancelWatchEvent(); 605 void CancelWatchEvent();
602 606
603 int process_id() const { return process_id_; } 607 int process_id() const { return process_id_; }
604 608
609 uint64 MangleEventId(uint64 id);
610
605 // Exposed for unittesting: 611 // Exposed for unittesting:
606 612
607 void WaitSamplingEventForTesting(); 613 void WaitSamplingEventForTesting();
608 614
609 // Allows deleting our singleton instance. 615 // Allows deleting our singleton instance.
610 static void DeleteForTesting(); 616 static void DeleteForTesting();
611 617
612 // Allow tests to inspect TraceEvents. 618 // Allow tests to inspect TraceEvents.
613 TraceEvent* GetEventByHandle(TraceEventHandle handle); 619 TraceEvent* GetEventByHandle(TraceEventHandle handle);
614 620
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 bool check_buffer_is_full); 709 bool check_buffer_is_full);
704 void CheckIfBufferIsFullWhileLocked(); 710 void CheckIfBufferIsFullWhileLocked();
705 void SetDisabledWhileLocked(); 711 void SetDisabledWhileLocked();
706 712
707 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, 713 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle,
708 OptionalAutoLock* lock); 714 OptionalAutoLock* lock);
709 715
710 // |generation| is used in the following callbacks to check if the callback 716 // |generation| is used in the following callbacks to check if the callback
711 // is called for the flush of the current |logged_events_|. 717 // is called for the flush of the current |logged_events_|.
712 void FlushCurrentThread(int generation); 718 void FlushCurrentThread(int generation);
713 void ConvertTraceEventsToTraceFormat(scoped_ptr<TraceBuffer> logged_events, 719 // Usually it runs on a different thread.
720 static void ConvertTraceEventsToTraceFormat(
721 scoped_ptr<TraceBuffer> logged_events,
714 const TraceLog::OutputCallback& flush_output_callback); 722 const TraceLog::OutputCallback& flush_output_callback);
715 void FinishFlush(int generation); 723 void FinishFlush(int generation);
716 void OnFlushTimeout(int generation); 724 void OnFlushTimeout(int generation);
717 725
718 int generation() const { 726 int generation() const {
719 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); 727 return static_cast<int>(subtle::NoBarrier_Load(&generation_));
720 } 728 }
721 bool CheckGeneration(int generation) const { 729 bool CheckGeneration(int generation) const {
722 return generation == this->generation(); 730 return generation == this->generation();
723 } 731 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 804
797 // For events which can't be added into the thread local buffer, e.g. events 805 // For events which can't be added into the thread local buffer, e.g. events
798 // from threads without a message loop. 806 // from threads without a message loop.
799 scoped_ptr<TraceBufferChunk> thread_shared_chunk_; 807 scoped_ptr<TraceBufferChunk> thread_shared_chunk_;
800 size_t thread_shared_chunk_index_; 808 size_t thread_shared_chunk_index_;
801 809
802 // Set when asynchronous Flush is in progress. 810 // Set when asynchronous Flush is in progress.
803 OutputCallback flush_output_callback_; 811 OutputCallback flush_output_callback_;
804 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; 812 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_;
805 subtle::AtomicWord generation_; 813 subtle::AtomicWord generation_;
814 bool use_worker_thread_;
806 815
807 DISALLOW_COPY_AND_ASSIGN(TraceLog); 816 DISALLOW_COPY_AND_ASSIGN(TraceLog);
808 }; 817 };
809 818
810 } // namespace trace_event 819 } // namespace trace_event
811 } // namespace base 820 } // namespace base
812 821
813 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ 822 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698