| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 flags, ##__VA_ARGS__); \ | 163 flags, ##__VA_ARGS__); \ |
| 164 } \ | 164 } \ |
| 165 } while (0) | 165 } while (0) |
| 166 | 166 |
| 167 // Implementation detail: internal macro to create static category and add begin | 167 // Implementation detail: internal macro to create static category and add begin |
| 168 // event if the category is enabled. Also adds the end event when the scope | 168 // event if the category is enabled. Also adds the end event when the scope |
| 169 // ends. | 169 // ends. |
| 170 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ | 170 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ |
| 171 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 171 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 172 blink::TraceEvent::ScopedTracer INTERNALTRACEEVENTUID(scopedTracer); \ | 172 blink::TraceEvent::ScopedTracer INTERNALTRACEEVENTUID(scopedTracer); \ |
| 173 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 173 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_TRACING()) { \ |
| 174 blink::TraceEvent::TraceEventHandle h = \ | 174 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) {
\ |
| 175 blink::TraceEvent::addTraceEvent( \ | 175 blink::TraceEvent::TraceEventHandle h = \ |
| 176 TRACE_EVENT_PHASE_COMPLETE, \ | 176 blink::TraceEvent::addTraceEvent( \ |
| 177 INTERNALTRACEEVENTUID(categoryGroupEnabled), name, \ | 177 TRACE_EVENT_PHASE_COMPLETE, \ |
| 178 blink::TraceEvent::kGlobalScope, blink::TraceEvent::noEventId, \ | 178 INTERNALTRACEEVENTUID(categoryGroupEnabled), name, \ |
| 179 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ | 179 blink::TraceEvent::kGlobalScope, blink::TraceEvent::noEventI
d, \ |
| 180 INTERNALTRACEEVENTUID(scopedTracer).initialize( \ | 180 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ |
| 181 INTERNALTRACEEVENTUID(categoryGroupEnabled), name, h); \ | 181 INTERNALTRACEEVENTUID(scopedTracer).initialize( \ |
| 182 INTERNALTRACEEVENTUID(categoryGroupEnabled), name, h); \ |
| 183 } \ |
| 184 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_PROFILING()) { \ |
| 185 INTERNALTRACEEVENTUID(scopedTracer) \ |
| 186 .initializeForHeapProfiling(name, TRACE_EVENT_FLAG_NONE); \ |
| 187 } \ |
| 182 } | 188 } |
| 183 | 189 |
| 184 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category, name, bindId, flowFl
ags, ...) \ | 190 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category, name, bindId, flowFl
ags, ...) \ |
| 185 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 191 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 186 blink::TraceEvent::ScopedTracer INTERNALTRACEEVENTUID(scopedTracer); \ | 192 blink::TraceEvent::ScopedTracer INTERNALTRACEEVENTUID(scopedTracer); \ |
| 187 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 193 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_TRACING()) { \ |
| 188 unsigned traceEventFlags = flowFlags; \ | 194 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) {
\ |
| 189 blink::TraceEvent::TraceID traceEventBindId(bindId, &traceEventFlags); \ | 195 unsigned traceEventFlags = flowFlags; \ |
| 190 blink::TraceEvent::TraceEventHandle h = \ | 196 blink::TraceEvent::TraceID traceEventBindId(bindId, &traceEventFlags
); \ |
| 191 blink::TraceEvent::addTraceEvent( \ | 197 blink::TraceEvent::TraceEventHandle h = \ |
| 192 TRACE_EVENT_PHASE_COMPLETE, \ | 198 blink::TraceEvent::addTraceEvent( \ |
| 193 INTERNALTRACEEVENTUID(categoryGroupEnabled), name, \ | 199 TRACE_EVENT_PHASE_COMPLETE, \ |
| 194 blink::TraceEvent::kGlobalScope, blink::TraceEvent::noEventId, \ | 200 INTERNALTRACEEVENTUID(categoryGroupEnabled), name, \ |
| 195 traceEventBindId.data(), \ | 201 blink::TraceEvent::kGlobalScope, blink::TraceEvent::noEventI
d, \ |
| 196 EventTracer::systemTraceTime(), traceEventFlags, ##__VA_ARGS__);
\ | 202 traceEventBindId.data(), \ |
| 197 INTERNALTRACEEVENTUID(scopedTracer).initialize( \ | 203 EventTracer::systemTraceTime(), traceEventFlags, ##__VA_ARGS
__); \ |
| 198 INTERNALTRACEEVENTUID(categoryGroupEnabled), name, h); \ | 204 INTERNALTRACEEVENTUID(scopedTracer).initialize( \ |
| 205 INTERNALTRACEEVENTUID(categoryGroupEnabled), name, h); \ |
| 206 } \ |
| 207 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_PROFILING()) { \ |
| 208 INTERNALTRACEEVENTUID(scopedTracer) \ |
| 209 .initializeForHeapProfiling(name, TRACE_EVENT_FLAG_NONE); \ |
| 210 } \ |
| 199 } | 211 } |
| 200 | 212 |
| 201 // Implementation detail: internal macro to create static category and add | 213 // Implementation detail: internal macro to create static category and add |
| 202 // event if the category is enabled. | 214 // event if the category is enabled. |
| 203 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, flags, ...)
\ | 215 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, flags, ...)
\ |
| 204 do { \ | 216 do { \ |
| 205 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 217 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 206 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) {
\ | 218 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) {
\ |
| 207 unsigned traceEventFlags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | 219 unsigned traceEventFlags = flags | TRACE_EVENT_FLAG_HAS_ID; \ |
| 208 blink::TraceEvent::TraceID traceEventTraceID( \ | 220 blink::TraceEvent::TraceID traceEventTraceID( \ |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ | 274 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ |
| 263 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ | 275 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ |
| 264 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ | 276 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ |
| 265 }; \ | 277 }; \ |
| 266 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ | 278 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ |
| 267 INTERNAL_TRACE_EVENT_UID(scoped_context)(context.data()); | 279 INTERNAL_TRACE_EVENT_UID(scoped_context)(context.data()); |
| 268 | 280 |
| 269 // These values must be in sync with base::debug::TraceLog::CategoryGroupEnabled
Flags. | 281 // These values must be in sync with base::debug::TraceLog::CategoryGroupEnabled
Flags. |
| 270 #define ENABLED_FOR_RECORDING (1 << 0) | 282 #define ENABLED_FOR_RECORDING (1 << 0) |
| 271 #define ENABLED_FOR_EVENT_CALLBACK (1 << 2) | 283 #define ENABLED_FOR_EVENT_CALLBACK (1 << 2) |
| 284 #define ENABLED_FOR_ETW_EXPORT (1 << 3) |
| 285 #define ENABLED_FOR_PROFILING (1 << 4) |
| 286 #define ENABLED_FOR_NON_PROFILING_MODE (ENABLED_FOR_RECORDING | ENABLED_FOR_EVEN
T_CALLBACK | ENABLED_FOR_ETW_EXPORT) |
| 287 |
| 288 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_TRACING() \ |
| 289 (*INTERNALTRACEEVENTUID(categoryGroupEnabled) & (ENABLED_FOR_PROFILING | ENA
BLED_FOR_NON_PROFILING_MODE)) |
| 272 | 290 |
| 273 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ | 291 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ |
| 274 (*INTERNALTRACEEVENTUID(categoryGroupEnabled) & (ENABLED_FOR_RECORDING | ENA
BLED_FOR_EVENT_CALLBACK)) | 292 (*INTERNALTRACEEVENTUID(categoryGroupEnabled) & ENABLED_FOR_NON_PROFILING_MO
DE) |
| 293 |
| 294 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_PROFILING() \ |
| 295 (*INTERNALTRACEEVENTUID(categoryGroupEnabled) & ENABLED_FOR_PROFILING) |
| 275 | 296 |
| 276 #define INTERNAL_TRACE_MEMORY(category, name) | 297 #define INTERNAL_TRACE_MEMORY(category, name) |
| 277 | 298 |
| 278 namespace blink { | 299 namespace blink { |
| 279 | 300 |
| 280 namespace TraceEvent { | 301 namespace TraceEvent { |
| 281 | 302 |
| 282 // Specify these values when the corresponding argument of addTraceEvent is not | 303 // Specify these values when the corresponding argument of addTraceEvent is not |
| 283 // used. | 304 // used. |
| 284 const int zeroNumArgs = 0; | 305 const int zeroNumArgs = 0; |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 | 615 |
| 595 // Used by TRACE_EVENTx macro. Do not use directly. | 616 // Used by TRACE_EVENTx macro. Do not use directly. |
| 596 class ScopedTracer final { | 617 class ScopedTracer final { |
| 597 STACK_ALLOCATED(); | 618 STACK_ALLOCATED(); |
| 598 WTF_MAKE_NONCOPYABLE(ScopedTracer); | 619 WTF_MAKE_NONCOPYABLE(ScopedTracer); |
| 599 public: | 620 public: |
| 600 // Note: members of m_data intentionally left uninitialized. See initialize. | 621 // Note: members of m_data intentionally left uninitialized. See initialize. |
| 601 ScopedTracer() : m_pdata(0) { } | 622 ScopedTracer() : m_pdata(0) { } |
| 602 ~ScopedTracer() | 623 ~ScopedTracer() |
| 603 { | 624 { |
| 604 if (m_pdata && *m_pdata->categoryGroupEnabled) | 625 if (m_data.name) { |
| 605 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(m_data.categoryGroupEnab
led, m_data.name, m_data.eventHandle); | 626 if (m_data.initializedForProfiling) |
| 627 blink::EventTracer::pushPseudoStackFrame(m_data.name); |
| 628 if (m_pdata && *m_pdata->categoryGroupEnabled) |
| 629 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(m_data.categoryGroup
Enabled, m_data.name, m_data.eventHandle); |
| 630 } |
| 606 } | 631 } |
| 607 | 632 |
| 608 void initialize(const unsigned char* categoryGroupEnabled, const char* name,
TraceEventHandle eventHandle) | 633 void initialize(const unsigned char* categoryGroupEnabled, const char* name,
TraceEventHandle eventHandle) |
| 609 { | 634 { |
| 610 m_data.categoryGroupEnabled = categoryGroupEnabled; | 635 m_data.categoryGroupEnabled = categoryGroupEnabled; |
| 611 m_data.name = name; | 636 m_data.name = name; |
| 612 m_data.eventHandle = eventHandle; | 637 m_data.eventHandle = eventHandle; |
| 613 m_pdata = &m_data; | 638 m_pdata = &m_data; |
| 614 } | 639 } |
| 615 | 640 |
| 641 void initializeForHeapProfiling(const char* name, unsigned flags) |
| 642 { |
| 643 if (!(flags & TRACE_EVENT_FLAG_COPY)) { |
| 644 m_data.initializedForProfiling = true; |
| 645 m_data.name = name; |
| 646 blink::EventTracer::pushPseudoStackFrame(name); |
| 647 } |
| 648 } |
| 649 |
| 616 private: | 650 private: |
| 617 // This Data struct workaround is to avoid initializing all the members | 651 // This Data struct workaround is to avoid initializing all the members |
| 618 // in Data during construction of this object, since this object is always | 652 // in Data during construction of this object, since this object is always |
| 619 // constructed, even when tracing is disabled. If the members of Data were | 653 // constructed, even when tracing is disabled. If the members of Data were |
| 620 // members of this class instead, compiler warnings occur about potential | 654 // members of this class instead, compiler warnings occur about potential |
| 621 // uninitialized accesses. | 655 // uninitialized accesses. |
| 622 struct Data { | 656 struct Data { |
| 623 DISALLOW_NEW(); | 657 DISALLOW_NEW(); |
| 624 const unsigned char* categoryGroupEnabled; | 658 const unsigned char* categoryGroupEnabled; |
| 625 const char* name; | 659 const char* name; |
| 626 TraceEventHandle eventHandle; | 660 TraceEventHandle eventHandle; |
| 661 bool initializedForProfiling; |
| 627 }; | 662 }; |
| 628 Data* m_pdata; | 663 Data* m_pdata; |
| 629 Data m_data; | 664 Data m_data; |
| 630 }; | 665 }; |
| 631 | 666 |
| 632 // TraceEventSamplingStateScope records the current sampling state | 667 // TraceEventSamplingStateScope records the current sampling state |
| 633 // and sets a new sampling state. When the scope exists, it restores | 668 // and sets a new sampling state. When the scope exists, it restores |
| 634 // the sampling state having recorded. | 669 // the sampling state having recorded. |
| 635 template<size_t BucketNumber> | 670 template<size_t BucketNumber> |
| 636 class SamplingStateScope final { | 671 class SamplingStateScope final { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 const char* m_categoryGroup; | 716 const char* m_categoryGroup; |
| 682 const char* m_name; | 717 const char* m_name; |
| 683 IDType m_id; | 718 IDType m_id; |
| 684 }; | 719 }; |
| 685 | 720 |
| 686 } // namespace TraceEvent | 721 } // namespace TraceEvent |
| 687 | 722 |
| 688 } // namespace blink | 723 } // namespace blink |
| 689 | 724 |
| 690 #endif | 725 #endif |
| OLD | NEW |