| OLD | NEW |
| 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 file contains the Windows-specific declarations for trace_event.h. | 5 // This file contains the Windows-specific declarations for trace_event.h. |
| 6 #ifndef BASE_DEBUG_TRACE_EVENT_WIN_H_ | 6 #ifndef BASE_DEBUG_TRACE_EVENT_WIN_H_ |
| 7 #define BASE_DEBUG_TRACE_EVENT_WIN_H_ | 7 #define BASE_DEBUG_TRACE_EVENT_WIN_H_ |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/win/event_trace_provider.h" | 14 #include "base/win/event_trace_provider.h" |
| 14 | 15 |
| 15 // Fwd. | 16 // Fwd. |
| 16 template <typename Type> | 17 template <typename Type> |
| 17 struct StaticMemorySingletonTraits; | 18 struct StaticMemorySingletonTraits; |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 namespace debug { | 21 namespace debug { |
| 21 | 22 |
| 22 // This EtwTraceProvider subclass implements ETW logging | 23 // This EtwTraceProvider subclass implements ETW logging |
| 23 // for the macros above on Windows. | 24 // for the macros above on Windows. |
| 24 class BASE_EXPORT TraceEventETWProvider : public base::win::EtwTraceProvider { | 25 class BASE_EXPORT TraceEventETWProvider : public base::win::EtwTraceProvider { |
| 25 public: | 26 public: |
| 26 // Start logging trace events. | 27 // Start logging trace events. |
| 27 // This is a noop in this implementation. | 28 // This is a noop in this implementation. |
| 28 static bool StartTracing(); | 29 static bool StartTracing(); |
| 29 | 30 |
| 30 // Trace begin/end/instant events, this is the bottleneck implementation | 31 // Trace begin/end/instant events. |
| 31 // all the others defer to. | |
| 32 // Allowing the use of std::string for name or extra is a convenience, | 32 // Allowing the use of std::string for name or extra is a convenience, |
| 33 // whereas passing name or extra as a const char* avoids the construction | 33 // whereas passing name or extra as a const char* avoids the construction |
| 34 // of temporary std::string instances. | 34 // of temporary std::string instances. |
| 35 // If -1 is passed for name_len or extra_len, the strlen of the string will | 35 // If -1 is passed for name_len or extra_len, the strlen of the string will |
| 36 // be used for length. | 36 // be used for length. |
| 37 static void Trace(const char* name, | 37 static void Trace(const char* name, |
| 38 size_t name_len, | 38 size_t name_len, |
| 39 char type, | 39 char type, |
| 40 const void* id, | 40 const void* id, |
| 41 const char* extra, | 41 const char* extra, |
| 42 size_t extra_len); | 42 size_t extra_len); |
| 43 | 43 |
| 44 // Allows passing extra as a std::string for convenience. | 44 // Allows passing extra as a std::string for convenience. |
| 45 static void Trace(const char* name, | 45 static void Trace(const char* name, |
| 46 char type, | 46 char type, |
| 47 const void* id, | 47 const void* id, |
| 48 const std::string& extra) { | 48 const std::string& extra) { |
| 49 return Trace(name, -1, type, id, extra.c_str(), extra.length()); | 49 return Trace(name, -1, type, id, extra.c_str(), extra.length()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Allows passing extra as a const char* to avoid constructing temporary | 52 // Allows passing extra as a const char* to avoid constructing temporary |
| 53 // std::string instances where not needed. | 53 // std::string instances where not needed. |
| 54 static void Trace(const char* name, | 54 static void Trace(const char* name, |
| 55 char type, | 55 char type, |
| 56 const void* id, | 56 const void* id, |
| 57 const char* extra) { | 57 const char* extra) { |
| 58 return Trace(name, -1, type, id, extra, -1); | 58 return Trace(name, -1, type, id, extra, -1); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Emit a trace event. |
| 62 // The event is defined by |category_group|, |name| and |type|. |
| 63 // |id| helps to identify related events. |
| 64 // |num_args| indicates the number of custom arguments to add to the trace. |
| 65 // It must be <= |kTraceMaxNumArgs|. The names of the arguments are specified |
| 66 // in |arg_names|. |arg_types| indicates how to interpret the value of |
| 67 // each argument. Finally, the value of an argument is obtained from |
| 68 // |convertable_values| if its type is TRACE_VALUE_TYPE_CONVERTABLE, |
| 69 // from |arg_values| otherwise. |
| 70 static void TraceWithArgs( |
| 71 const char* category_group, |
| 72 const char* name, |
| 73 char type, |
| 74 unsigned long long id, |
| 75 int num_args, |
| 76 const char** arg_names, |
| 77 const unsigned char* arg_types, |
| 78 const unsigned long long* arg_values, |
| 79 const scoped_refptr<ConvertableToTraceFormat>* convertable_values); |
| 80 |
| 61 // Retrieves the singleton. | 81 // Retrieves the singleton. |
| 62 // Note that this may return NULL post-AtExit processing. | 82 // Note that this may return NULL post-AtExit processing. |
| 63 static TraceEventETWProvider* GetInstance(); | 83 static TraceEventETWProvider* GetInstance(); |
| 64 | 84 |
| 65 // Returns true iff tracing is turned on. | 85 // Returns true iff tracing is turned on. |
| 66 bool IsTracing() { | 86 bool IsTracing() { |
| 67 return enable_level() >= TRACE_LEVEL_INFORMATION; | 87 return enable_level() >= TRACE_LEVEL_INFORMATION; |
| 68 } | 88 } |
| 69 | 89 |
| 90 // Exposed for unittesting only, allows resurrecting our |
| 91 // singleton instance post-AtExit processing. |
| 92 static void Resurrect(); |
| 93 |
| 94 private: |
| 95 // Ensure only the provider can construct us. |
| 96 friend struct StaticMemorySingletonTraits<TraceEventETWProvider>; |
| 97 TraceEventETWProvider(); |
| 98 |
| 70 // Emit a trace of type |type| containing |name|, |id|, and |extra|. | 99 // Emit a trace of type |type| containing |name|, |id|, and |extra|. |
| 71 // Note: |name| and |extra| must be NULL, or a zero-terminated string of | 100 // Note: |name| and |extra| must be NULL, or a zero-terminated string of |
| 72 // length |name_len| or |extra_len| respectively. | 101 // length |name_len| or |extra_len| respectively. |
| 73 // Note: if name_len or extra_len are -1, the length of the corresponding | 102 // The event format consists of: |
| 74 // string will be used. | 103 // The "name" string as a zero-terminated ASCII string. |
| 104 // The id pointer in the machine bitness. |
| 105 // The "extra" string as a zero-terminated ASCII string. |
| 106 // Optionally the stack trace, consisting of a DWORD "depth", followed |
| 107 // by an array of void* (machine bitness) of length "depth". |
| 75 void TraceEvent(const char* name, | 108 void TraceEvent(const char* name, |
| 76 size_t name_len, | 109 size_t name_len, |
| 77 char type, | 110 char type, |
| 78 const void* id, | 111 const void* id, |
| 79 const char* extra, | 112 const char* extra, |
| 80 size_t extra_len); | 113 size_t extra_len); |
| 81 | 114 |
| 82 // Exposed for unittesting only, allows resurrecting our | 115 // Emit a trace event. |
| 83 // singleton instance post-AtExit processing. | 116 // The event format consists of: |
| 84 static void Resurrect(); | 117 // The "name" as a zero-terminated ASCII string. |
| 85 | 118 // A 64 bits "id" to help identify related events. |
| 86 private: | 119 // The "category" as a zero-terminated ASCII string. |
| 87 // Ensure only the provider can construct us. | 120 // For each extra argument, a "name" followed by a "value", both |
| 88 friend struct StaticMemorySingletonTraits<TraceEventETWProvider>; | 121 // zero-terminated strings. |
| 89 TraceEventETWProvider(); | 122 // Optionally the stack trace, consisting of a DWORD "depth", followed |
| 123 // by an array of void* (machine bitness) of length "depth". |
| 124 void TraceEventWithArgs( |
| 125 const char* category_group, |
| 126 const char* name, |
| 127 char type, |
| 128 unsigned long long id, |
| 129 int num_args, |
| 130 const char** arg_names, |
| 131 const unsigned char* arg_types, |
| 132 const unsigned long long* arg_values, |
| 133 const scoped_refptr<ConvertableToTraceFormat>* convertable_values); |
| 90 | 134 |
| 91 DISALLOW_COPY_AND_ASSIGN(TraceEventETWProvider); | 135 DISALLOW_COPY_AND_ASSIGN(TraceEventETWProvider); |
| 92 }; | 136 }; |
| 93 | 137 |
| 94 // The ETW trace provider GUID. | 138 // The ETW trace provider GUID. |
| 95 BASE_EXPORT extern const GUID kChromeTraceProviderName; | 139 BASE_EXPORT extern const GUID kChromeTraceProviderName; |
| 96 | 140 |
| 97 // The ETW event class GUID for 32 bit events. | 141 // The ETW event class GUID for old events from TRACE_EVENT_*_ETW macros. |
| 98 BASE_EXPORT extern const GUID kTraceEventClass32; | 142 BASE_EXPORT extern const GUID kTraceEventClass32; |
| 99 | 143 |
| 100 // The ETW event class GUID for 64 bit events. | |
| 101 BASE_EXPORT extern const GUID kTraceEventClass64; | |
| 102 | |
| 103 // The ETW event types, IDs 0x00-0x09 are reserved, so start at 0x10. | 144 // The ETW event types, IDs 0x00-0x09 are reserved, so start at 0x10. |
| 104 const base::win::EtwEventType kTraceEventTypeBegin = 0x10; | 145 const base::win::EtwEventType kTraceEventTypeBegin = 0x10; |
| 105 const base::win::EtwEventType kTraceEventTypeEnd = 0x11; | 146 const base::win::EtwEventType kTraceEventTypeEnd = 0x11; |
| 106 const base::win::EtwEventType kTraceEventTypeInstant = 0x12; | 147 const base::win::EtwEventType kTraceEventTypeInstant = 0x12; |
| 107 | 148 |
| 108 // If this flag is set in enable flags | 149 // Enable flags that can be set for the trace session. |
| 109 enum TraceEventETWFlags { | 150 enum TraceEventETWFlags { |
| 151 // Include a stack trace for each event. |
| 110 CAPTURE_STACK_TRACE = 0x0001, | 152 CAPTURE_STACK_TRACE = 0x0001, |
| 153 |
| 154 // Include simple arguments with traced events. |
| 155 CAPTURE_SIMPLE_ARGUMENTS = 0x0002, |
| 156 |
| 157 // Include all arguments with traced events. Some arguments can be quite |
| 158 // large. Tracing them adds an overhead that can affect performance. |
| 159 CAPTURE_ALL_ARGUMENTS = 0x0004 |
| 111 }; | 160 }; |
| 112 | 161 |
| 113 // The event format consists of: | |
| 114 // The "name" string as a zero-terminated ASCII string. | |
| 115 // The id pointer in the machine bitness. | |
| 116 // The "extra" string as a zero-terminated ASCII string. | |
| 117 // Optionally the stack trace, consisting of a DWORD "depth", followed | |
| 118 // by an array of void* (machine bitness) of length "depth". | |
| 119 | |
| 120 } // namespace debug | 162 } // namespace debug |
| 121 } // namespace base | 163 } // namespace base |
| 122 | 164 |
| 123 #endif // BASE_DEBUG_TRACE_EVENT_WIN_H_ | 165 #endif // BASE_DEBUG_TRACE_EVENT_WIN_H_ |
| OLD | NEW |