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

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

Issue 66193005: Independently enable recording and event callback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
« no previous file with comments | « no previous file | base/debug/trace_event_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 file defines the set of trace_event macros without specifying 5 // This header file defines the set of 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 // events to some other universe, you can copy-and-paste this file as well as 7 // events to some other universe, you can copy-and-paste this file as well as
8 // trace_event.h, modifying the macros contained there as necessary for the 8 // trace_event.h, modifying the macros contained there as necessary for the
9 // target platform. The end result is that multiple libraries can funnel events 9 // target platform. The end result is that multiple libraries can funnel events
10 // through to a shared trace event collector. 10 // through to a shared trace event collector.
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 // int num_args, 800 // int num_args,
801 // const char** arg_names, 801 // const char** arg_names,
802 // const unsigned char* arg_types, 802 // const unsigned char* arg_types,
803 // const unsigned long long* arg_values, 803 // const unsigned long long* arg_values,
804 // unsigned char flags) 804 // unsigned char flags)
805 #define TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP \ 805 #define TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP \
806 base::debug::TraceLog::GetInstance()->AddTraceEventWithThreadIdAndTimestamp 806 base::debug::TraceLog::GetInstance()->AddTraceEventWithThreadIdAndTimestamp
807 807
808 // Set the duration field of a COMPLETE trace event. 808 // Set the duration field of a COMPLETE trace event.
809 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( 809 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
810 // const unsigned char* category_group_enabled,
811 // const char* name,
810 // base::debug::TraceEventHandle id) 812 // base::debug::TraceEventHandle id)
811 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ 813 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
812 base::debug::TraceLog::GetInstance()->UpdateTraceEventDuration 814 base::debug::TraceLog::GetInstance()->UpdateTraceEventDuration
813 815
814 // Defines atomic operations used internally by the tracing system. 816 // Defines atomic operations used internally by the tracing system.
815 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord 817 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord
816 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var)) 818 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var))
817 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \ 819 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \
818 base::subtle::NoBarrier_Store(&(var), (value)) 820 base::subtle::NoBarrier_Store(&(var), (value))
819 821
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ 883 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
882 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 884 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
883 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ 885 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
884 if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \ 886 if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \
885 base::debug::TraceEventHandle h = trace_event_internal::AddTraceEvent( \ 887 base::debug::TraceEventHandle h = trace_event_internal::AddTraceEvent( \
886 TRACE_EVENT_PHASE_COMPLETE, \ 888 TRACE_EVENT_PHASE_COMPLETE, \
887 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ 889 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \
888 name, trace_event_internal::kNoEventId, \ 890 name, trace_event_internal::kNoEventId, \
889 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ 891 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
890 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ 892 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
891 INTERNAL_TRACE_EVENT_UID(category_group_enabled), h); \ 893 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
892 } 894 }
893 895
894 // Implementation detail: internal macro to create static category and add 896 // Implementation detail: internal macro to create static category and add
895 // event if the category is enabled. 897 // event if the category is enabled.
896 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ 898 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \
897 flags, ...) \ 899 flags, ...) \
898 do { \ 900 do { \
899 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 901 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
900 if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \ 902 if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \
901 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ 903 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 } 1373 }
1372 1374
1373 // Used by TRACE_EVENTx macros. Do not use directly. 1375 // Used by TRACE_EVENTx macros. Do not use directly.
1374 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { 1376 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer {
1375 public: 1377 public:
1376 // Note: members of data_ intentionally left uninitialized. See Initialize. 1378 // Note: members of data_ intentionally left uninitialized. See Initialize.
1377 ScopedTracer() : p_data_(NULL) {} 1379 ScopedTracer() : p_data_(NULL) {}
1378 1380
1379 ~ScopedTracer() { 1381 ~ScopedTracer() {
1380 if (p_data_ && *data_.category_group_enabled) 1382 if (p_data_ && *data_.category_group_enabled)
1381 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(data_.event_handle); 1383 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
1384 data_.category_group_enabled, data_.name, data_.event_handle);
1382 } 1385 }
1383 1386
1384 void Initialize(const unsigned char* category_group_enabled, 1387 void Initialize(const unsigned char* category_group_enabled,
1388 const char* name,
1385 base::debug::TraceEventHandle event_handle) { 1389 base::debug::TraceEventHandle event_handle) {
1386 data_.category_group_enabled = category_group_enabled; 1390 data_.category_group_enabled = category_group_enabled;
1391 data_.name = name;
1387 data_.event_handle = event_handle; 1392 data_.event_handle = event_handle;
1388 p_data_ = &data_; 1393 p_data_ = &data_;
1389 } 1394 }
1390 1395
1391 private: 1396 private:
1392 // This Data struct workaround is to avoid initializing all the members 1397 // This Data struct workaround is to avoid initializing all the members
1393 // in Data during construction of this object, since this object is always 1398 // in Data during construction of this object, since this object is always
1394 // constructed, even when tracing is disabled. If the members of Data were 1399 // constructed, even when tracing is disabled. If the members of Data were
1395 // members of this class instead, compiler warnings occur about potential 1400 // members of this class instead, compiler warnings occur about potential
1396 // uninitialized accesses. 1401 // uninitialized accesses.
1397 struct Data { 1402 struct Data {
1398 const unsigned char* category_group_enabled; 1403 const unsigned char* category_group_enabled;
1404 const char* name;
1399 base::debug::TraceEventHandle event_handle; 1405 base::debug::TraceEventHandle event_handle;
1400 }; 1406 };
1401 Data* p_data_; 1407 Data* p_data_;
1402 Data data_; 1408 Data data_;
1403 }; 1409 };
1404 1410
1405 // Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly. 1411 // Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly.
1406 class TRACE_EVENT_API_CLASS_EXPORT ScopedTraceBinaryEfficient { 1412 class TRACE_EVENT_API_CLASS_EXPORT ScopedTraceBinaryEfficient {
1407 public: 1413 public:
1408 ScopedTraceBinaryEfficient(const char* category_group, const char* name); 1414 ScopedTraceBinaryEfficient(const char* category_group, const char* name);
1409 ~ScopedTraceBinaryEfficient(); 1415 ~ScopedTraceBinaryEfficient();
1410 1416
1411 private: 1417 private:
1412 const unsigned char* category_group_enabled_; 1418 const unsigned char* category_group_enabled_;
1419 const char* name_;
1413 base::debug::TraceEventHandle event_handle_; 1420 base::debug::TraceEventHandle event_handle_;
1414 }; 1421 };
1415 1422
1416 // This macro generates less code then TRACE_EVENT0 but is also 1423 // This macro generates less code then TRACE_EVENT0 but is also
1417 // slower to execute when tracing is off. It should generally only be 1424 // slower to execute when tracing is off. It should generally only be
1418 // used with code that is seldom executed or conditionally executed 1425 // used with code that is seldom executed or conditionally executed
1419 // when debugging. 1426 // when debugging.
1420 // For now the category_group must be "gpu". 1427 // For now the category_group must be "gpu".
1421 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \ 1428 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \
1422 trace_event_internal::ScopedTraceBinaryEfficient \ 1429 trace_event_internal::ScopedTraceBinaryEfficient \
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 const char* name_; 1488 const char* name_;
1482 IDType id_; 1489 IDType id_;
1483 1490
1484 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); 1491 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject);
1485 }; 1492 };
1486 1493
1487 } // namespace debug 1494 } // namespace debug
1488 } // namespace base 1495 } // namespace base
1489 1496
1490 #endif /* BASE_DEBUG_TRACE_EVENT_H_ */ 1497 #endif /* BASE_DEBUG_TRACE_EVENT_H_ */
OLDNEW
« no previous file with comments | « no previous file | base/debug/trace_event_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698