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/win/event_trace_provider.h" | 13 #include "base/win/event_trace_provider.h" |
14 | 14 |
15 // Fwd. | 15 // Fwd. |
16 template <typename Type> | 16 template <typename Type> |
17 struct StaticMemorySingletonTraits; | 17 struct StaticMemorySingletonTraits; |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 namespace debug { | 20 namespace debug { |
21 | 21 |
22 // This EtwTraceProvider subclass implements ETW logging | 22 // This EtwTraceProvider subclass implements ETW logging |
23 // for the macros above on Windows. | 23 // for the macros above on Windows. |
24 class BASE_EXPORT TraceEventETWProvider : public base::win::EtwTraceProvider { | 24 class BASE_EXPORT TraceEventETWProvider : public base::win::EtwTraceProvider { |
25 public: | 25 public: |
| 26 static const size_t kUseStrlen = static_cast<size_t>(-1); |
| 27 |
26 // Start logging trace events. | 28 // Start logging trace events. |
27 // This is a noop in this implementation. | 29 // This is a noop in this implementation. |
28 static bool StartTracing(); | 30 static bool StartTracing(); |
29 | 31 |
30 // Trace begin/end/instant events, this is the bottleneck implementation | 32 // Trace begin/end/instant events, this is the bottleneck implementation |
31 // all the others defer to. | 33 // all the others defer to. |
32 // Allowing the use of std::string for name or extra is a convenience, | 34 // 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 | 35 // whereas passing name or extra as a const char* avoids the construction |
34 // of temporary std::string instances. | 36 // of temporary std::string instances. |
35 // If -1 is passed for name_len or extra_len, the strlen of the string will | 37 // If kUseStrlen is passed for name_len or extra_len, the strlen of the string |
36 // be used for length. | 38 // will be used for length. |
37 static void Trace(const char* name, | 39 static void Trace(const char* name, |
38 size_t name_len, | 40 size_t name_len, |
39 char type, | 41 char type, |
40 const void* id, | 42 const void* id, |
41 const char* extra, | 43 const char* extra, |
42 size_t extra_len); | 44 size_t extra_len); |
43 | 45 |
44 // Allows passing extra as a std::string for convenience. | 46 // Allows passing extra as a std::string for convenience. |
45 static void Trace(const char* name, | 47 static void Trace(const char* name, |
46 char type, | 48 char type, |
47 const void* id, | 49 const void* id, |
48 const std::string& extra) { | 50 const std::string& extra) { |
49 return Trace(name, -1, type, id, extra.c_str(), extra.length()); | 51 return Trace(name, kUseStrlen, type, id, extra.c_str(), extra.length()); |
50 } | 52 } |
51 | 53 |
52 // Allows passing extra as a const char* to avoid constructing temporary | 54 // Allows passing extra as a const char* to avoid constructing temporary |
53 // std::string instances where not needed. | 55 // std::string instances where not needed. |
54 static void Trace(const char* name, | 56 static void Trace(const char* name, |
55 char type, | 57 char type, |
56 const void* id, | 58 const void* id, |
57 const char* extra) { | 59 const char* extra) { |
58 return Trace(name, -1, type, id, extra, -1); | 60 return Trace(name, kUseStrlen, type, id, extra, kUseStrlen); |
59 } | 61 } |
60 | 62 |
61 // Retrieves the singleton. | 63 // Retrieves the singleton. |
62 // Note that this may return NULL post-AtExit processing. | 64 // Note that this may return NULL post-AtExit processing. |
63 static TraceEventETWProvider* GetInstance(); | 65 static TraceEventETWProvider* GetInstance(); |
64 | 66 |
65 // Returns true iff tracing is turned on. | 67 // Returns true iff tracing is turned on. |
66 bool IsTracing() { | 68 bool IsTracing() { |
67 return enable_level() >= TRACE_LEVEL_INFORMATION; | 69 return enable_level() >= TRACE_LEVEL_INFORMATION; |
68 } | 70 } |
69 | 71 |
70 // Emit a trace of type |type| containing |name|, |id|, and |extra|. | 72 // 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 | 73 // Note: |name| and |extra| must be NULL, or a zero-terminated string of |
72 // length |name_len| or |extra_len| respectively. | 74 // length |name_len| or |extra_len| respectively. |
73 // Note: if name_len or extra_len are -1, the length of the corresponding | 75 // Note: if name_len or extra_len are kUseStrlen, the length of the |
74 // string will be used. | 76 // corresponding string will be used. |
75 void TraceEvent(const char* name, | 77 void TraceEvent(const char* name, |
76 size_t name_len, | 78 size_t name_len, |
77 char type, | 79 char type, |
78 const void* id, | 80 const void* id, |
79 const char* extra, | 81 const char* extra, |
80 size_t extra_len); | 82 size_t extra_len); |
81 | 83 |
82 // Exposed for unittesting only, allows resurrecting our | 84 // Exposed for unittesting only, allows resurrecting our |
83 // singleton instance post-AtExit processing. | 85 // singleton instance post-AtExit processing. |
84 static void Resurrect(); | 86 static void Resurrect(); |
(...skipping 29 matching lines...) Expand all Loading... |
114 // The "name" string as a zero-terminated ASCII string. | 116 // The "name" string as a zero-terminated ASCII string. |
115 // The id pointer in the machine bitness. | 117 // The id pointer in the machine bitness. |
116 // The "extra" string as a zero-terminated ASCII string. | 118 // The "extra" string as a zero-terminated ASCII string. |
117 // Optionally the stack trace, consisting of a DWORD "depth", followed | 119 // Optionally the stack trace, consisting of a DWORD "depth", followed |
118 // by an array of void* (machine bitness) of length "depth". | 120 // by an array of void* (machine bitness) of length "depth". |
119 | 121 |
120 } // namespace debug | 122 } // namespace debug |
121 } // namespace base | 123 } // namespace base |
122 | 124 |
123 #endif // BASE_DEBUG_TRACE_EVENT_WIN_H_ | 125 #endif // BASE_DEBUG_TRACE_EVENT_WIN_H_ |
OLD | NEW |