OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 8 #pragma once |
9 | 9 |
10 #include <string> | 10 #include <string> |
| 11 #include "base/debug/trace_event.h" |
11 #include "base/win/event_trace_provider.h" | 12 #include "base/win/event_trace_provider.h" |
12 | 13 |
13 #define TRACE_EVENT_BEGIN(name, id, extra) \ | |
14 base::debug::TraceLog::Trace( \ | |
15 name, \ | |
16 base::debug::TraceLog::EVENT_BEGIN, \ | |
17 reinterpret_cast<const void*>(id), \ | |
18 extra); | |
19 | |
20 #define TRACE_EVENT_END(name, id, extra) \ | |
21 base::debug::TraceLog::Trace( \ | |
22 name, \ | |
23 base::debug::TraceLog::EVENT_END, \ | |
24 reinterpret_cast<const void*>(id), \ | |
25 extra); | |
26 | |
27 #define TRACE_EVENT_INSTANT(name, id, extra) \ | |
28 base::debug::TraceLog::Trace( \ | |
29 name, \ | |
30 base::debug::TraceLog::EVENT_INSTANT, \ | |
31 reinterpret_cast<const void*>(id), \ | |
32 extra); | |
33 | |
34 // Fwd. | 14 // Fwd. |
35 template <typename Type> | 15 template <typename Type> |
36 struct StaticMemorySingletonTraits; | 16 struct StaticMemorySingletonTraits; |
37 | 17 |
38 namespace base { | 18 namespace base { |
39 namespace debug { | 19 namespace debug { |
40 | 20 |
41 // This EtwTraceProvider subclass implements ETW logging | 21 // This EtwTraceProvider subclass implements ETW logging |
42 // for the macros above on Windows. | 22 // for the macros above on Windows. |
43 class TraceLog : public base::win::EtwTraceProvider { | 23 class TraceEventETWProvider : public base::win::EtwTraceProvider { |
44 public: | 24 public: |
45 enum EventType { | |
46 EVENT_BEGIN, | |
47 EVENT_END, | |
48 EVENT_INSTANT | |
49 }; | |
50 | |
51 // Start logging trace events. | 25 // Start logging trace events. |
52 // This is a noop in this implementation. | 26 // This is a noop in this implementation. |
53 static bool StartTracing(); | 27 static bool StartTracing(); |
54 | 28 |
55 // Trace begin/end/instant events, this is the bottleneck implementation | 29 // Trace begin/end/instant events, this is the bottleneck implementation |
56 // all the others defer to. | 30 // all the others defer to. |
57 // Allowing the use of std::string for name or extra is a convenience, | 31 // Allowing the use of std::string for name or extra is a convenience, |
58 // whereas passing name or extra as a const char* avoids the construction | 32 // whereas passing name or extra as a const char* avoids the construction |
59 // of temporary std::string instances. | 33 // of temporary std::string instances. |
60 // If -1 is passed for name_len or extra_len, the strlen of the string will | 34 // If -1 is passed for name_len or extra_len, the strlen of the string will |
61 // be used for length. | 35 // be used for length. |
62 static void Trace(const char* name, | 36 static void Trace(const char* name, |
63 size_t name_len, | 37 size_t name_len, |
64 EventType type, | 38 TraceEventPhase type, |
65 const void* id, | 39 const void* id, |
66 const char* extra, | 40 const char* extra, |
67 size_t extra_len); | 41 size_t extra_len); |
68 | 42 |
69 // Allows passing extra as a std::string for convenience. | 43 // Allows passing extra as a std::string for convenience. |
70 static void Trace(const char* name, | 44 static void Trace(const char* name, |
71 EventType type, | 45 TraceEventPhase type, |
72 const void* id, | 46 const void* id, |
73 const std::string& extra) { | 47 const std::string& extra) { |
74 return Trace(name, -1, type, id, extra.c_str(), extra.length()); | 48 return Trace(name, -1, type, id, extra.c_str(), extra.length()); |
75 } | 49 } |
76 | 50 |
77 // Allows passing extra as a const char* to avoid constructing temporary | 51 // Allows passing extra as a const char* to avoid constructing temporary |
78 // std::string instances where not needed. | 52 // std::string instances where not needed. |
79 static void Trace(const char* name, | 53 static void Trace(const char* name, |
80 EventType type, | 54 TraceEventPhase type, |
81 const void* id, | 55 const void* id, |
82 const char* extra) { | 56 const char* extra) { |
83 return Trace(name, -1, type, id, extra, -1); | 57 return Trace(name, -1, type, id, extra, -1); |
84 } | 58 } |
85 | 59 |
86 // Retrieves the singleton. | 60 // Retrieves the singleton. |
87 // Note that this may return NULL post-AtExit processing. | 61 // Note that this may return NULL post-AtExit processing. |
88 static TraceLog* GetInstance(); | 62 static TraceEventETWProvider* GetInstance(); |
89 | 63 |
90 // Returns true iff tracing is turned on. | 64 // Returns true iff tracing is turned on. |
91 bool IsTracing() { | 65 bool IsTracing() { |
92 return enable_level() >= TRACE_LEVEL_INFORMATION; | 66 return enable_level() >= TRACE_LEVEL_INFORMATION; |
93 } | 67 } |
94 | 68 |
95 // Emit a trace of type |type| containing |name|, |id|, and |extra|. | 69 // Emit a trace of type |type| containing |name|, |id|, and |extra|. |
96 // Note: |name| and |extra| must be NULL, or a zero-terminated string of | 70 // Note: |name| and |extra| must be NULL, or a zero-terminated string of |
97 // length |name_len| or |extra_len| respectively. | 71 // length |name_len| or |extra_len| respectively. |
98 // Note: if name_len or extra_len are -1, the length of the corresponding | 72 // Note: if name_len or extra_len are -1, the length of the corresponding |
99 // string will be used. | 73 // string will be used. |
100 void TraceEvent(const char* name, | 74 void TraceEvent(const char* name, |
101 size_t name_len, | 75 size_t name_len, |
102 EventType type, | 76 TraceEventPhase type, |
103 const void* id, | 77 const void* id, |
104 const char* extra, | 78 const char* extra, |
105 size_t extra_len); | 79 size_t extra_len); |
106 | 80 |
107 // Exposed for unittesting only, allows resurrecting our | 81 // Exposed for unittesting only, allows resurrecting our |
108 // singleton instance post-AtExit processing. | 82 // singleton instance post-AtExit processing. |
109 static void Resurrect(); | 83 static void Resurrect(); |
110 | 84 |
111 private: | 85 private: |
112 // Ensure only the provider can construct us. | 86 // Ensure only the provider can construct us. |
113 friend struct StaticMemorySingletonTraits<TraceLog>; | 87 friend struct StaticMemorySingletonTraits<TraceEventETWProvider>; |
114 TraceLog(); | 88 TraceEventETWProvider(); |
115 | 89 |
116 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 90 DISALLOW_COPY_AND_ASSIGN(TraceEventETWProvider); |
117 }; | 91 }; |
118 | 92 |
119 // The ETW trace provider GUID. | 93 // The ETW trace provider GUID. |
120 extern const GUID kChromeTraceProviderName; | 94 extern const GUID kChromeTraceProviderName; |
121 | 95 |
122 // The ETW event class GUID for 32 bit events. | 96 // The ETW event class GUID for 32 bit events. |
123 extern const GUID kTraceEventClass32; | 97 extern const GUID kTraceEventClass32; |
124 | 98 |
125 // The ETW event class GUID for 64 bit events. | 99 // The ETW event class GUID for 64 bit events. |
126 extern const GUID kTraceEventClass64; | 100 extern const GUID kTraceEventClass64; |
(...skipping 15 matching lines...) Expand all Loading... |
142 // Optionally the stack trace, consisting of a DWORD "depth", followed | 116 // Optionally the stack trace, consisting of a DWORD "depth", followed |
143 // by an array of void* (machine bitness) of length "depth". | 117 // by an array of void* (machine bitness) of length "depth". |
144 | 118 |
145 // Forward decl. | 119 // Forward decl. |
146 struct TraceLogSingletonTraits; | 120 struct TraceLogSingletonTraits; |
147 | 121 |
148 } // nemspace debug | 122 } // nemspace debug |
149 } // namespace base | 123 } // namespace base |
150 | 124 |
151 #endif // BASE_DEBUG_TRACE_EVENT_WIN_H_ | 125 #endif // BASE_DEBUG_TRACE_EVENT_WIN_H_ |
OLD | NEW |