OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 165 |
166 #include "platform/EventTracer.h" | 166 #include "platform/EventTracer.h" |
167 | 167 |
168 #include "wtf/DynamicAnnotations.h" | 168 #include "wtf/DynamicAnnotations.h" |
169 #include "wtf/PassRefPtr.h" | 169 #include "wtf/PassRefPtr.h" |
170 #include "wtf/text/CString.h" | 170 #include "wtf/text/CString.h" |
171 | 171 |
172 // By default, const char* argument values are assumed to have long-lived scope | 172 // By default, const char* argument values are assumed to have long-lived scope |
173 // and will not be copied. Use this macro to force a const char* to be copied. | 173 // and will not be copied. Use this macro to force a const char* to be copied. |
174 #define TRACE_STR_COPY(str) \ | 174 #define TRACE_STR_COPY(str) \ |
175 WebCore::TraceEvent::TraceStringWithCopy(str) | 175 blink::TraceEvent::TraceStringWithCopy(str) |
176 | 176 |
177 // By default, uint64 ID argument values are not mangled with the Process ID in | 177 // By default, uint64 ID argument values are not mangled with the Process ID in |
178 // TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling. | 178 // TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling. |
179 #define TRACE_ID_MANGLE(id) \ | 179 #define TRACE_ID_MANGLE(id) \ |
180 WebCore::TraceEvent::TraceID::ForceMangle(id) | 180 blink::TraceEvent::TraceID::ForceMangle(id) |
181 | 181 |
182 // By default, pointers are mangled with the Process ID in TRACE_EVENT_ASYNC | 182 // By default, pointers are mangled with the Process ID in TRACE_EVENT_ASYNC |
183 // macros. Use this macro to prevent Process ID mangling. | 183 // macros. Use this macro to prevent Process ID mangling. |
184 #define TRACE_ID_DONT_MANGLE(id) \ | 184 #define TRACE_ID_DONT_MANGLE(id) \ |
185 WebCore::TraceEvent::TraceID::DontMangle(id) | 185 blink::TraceEvent::TraceID::DontMangle(id) |
186 | 186 |
187 // Records a pair of begin and end events called "name" for the current | 187 // Records a pair of begin and end events called "name" for the current |
188 // scope, with 0, 1 or 2 associated arguments. If the category is not | 188 // scope, with 0, 1 or 2 associated arguments. If the category is not |
189 // enabled, then this does nothing. | 189 // enabled, then this does nothing. |
190 // - category and name strings must have application lifetime (statics or | 190 // - category and name strings must have application lifetime (statics or |
191 // literals). They may not include " chars. | 191 // literals). They may not include " chars. |
192 #define TRACE_EVENT0(category, name) \ | 192 #define TRACE_EVENT0(category, name) \ |
193 INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name) | 193 INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name) |
194 #define TRACE_EVENT1(category, name, arg1_name, arg1_val) \ | 194 #define TRACE_EVENT1(category, name, arg1_name, arg1_val) \ |
195 INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val) | 195 INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val) |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 // long-lived literal strings should be given as the category name. The returned | 523 // long-lived literal strings should be given as the category name. The returned |
524 // pointer can be held permanently in a local static for example. If the | 524 // pointer can be held permanently in a local static for example. If the |
525 // unsigned char is non-zero, tracing is enabled. If tracing is enabled, | 525 // unsigned char is non-zero, tracing is enabled. If tracing is enabled, |
526 // TRACE_EVENT_API_ADD_TRACE_EVENT can be called. It's OK if tracing is disabled | 526 // TRACE_EVENT_API_ADD_TRACE_EVENT can be called. It's OK if tracing is disabled |
527 // between the load of the tracing state and the call to | 527 // between the load of the tracing state and the call to |
528 // TRACE_EVENT_API_ADD_TRACE_EVENT, because this flag only provides an early out | 528 // TRACE_EVENT_API_ADD_TRACE_EVENT, because this flag only provides an early out |
529 // for best performance when tracing is disabled. | 529 // for best performance when tracing is disabled. |
530 // const unsigned char* | 530 // const unsigned char* |
531 // TRACE_EVENT_API_GET_CATEGORY_ENABLED(const char* category_name) | 531 // TRACE_EVENT_API_GET_CATEGORY_ENABLED(const char* category_name) |
532 #define TRACE_EVENT_API_GET_CATEGORY_ENABLED \ | 532 #define TRACE_EVENT_API_GET_CATEGORY_ENABLED \ |
533 WebCore::EventTracer::getTraceCategoryEnabledFlag | 533 blink::EventTracer::getTraceCategoryEnabledFlag |
534 | 534 |
535 // Add a trace event to the platform tracing system. | 535 // Add a trace event to the platform tracing system. |
536 // WebCore::TraceEvent::TraceEventHandle TRACE_EVENT_API_ADD_TRACE_EVENT( | 536 // blink::TraceEvent::TraceEventHandle TRACE_EVENT_API_ADD_TRACE_EVENT( |
537 // char phase, | 537 // char phase, |
538 // const unsigned char* category_enabled, | 538 // const unsigned char* category_enabled, |
539 // const char* name, | 539 // const char* name, |
540 // unsigned long long id, | 540 // unsigned long long id, |
541 // int num_args, | 541 // int num_args, |
542 // const char** arg_names, | 542 // const char** arg_names, |
543 // const unsigned char* arg_types, | 543 // const unsigned char* arg_types, |
544 // const unsigned long long* arg_values, | 544 // const unsigned long long* arg_values, |
545 // const RefPtr<ConvertableToTraceFormat>* convertableValues | 545 // const RefPtr<ConvertableToTraceFormat>* convertableValues |
546 // unsigned char flags) | 546 // unsigned char flags) |
547 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ | 547 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ |
548 WebCore::EventTracer::addTraceEvent | 548 blink::EventTracer::addTraceEvent |
549 | 549 |
550 // Set the duration field of a COMPLETE trace event. | 550 // Set the duration field of a COMPLETE trace event. |
551 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | 551 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( |
552 // WebCore::TraceEvent::TraceEventHandle handle) | 552 // blink::TraceEvent::TraceEventHandle handle) |
553 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ | 553 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ |
554 WebCore::EventTracer::updateTraceEventDuration | 554 blink::EventTracer::updateTraceEventDuration |
555 | 555 |
556 //////////////////////////////////////////////////////////////////////////////// | 556 //////////////////////////////////////////////////////////////////////////////// |
557 | 557 |
558 // Implementation detail: trace event macros create temporary variables | 558 // Implementation detail: trace event macros create temporary variables |
559 // to keep instrumentation overhead low. These macros give each temporary | 559 // to keep instrumentation overhead low. These macros give each temporary |
560 // variable a unique name based on the line number to prevent name collissions. | 560 // variable a unique name based on the line number to prevent name collissions. |
561 #define INTERNAL_TRACE_EVENT_UID3(a, b) \ | 561 #define INTERNAL_TRACE_EVENT_UID3(a, b) \ |
562 trace_event_unique_##a##b | 562 trace_event_unique_##a##b |
563 #define INTERNAL_TRACE_EVENT_UID2(a, b) \ | 563 #define INTERNAL_TRACE_EVENT_UID2(a, b) \ |
564 INTERNAL_TRACE_EVENT_UID3(a, b) | 564 INTERNAL_TRACE_EVENT_UID3(a, b) |
(...skipping 11 matching lines...) Expand all Loading... |
576 INTERNALTRACEEVENTUID(categoryGroupEnabled) = \ | 576 INTERNALTRACEEVENTUID(categoryGroupEnabled) = \ |
577 TRACE_EVENT_API_GET_CATEGORY_ENABLED(category); \ | 577 TRACE_EVENT_API_GET_CATEGORY_ENABLED(category); \ |
578 } | 578 } |
579 | 579 |
580 // Implementation detail: internal macro to create static category and add | 580 // Implementation detail: internal macro to create static category and add |
581 // event if the category is enabled. | 581 // event if the category is enabled. |
582 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ | 582 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ |
583 do { \ | 583 do { \ |
584 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 584 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
585 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) {
\ | 585 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) {
\ |
586 WebCore::TraceEvent::addTraceEvent( \ | 586 blink::TraceEvent::addTraceEvent( \ |
587 phase, INTERNALTRACEEVENTUID(categoryGroupEnabled), name, \ | 587 phase, INTERNALTRACEEVENTUID(categoryGroupEnabled), name, \ |
588 WebCore::TraceEvent::noEventId, flags, ##__VA_ARGS__); \ | 588 blink::TraceEvent::noEventId, flags, ##__VA_ARGS__); \ |
589 } \ | 589 } \ |
590 } while (0) | 590 } while (0) |
591 | 591 |
592 // Implementation detail: internal macro to create static category and add begin | 592 // Implementation detail: internal macro to create static category and add begin |
593 // event if the category is enabled. Also adds the end event when the scope | 593 // event if the category is enabled. Also adds the end event when the scope |
594 // ends. | 594 // ends. |
595 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ | 595 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ |
596 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 596 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
597 WebCore::TraceEvent::ScopedTracer INTERNALTRACEEVENTUID(scopedTracer); \ | 597 blink::TraceEvent::ScopedTracer INTERNALTRACEEVENTUID(scopedTracer); \ |
598 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 598 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
599 WebCore::TraceEvent::TraceEventHandle h = \ | 599 blink::TraceEvent::TraceEventHandle h = \ |
600 WebCore::TraceEvent::addTraceEvent( \ | 600 blink::TraceEvent::addTraceEvent( \ |
601 TRACE_EVENT_PHASE_COMPLETE, \ | 601 TRACE_EVENT_PHASE_COMPLETE, \ |
602 INTERNALTRACEEVENTUID(categoryGroupEnabled), \ | 602 INTERNALTRACEEVENTUID(categoryGroupEnabled), \ |
603 name, WebCore::TraceEvent::noEventId, \ | 603 name, blink::TraceEvent::noEventId, \ |
604 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ | 604 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ |
605 INTERNALTRACEEVENTUID(scopedTracer).initialize( \ | 605 INTERNALTRACEEVENTUID(scopedTracer).initialize( \ |
606 INTERNALTRACEEVENTUID(categoryGroupEnabled), name, h); \ | 606 INTERNALTRACEEVENTUID(categoryGroupEnabled), name, h); \ |
607 } | 607 } |
608 | 608 |
609 // Implementation detail: internal macro to create static category and add | 609 // Implementation detail: internal macro to create static category and add |
610 // event if the category is enabled. | 610 // event if the category is enabled. |
611 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, flags, \ | 611 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, flags, \ |
612 ...) \ | 612 ...) \ |
613 do { \ | 613 do { \ |
614 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 614 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
615 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) {
\ | 615 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) {
\ |
616 unsigned char traceEventFlags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | 616 unsigned char traceEventFlags = flags | TRACE_EVENT_FLAG_HAS_ID; \ |
617 WebCore::TraceEvent::TraceID traceEventTraceID( \ | 617 blink::TraceEvent::TraceID traceEventTraceID( \ |
618 id, &traceEventFlags); \ | 618 id, &traceEventFlags); \ |
619 WebCore::TraceEvent::addTraceEvent( \ | 619 blink::TraceEvent::addTraceEvent( \ |
620 phase, INTERNALTRACEEVENTUID(categoryGroupEnabled), \ | 620 phase, INTERNALTRACEEVENTUID(categoryGroupEnabled), \ |
621 name, traceEventTraceID.data(), traceEventFlags, \ | 621 name, traceEventTraceID.data(), traceEventFlags, \ |
622 ##__VA_ARGS__); \ | 622 ##__VA_ARGS__); \ |
623 } \ | 623 } \ |
624 } while (0) | 624 } while (0) |
625 | 625 |
626 // Notes regarding the following definitions: | 626 // Notes regarding the following definitions: |
627 // New values can be added and propagated to third party libraries, but existing | 627 // New values can be added and propagated to third party libraries, but existing |
628 // definitions must never be changed, because third party libraries may use old | 628 // definitions must never be changed, because third party libraries may use old |
629 // definitions. | 629 // definitions. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 #define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7)) | 661 #define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7)) |
662 #define TRACE_VALUE_TYPE_CONVERTABLE (static_cast<unsigned char>(8)) | 662 #define TRACE_VALUE_TYPE_CONVERTABLE (static_cast<unsigned char>(8)) |
663 | 663 |
664 // These values must be in sync with base::debug::TraceLog::CategoryGroupEnabled
Flags. | 664 // These values must be in sync with base::debug::TraceLog::CategoryGroupEnabled
Flags. |
665 #define ENABLED_FOR_RECORDING (1 << 0) | 665 #define ENABLED_FOR_RECORDING (1 << 0) |
666 #define ENABLED_FOR_EVENT_CALLBACK (1 << 2) | 666 #define ENABLED_FOR_EVENT_CALLBACK (1 << 2) |
667 | 667 |
668 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ | 668 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ |
669 (*INTERNALTRACEEVENTUID(categoryGroupEnabled) & (ENABLED_FOR_RECORDING | ENA
BLED_FOR_EVENT_CALLBACK)) | 669 (*INTERNALTRACEEVENTUID(categoryGroupEnabled) & (ENABLED_FOR_RECORDING | ENA
BLED_FOR_EVENT_CALLBACK)) |
670 | 670 |
671 namespace WebCore { | 671 namespace blink { |
672 | 672 |
673 namespace TraceEvent { | 673 namespace TraceEvent { |
674 | 674 |
675 // Specify these values when the corresponding argument of addTraceEvent is not | 675 // Specify these values when the corresponding argument of addTraceEvent is not |
676 // used. | 676 // used. |
677 const int zeroNumArgs = 0; | 677 const int zeroNumArgs = 0; |
678 const unsigned long long noEventId = 0; | 678 const unsigned long long noEventId = 0; |
679 | 679 |
680 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers | 680 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers |
681 // are mangled with the Process ID so that they are unlikely to collide when the | 681 // are mangled with the Process ID so that they are unlikely to collide when the |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 } | 965 } |
966 | 966 |
967 ~SamplingStateScope() | 967 ~SamplingStateScope() |
968 { | 968 { |
969 SamplingStateScope<BucketNumber>::set(m_previousState); | 969 SamplingStateScope<BucketNumber>::set(m_previousState); |
970 } | 970 } |
971 | 971 |
972 // FIXME: Make load/store to traceSamplingState[] thread-safe and atomic. | 972 // FIXME: Make load/store to traceSamplingState[] thread-safe and atomic. |
973 static inline const char* current() | 973 static inline const char* current() |
974 { | 974 { |
975 return reinterpret_cast<const char*>(*WebCore::traceSamplingState[Bucket
Number]); | 975 return reinterpret_cast<const char*>(*blink::traceSamplingState[BucketNu
mber]); |
976 } | 976 } |
977 static inline void set(const char* categoryAndName) | 977 static inline void set(const char* categoryAndName) |
978 { | 978 { |
979 *WebCore::traceSamplingState[BucketNumber] = reinterpret_cast<long>(cons
t_cast<char*>(categoryAndName)); | 979 *blink::traceSamplingState[BucketNumber] = reinterpret_cast<long>(const_
cast<char*>(categoryAndName)); |
980 } | 980 } |
981 | 981 |
982 private: | 982 private: |
983 const char* m_previousState; | 983 const char* m_previousState; |
984 }; | 984 }; |
985 | 985 |
986 template<typename IDType> class TraceScopedTrackableObject { | 986 template<typename IDType> class TraceScopedTrackableObject { |
987 WTF_MAKE_NONCOPYABLE(TraceScopedTrackableObject); | 987 WTF_MAKE_NONCOPYABLE(TraceScopedTrackableObject); |
988 public: | 988 public: |
989 TraceScopedTrackableObject(const char* categoryGroup, const char* name, IDTy
pe id) | 989 TraceScopedTrackableObject(const char* categoryGroup, const char* name, IDTy
pe id) |
990 : m_categoryGroup(categoryGroup), m_name(name), m_id(id) | 990 : m_categoryGroup(categoryGroup), m_name(name), m_id(id) |
991 { | 991 { |
992 TRACE_EVENT_OBJECT_CREATED_WITH_ID(m_categoryGroup, m_name, m_id); | 992 TRACE_EVENT_OBJECT_CREATED_WITH_ID(m_categoryGroup, m_name, m_id); |
993 } | 993 } |
994 | 994 |
995 ~TraceScopedTrackableObject() | 995 ~TraceScopedTrackableObject() |
996 { | 996 { |
997 TRACE_EVENT_OBJECT_DELETED_WITH_ID(m_categoryGroup, m_name, m_id); | 997 TRACE_EVENT_OBJECT_DELETED_WITH_ID(m_categoryGroup, m_name, m_id); |
998 } | 998 } |
999 | 999 |
1000 private: | 1000 private: |
1001 const char* m_categoryGroup; | 1001 const char* m_categoryGroup; |
1002 const char* m_name; | 1002 const char* m_name; |
1003 IDType m_id; | 1003 IDType m_id; |
1004 }; | 1004 }; |
1005 | 1005 |
1006 } // namespace TraceEvent | 1006 } // namespace TraceEvent |
1007 | 1007 |
1008 } // namespace WebCore | 1008 } // namespace blink |
1009 | 1009 |
1010 #endif | 1010 #endif |
OLD | NEW |