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

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

Issue 11345019: Make Chrome Trace work with Android ATrace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove redundant checking Created 8 years, 1 month 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 | Annotate | Revision Log
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 // This header is designed to give you trace_event macros without specifying 5 // This header is designed to give you trace_event macros without specifying
6 // how the events actually get collected and stored. If you need to expose trace 6 // how the events actually get collected and stored. If you need to expose trace
7 // event to some other universe, you can copy-and-paste this file, 7 // event to some other universe, you can copy-and-paste this file,
8 // implement the TRACE_EVENT_API macros, and do any other necessary fixup for 8 // implement the TRACE_EVENT_API macros, and do any other necessary fixup for
9 // the target platform. The end result is that multiple libraries can funnel 9 // the target platform. The end result is that multiple libraries can funnel
10 // events through to a shared trace event collector. 10 // events through to a shared trace event collector.
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 // int num_args, 590 // int num_args,
591 // const char** arg_names, 591 // const char** arg_names,
592 // const unsigned char* arg_types, 592 // const unsigned char* arg_types,
593 // const unsigned long long* arg_values, 593 // const unsigned long long* arg_values,
594 // int threshold_begin_id, 594 // int threshold_begin_id,
595 // long long threshold, 595 // long long threshold,
596 // unsigned char flags) 596 // unsigned char flags)
597 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ 597 #define TRACE_EVENT_API_ADD_TRACE_EVENT \
598 base::debug::TraceLog::GetInstance()->AddTraceEvent 598 base::debug::TraceLog::GetInstance()->AddTraceEvent
599 599
600 // Checks if Android ATrace is enabled.
601 #if defined(OS_ANDROID)
602 #define TRACE_EVENT_API_IS_ATRACE_ENABLED() \
603 base::debug::TraceLog::IsATraceEnabled()
604 #else
605 #define TRACE_EVENT_API_IS_ATRACE_ENABLED() false
606 #endif
607
600 //////////////////////////////////////////////////////////////////////////////// 608 ////////////////////////////////////////////////////////////////////////////////
601 609
602 // Implementation detail: trace event macros create temporary variables 610 // Implementation detail: trace event macros create temporary variables
603 // to keep instrumentation overhead low. These macros give each temporary 611 // to keep instrumentation overhead low. These macros give each temporary
604 // variable a unique name based on the line number to prevent name collissions. 612 // variable a unique name based on the line number to prevent name collissions.
605 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ 613 #define INTERNAL_TRACE_EVENT_UID3(a,b) \
606 trace_event_unique_##a##b 614 trace_event_unique_##a##b
607 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ 615 #define INTERNAL_TRACE_EVENT_UID2(a,b) \
608 INTERNAL_TRACE_EVENT_UID3(a,b) 616 INTERNAL_TRACE_EVENT_UID3(a,b)
609 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ 617 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \
610 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) 618 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__)
611 619
612 // Implementation detail: internal macro to create static category. 620 // Implementation detail: internal macro to create static category.
613 // No barriers are needed, because this code is designed to operate safely 621 // No barriers are needed, because this code is designed to operate safely
614 // even when the unsigned char* points to garbage data (which may be the case 622 // even when the unsigned char* points to garbage data (which may be the case
615 // on processors without cache coherency). 623 // on processors without cache coherency).
616 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category) \ 624 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category) \
617 static base::subtle::AtomicWord INTERNAL_TRACE_EVENT_UID(atomic) = 0; \ 625 static base::subtle::AtomicWord INTERNAL_TRACE_EVENT_UID(atomic) = 0; \
618 const uint8* INTERNAL_TRACE_EVENT_UID(catstatic) = \ 626 const uint8* INTERNAL_TRACE_EVENT_UID(catstatic) = \
619 reinterpret_cast<const uint8*>( \ 627 reinterpret_cast<const uint8*>( \
620 base::subtle::NoBarrier_Load(&INTERNAL_TRACE_EVENT_UID(atomic))); \ 628 base::subtle::NoBarrier_Load(&INTERNAL_TRACE_EVENT_UID(atomic))); \
621 if (!INTERNAL_TRACE_EVENT_UID(catstatic)) { \ 629 if (!INTERNAL_TRACE_EVENT_UID(catstatic)) { \
622 INTERNAL_TRACE_EVENT_UID(catstatic) = \ 630 INTERNAL_TRACE_EVENT_UID(catstatic) = \
623 TRACE_EVENT_API_GET_CATEGORY_ENABLED(category); \ 631 TRACE_EVENT_API_GET_CATEGORY_ENABLED(category); \
624 base::subtle::NoBarrier_Store(&INTERNAL_TRACE_EVENT_UID(atomic), \ 632 base::subtle::NoBarrier_Store(&INTERNAL_TRACE_EVENT_UID(atomic), \
625 reinterpret_cast<base::subtle::AtomicWord>( \ 633 reinterpret_cast<base::subtle::AtomicWord>( \
626 INTERNAL_TRACE_EVENT_UID(catstatic))); \ 634 INTERNAL_TRACE_EVENT_UID(catstatic))); \
627 } 635 }
628 636
637 // Implementation detail: internal macro to check if Android ATrace or the
638 // current category (using the current static category variable) is enabled.
639 #define INTERNAL_TRACE_EVENT_IS_ATRACE_OR_CATEGORY_ENABLED() \
640 TRACE_EVENT_API_IS_ATRACE_ENABLED() || *INTERNAL_TRACE_EVENT_UID(catstatic)
641
629 // Implementation detail: internal macro to create static category and add 642 // Implementation detail: internal macro to create static category and add
630 // event if the category is enabled. 643 // event if the category is enabled.
631 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ 644 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \
632 do { \ 645 do { \
633 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ 646 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \
634 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ 647 if (INTERNAL_TRACE_EVENT_IS_ATRACE_OR_CATEGORY_ENABLED()) { \
635 trace_event_internal::AddTraceEvent( \ 648 trace_event_internal::AddTraceEvent( \
636 phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \ 649 phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \
637 trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ 650 trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \
638 } \ 651 } \
639 } while (0) 652 } while (0)
640 653
641 // Implementation detail: internal macro to create static category and add begin 654 // Implementation detail: internal macro to create static category and add begin
642 // event if the category is enabled. Also adds the end event when the scope 655 // event if the category is enabled. Also adds the end event when the scope
643 // ends. 656 // ends.
644 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ 657 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \
645 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ 658 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \
646 trace_event_internal::TraceEndOnScopeClose \ 659 trace_event_internal::TraceEndOnScopeClose \
647 INTERNAL_TRACE_EVENT_UID(profileScope); \ 660 INTERNAL_TRACE_EVENT_UID(profileScope); \
648 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ 661 if (INTERNAL_TRACE_EVENT_IS_ATRACE_OR_CATEGORY_ENABLED()) { \
649 trace_event_internal::AddTraceEvent( \ 662 trace_event_internal::AddTraceEvent( \
650 TRACE_EVENT_PHASE_BEGIN, \ 663 TRACE_EVENT_PHASE_BEGIN, \
651 INTERNAL_TRACE_EVENT_UID(catstatic), \ 664 INTERNAL_TRACE_EVENT_UID(catstatic), \
652 name, trace_event_internal::kNoEventId, \ 665 name, trace_event_internal::kNoEventId, \
653 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ 666 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
654 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ 667 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \
655 INTERNAL_TRACE_EVENT_UID(catstatic), name); \ 668 INTERNAL_TRACE_EVENT_UID(catstatic), name); \
656 } 669 }
657 670
658 // Implementation detail: internal macro to create static category and add begin 671 // Implementation detail: internal macro to create static category and add begin
659 // event if the category is enabled. Also adds the end event when the scope 672 // event if the category is enabled. Also adds the end event when the scope
660 // ends. If the elapsed time is < threshold time, the begin/end pair is erased. 673 // ends. If the elapsed time is < threshold time, the begin/end pair is erased.
661 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold, \ 674 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold, \
662 category, name, ...) \ 675 category, name, ...) \
663 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ 676 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \
664 trace_event_internal::TraceEndOnScopeCloseThreshold \ 677 trace_event_internal::TraceEndOnScopeCloseThreshold \
665 INTERNAL_TRACE_EVENT_UID(profileScope); \ 678 INTERNAL_TRACE_EVENT_UID(profileScope); \
666 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ 679 if (INTERNAL_TRACE_EVENT_IS_ATRACE_OR_CATEGORY_ENABLED()) { \
667 int INTERNAL_TRACE_EVENT_UID(begin_event_id) = \ 680 int INTERNAL_TRACE_EVENT_UID(begin_event_id) = \
668 trace_event_internal::AddTraceEvent( \ 681 trace_event_internal::AddTraceEvent( \
669 TRACE_EVENT_PHASE_BEGIN, \ 682 TRACE_EVENT_PHASE_BEGIN, \
670 INTERNAL_TRACE_EVENT_UID(catstatic), \ 683 INTERNAL_TRACE_EVENT_UID(catstatic), \
671 name, trace_event_internal::kNoEventId, \ 684 name, trace_event_internal::kNoEventId, \
672 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ 685 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
673 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ 686 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \
674 INTERNAL_TRACE_EVENT_UID(catstatic), name, \ 687 INTERNAL_TRACE_EVENT_UID(catstatic), name, \
675 INTERNAL_TRACE_EVENT_UID(begin_event_id), threshold); \ 688 INTERNAL_TRACE_EVENT_UID(begin_event_id), threshold); \
676 } 689 }
677 690
678 // Implementation detail: internal macro to create static category and add 691 // Implementation detail: internal macro to create static category and add
679 // event if the category is enabled. 692 // event if the category is enabled.
680 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, flags, \ 693 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, flags, \
681 ...) \ 694 ...) \
682 do { \ 695 do { \
683 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ 696 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \
684 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ 697 if (INTERNAL_TRACE_EVENT_IS_ATRACE_OR_CATEGORY_ENABLED()) { \
685 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ 698 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
686 trace_event_internal::TraceID trace_event_trace_id( \ 699 trace_event_internal::TraceID trace_event_trace_id( \
687 id, &trace_event_flags); \ 700 id, &trace_event_flags); \
688 trace_event_internal::AddTraceEvent( \ 701 trace_event_internal::AddTraceEvent( \
689 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ 702 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \
690 name, trace_event_trace_id.data(), trace_event_flags, \ 703 name, trace_event_trace_id.data(), trace_event_flags, \
691 ##__VA_ARGS__); \ 704 ##__VA_ARGS__); \
692 } \ 705 } \
693 } while (0) 706 } while (0)
694 707
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 const char* name; 1005 const char* name;
993 int threshold_begin_id; 1006 int threshold_begin_id;
994 }; 1007 };
995 Data* p_data_; 1008 Data* p_data_;
996 Data data_; 1009 Data data_;
997 }; 1010 };
998 1011
999 } // namespace trace_event_internal 1012 } // namespace trace_event_internal
1000 1013
1001 #endif // BASE_DEBUG_TRACE_EVENT_H_ 1014 #endif // BASE_DEBUG_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/debug/trace_event.cc » ('j') | base/debug/trace_event_android.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698