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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 const int zeroNumArgs = 0; | 284 const int zeroNumArgs = 0; |
285 const std::nullptr_t kGlobalScope = nullptr; | 285 const std::nullptr_t kGlobalScope = nullptr; |
286 const unsigned long long noEventId = 0; | 286 const unsigned long long noEventId = 0; |
287 const unsigned long long noBindId = 0; | 287 const unsigned long long noBindId = 0; |
288 | 288 |
289 // TraceID encapsulates an ID that can either be an integer or pointer; | 289 // TraceID encapsulates an ID that can either be an integer or pointer; |
290 // optionally, it can be paired with a scope string, too. Pointers are mangled | 290 // optionally, it can be paired with a scope string, too. Pointers are mangled |
291 // with the Process ID so that they are unlikely to collide when the same | 291 // with the Process ID so that they are unlikely to collide when the same |
292 // pointer is used on different processes. | 292 // pointer is used on different processes. |
293 class TraceID final { | 293 class TraceID final { |
294 STACK_ALLOCATED(); | 294 DISALLOW_NEW(); |
295 WTF_MAKE_NONCOPYABLE(TraceID); | 295 WTF_MAKE_NONCOPYABLE(TraceID); |
296 public: | 296 public: |
297 class WithScope final { | 297 class WithScope final { |
298 STACK_ALLOCATED(); | 298 DISALLOW_NEW(); |
| 299 |
299 public: | 300 public: |
300 template<typename T> WithScope(const char* scope, T id) | 301 template<typename T> WithScope(const char* scope, T id) |
301 : m_scope(scope), m_data(reinterpret_cast<unsigned long long>(id)) {
} | 302 : m_scope(scope), m_data(reinterpret_cast<unsigned long long>(id)) {
} |
302 const char* scope() const { return m_scope; } | 303 const char* scope() const { return m_scope; } |
303 unsigned long long data() const { return m_data; } | 304 unsigned long long data() const { return m_data; } |
304 private: | 305 private: |
305 const char* m_scope = kGlobalScope; | 306 const char* m_scope = kGlobalScope; |
306 unsigned long long m_data; | 307 unsigned long long m_data; |
307 }; | 308 }; |
308 | 309 |
309 template<bool dummyMangle> class MangleBehavior final { | 310 template<bool dummyMangle> class MangleBehavior final { |
310 STACK_ALLOCATED(); | 311 DISALLOW_NEW(); |
| 312 |
311 public: | 313 public: |
312 template<typename T> explicit MangleBehavior(T id) : m_data(reinterpret_
cast<unsigned long long>(id)) { } | 314 template<typename T> explicit MangleBehavior(T id) : m_data(reinterpret_
cast<unsigned long long>(id)) { } |
313 explicit MangleBehavior(WithScope scopedID) : m_scope(scopedID.scope()),
m_data(scopedID.data()) { } | 315 explicit MangleBehavior(WithScope scopedID) : m_scope(scopedID.scope()),
m_data(scopedID.data()) { } |
314 const char* scope() const { return m_scope; } | 316 const char* scope() const { return m_scope; } |
315 unsigned long long data() const { return m_data; } | 317 unsigned long long data() const { return m_data; } |
316 private: | 318 private: |
317 const char* m_scope = kGlobalScope; | 319 const char* m_scope = kGlobalScope; |
318 unsigned long long m_data; | 320 unsigned long long m_data; |
319 }; | 321 }; |
320 typedef MangleBehavior<false> DontMangle; | 322 typedef MangleBehavior<false> DontMangle; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 bool m_bool; | 364 bool m_bool; |
363 unsigned long long m_uint; | 365 unsigned long long m_uint; |
364 long long m_int; | 366 long long m_int; |
365 double m_double; | 367 double m_double; |
366 const void* m_pointer; | 368 const void* m_pointer; |
367 const char* m_string; | 369 const char* m_string; |
368 }; | 370 }; |
369 | 371 |
370 // Simple container for const char* that should be copied instead of retained. | 372 // Simple container for const char* that should be copied instead of retained. |
371 class TraceStringWithCopy { | 373 class TraceStringWithCopy { |
372 STACK_ALLOCATED(); | 374 DISALLOW_NEW(); |
| 375 |
373 public: | 376 public: |
374 explicit TraceStringWithCopy(const char* str) : m_str(str) { } | 377 explicit TraceStringWithCopy(const char* str) : m_str(str) { } |
375 const char* str() const { return m_str; } | 378 const char* str() const { return m_str; } |
376 private: | 379 private: |
377 const char* m_str; | 380 const char* m_str; |
378 }; | 381 }; |
379 | 382 |
380 // Define setTraceValue for each allowed type. It stores the type and | 383 // Define setTraceValue for each allowed type. It stores the type and |
381 // value in the return arguments. This allows this API to avoid declaring any | 384 // value in the return arguments. This allows this API to avoid declaring any |
382 // structures so that it is portable to third_party libraries. | 385 // structures so that it is portable to third_party libraries. |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 const char* arg2Name, | 590 const char* arg2Name, |
588 const ARG2_TYPE& arg2Val) | 591 const ARG2_TYPE& arg2Val) |
589 { | 592 { |
590 return addTraceEvent(phase, categoryEnabled, name, scope, id, | 593 return addTraceEvent(phase, categoryEnabled, name, scope, id, |
591 blink::TraceEvent::noBindId, EventTracer::systemTraceTime(), flags, | 594 blink::TraceEvent::noBindId, EventTracer::systemTraceTime(), flags, |
592 arg1Name, arg1Val, arg2Name, arg2Val); | 595 arg1Name, arg1Val, arg2Name, arg2Val); |
593 } | 596 } |
594 | 597 |
595 // Used by TRACE_EVENTx macro. Do not use directly. | 598 // Used by TRACE_EVENTx macro. Do not use directly. |
596 class ScopedTracer final { | 599 class ScopedTracer final { |
597 STACK_ALLOCATED(); | 600 DISALLOW_NEW(); |
598 WTF_MAKE_NONCOPYABLE(ScopedTracer); | 601 WTF_MAKE_NONCOPYABLE(ScopedTracer); |
599 public: | 602 public: |
600 // Note: members of m_data intentionally left uninitialized. See initialize. | 603 // Note: members of m_data intentionally left uninitialized. See initialize. |
601 ScopedTracer() : m_pdata(0) { } | 604 ScopedTracer() : m_pdata(0) { } |
602 ~ScopedTracer() | 605 ~ScopedTracer() |
603 { | 606 { |
604 if (m_pdata && *m_pdata->categoryGroupEnabled) | 607 if (m_pdata && *m_pdata->categoryGroupEnabled) |
605 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(m_data.categoryGroupEnab
led, m_data.name, m_data.eventHandle); | 608 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(m_data.categoryGroupEnab
led, m_data.name, m_data.eventHandle); |
606 } | 609 } |
607 | 610 |
(...skipping 19 matching lines...) Expand all Loading... |
627 }; | 630 }; |
628 Data* m_pdata; | 631 Data* m_pdata; |
629 Data m_data; | 632 Data m_data; |
630 }; | 633 }; |
631 | 634 |
632 // TraceEventSamplingStateScope records the current sampling state | 635 // TraceEventSamplingStateScope records the current sampling state |
633 // and sets a new sampling state. When the scope exists, it restores | 636 // and sets a new sampling state. When the scope exists, it restores |
634 // the sampling state having recorded. | 637 // the sampling state having recorded. |
635 template<size_t BucketNumber> | 638 template<size_t BucketNumber> |
636 class SamplingStateScope final { | 639 class SamplingStateScope final { |
637 STACK_ALLOCATED(); | 640 DISALLOW_NEW(); |
638 WTF_MAKE_NONCOPYABLE(SamplingStateScope); | 641 WTF_MAKE_NONCOPYABLE(SamplingStateScope); |
639 public: | 642 public: |
640 SamplingStateScope(const char* categoryAndName) | 643 SamplingStateScope(const char* categoryAndName) |
641 { | 644 { |
642 m_previousState = SamplingStateScope<BucketNumber>::current(); | 645 m_previousState = SamplingStateScope<BucketNumber>::current(); |
643 SamplingStateScope<BucketNumber>::set(categoryAndName); | 646 SamplingStateScope<BucketNumber>::set(categoryAndName); |
644 } | 647 } |
645 | 648 |
646 ~SamplingStateScope() | 649 ~SamplingStateScope() |
647 { | 650 { |
648 SamplingStateScope<BucketNumber>::set(m_previousState); | 651 SamplingStateScope<BucketNumber>::set(m_previousState); |
649 } | 652 } |
650 | 653 |
651 // FIXME: Make load/store to traceSamplingState[] thread-safe and atomic. | 654 // FIXME: Make load/store to traceSamplingState[] thread-safe and atomic. |
652 static const char* current() | 655 static const char* current() |
653 { | 656 { |
654 return reinterpret_cast<const char*>(*blink::traceSamplingState[BucketNu
mber]); | 657 return reinterpret_cast<const char*>(*blink::traceSamplingState[BucketNu
mber]); |
655 } | 658 } |
656 static void set(const char* categoryAndName) | 659 static void set(const char* categoryAndName) |
657 { | 660 { |
658 *blink::traceSamplingState[BucketNumber] = reinterpret_cast<TraceEventAP
IAtomicWord>(categoryAndName); | 661 *blink::traceSamplingState[BucketNumber] = reinterpret_cast<TraceEventAP
IAtomicWord>(categoryAndName); |
659 } | 662 } |
660 | 663 |
661 private: | 664 private: |
662 const char* m_previousState; | 665 const char* m_previousState; |
663 }; | 666 }; |
664 | 667 |
665 template<typename IDType> class TraceScopedTrackableObject { | 668 template<typename IDType> class TraceScopedTrackableObject { |
666 STACK_ALLOCATED(); | 669 DISALLOW_NEW(); |
667 WTF_MAKE_NONCOPYABLE(TraceScopedTrackableObject); | 670 WTF_MAKE_NONCOPYABLE(TraceScopedTrackableObject); |
668 public: | 671 public: |
669 TraceScopedTrackableObject(const char* categoryGroup, const char* name, IDTy
pe id) | 672 TraceScopedTrackableObject(const char* categoryGroup, const char* name, IDTy
pe id) |
670 : m_categoryGroup(categoryGroup), m_name(name), m_id(id) | 673 : m_categoryGroup(categoryGroup), m_name(name), m_id(id) |
671 { | 674 { |
672 TRACE_EVENT_OBJECT_CREATED_WITH_ID(m_categoryGroup, m_name, m_id); | 675 TRACE_EVENT_OBJECT_CREATED_WITH_ID(m_categoryGroup, m_name, m_id); |
673 } | 676 } |
674 | 677 |
| 678 template <typename ArgType> |
| 679 void snapshot(ArgType snapshot) const |
| 680 { |
| 681 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(m_categoryGroup, m_name, m_id, snaps
hot); |
| 682 } |
| 683 |
675 ~TraceScopedTrackableObject() | 684 ~TraceScopedTrackableObject() |
676 { | 685 { |
677 TRACE_EVENT_OBJECT_DELETED_WITH_ID(m_categoryGroup, m_name, m_id); | 686 TRACE_EVENT_OBJECT_DELETED_WITH_ID(m_categoryGroup, m_name, m_id); |
678 } | 687 } |
679 | 688 |
680 private: | 689 private: |
681 const char* m_categoryGroup; | 690 const char* m_categoryGroup; |
682 const char* m_name; | 691 const char* m_name; |
683 IDType m_id; | 692 IDType m_id; |
684 }; | 693 }; |
685 | 694 |
686 } // namespace TraceEvent | 695 } // namespace TraceEvent |
687 | 696 |
688 } // namespace blink | 697 } // namespace blink |
689 | 698 |
690 #endif | 699 #endif |
OLD | NEW |