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

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

Issue 23934003: Have all trace points emit to ETW. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Chris' comments Created 7 years, 3 months 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
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 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/scoped_ptr.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
36 // be used for length.
37 static void Trace(const char* name, 35 static void Trace(const char* name,
38 size_t name_len,
39 char type, 36 char type,
40 const void* id, 37 const void* id,
41 const char* extra, 38 const char* extra);
42 size_t extra_len);
43 39
44 // Allows passing extra as a std::string for convenience. 40 // Allows passing extra as a std::string for convenience.
45 static void Trace(const char* name, 41 static void Trace(const char* name,
46 char type, 42 char type,
47 const void* id, 43 const void* id,
48 const std::string& extra) { 44 const std::string& extra) {
49 return Trace(name, -1, type, id, extra.c_str(), extra.length()); 45 return Trace(name, type, id, extra.c_str());
50 } 46 }
51 47
52 // Allows passing extra as a const char* to avoid constructing temporary 48 // Emit a trace event.
53 // std::string instances where not needed. 49 // The event is defined by |category_group|, |name| and |type|.
54 static void Trace(const char* name, 50 // |id| helps to identify related events.
55 char type, 51 // |thread_name| is the name of the thread that produced the event.
56 const void* id, 52 // |num_args| indicates the number of custom arguments to add to the trace.
57 const char* extra) { 53 // It must be <= |kTraceMaxNumArgs|. The names of the arguments are specified
58 return Trace(name, -1, type, id, extra, -1); 54 // in |arg_names|. |arg_types| indicates how to interpret the value of
59 } 55 // each argument. Finally, the value of an argument is obtained from
56 // |convertable_values| if its type is TRACE_VALUE_TYPE_CONVERTABLE,
57 // from |arg_values| otherwise.
58 static void TraceWithArgs(
59 const char* category_group,
60 const char* name,
61 char type,
62 unsigned long long id,
63 const std::string& thread_name,
64 int num_args,
65 const char** arg_names,
66 const unsigned char* arg_types,
67 const unsigned long long* arg_values,
68 scoped_ptr<ConvertableToTraceFormat> convertable_values[]);
60 69
61 // Retrieves the singleton. 70 // Retrieves the singleton.
62 // Note that this may return NULL post-AtExit processing. 71 // Note that this may return NULL post-AtExit processing.
63 static TraceEventETWProvider* GetInstance(); 72 static TraceEventETWProvider* GetInstance();
64 73
65 // Returns true iff tracing is turned on. 74 // Returns true iff tracing is turned on.
66 bool IsTracing() { 75 bool IsTracing() {
67 return enable_level() >= TRACE_LEVEL_INFORMATION; 76 return enable_level() >= TRACE_LEVEL_INFORMATION;
68 } 77 }
69 78
70 // 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
72 // length |name_len| or |extra_len| respectively.
73 // Note: if name_len or extra_len are -1, the length of the corresponding
74 // string will be used.
75 void TraceEvent(const char* name,
76 size_t name_len,
77 char type,
78 const void* id,
79 const char* extra,
80 size_t extra_len);
81
82 // Exposed for unittesting only, allows resurrecting our 79 // Exposed for unittesting only, allows resurrecting our
83 // singleton instance post-AtExit processing. 80 // singleton instance post-AtExit processing.
84 static void Resurrect(); 81 static void Resurrect();
85 82
86 private: 83 private:
87 // Ensure only the provider can construct us. 84 // Ensure only the provider can construct us.
88 friend struct StaticMemorySingletonTraits<TraceEventETWProvider>; 85 friend struct StaticMemorySingletonTraits<TraceEventETWProvider>;
89 TraceEventETWProvider(); 86 TraceEventETWProvider();
90 87
88 // Emit a trace event.
Sigurður Ásgeirsson 2013/09/10 21:15:54 If you're defining a message format that's incompa
fdoray 2013/09/16 00:51:03 Done.
89 // It's possible to add up to |kTraceMaxNumArgs| custom arguments to
90 // the trace. |arg_values| and |arg_names| are arrays of |num_args| strings
91 // that indicate the names and values of the custom arguments.
92 // The payload of the produced trace follows this format:
93 // - Name (string)
94 // - Id (unsigned long long)
95 // - Category (string)
96 // - Thread name (string)
97 // - Name of parameter 1, or '\0' (string)
98 // - Value of parameter 1, or '\0' (string)
99 // - Name of parameter 2, or '\0' (string)
100 // - Value of parameter 2, or '\0' (string)
101 // If stack capture is enabled for the trace session:
Sigurður Ásgeirsson 2013/09/10 21:15:54 It's not clear to me that this message format can
fdoray 2013/09/16 00:51:03 The new format can be parsed using this schema: ht
102 // - Stack size (DWORD)
103 // - Stack pointers (stack size * void*)
104 // Strings are null-terminated and have a variable size.
105 //
106 // Note: |name| and |category_group| must be NULL, or a zero-terminated
107 // string. The length of |name| must be specified by |name_len|.
108 void TraceEvent(const char* category_group,
109 const char* name,
110 char type,
111 unsigned long long id,
112 const std::string& thread_name,
113 int num_args,
114 const char** arg_names,
115 std::string* arg_values);
116
91 DISALLOW_COPY_AND_ASSIGN(TraceEventETWProvider); 117 DISALLOW_COPY_AND_ASSIGN(TraceEventETWProvider);
92 }; 118 };
93 119
94 // The ETW trace provider GUID. 120 // The ETW trace provider GUID.
95 BASE_EXPORT extern const GUID kChromeTraceProviderName; 121 BASE_EXPORT extern const GUID kChromeTraceProviderName;
96 122
97 // The ETW event class GUID for 32 bit events. 123 // The ETW event class GUID for 32 bit events.
98 BASE_EXPORT extern const GUID kTraceEventClass32; 124 BASE_EXPORT extern const GUID kTraceEventClass32;
99 125
100 // The ETW event class GUID for 64 bit events. 126 // The ETW event class GUID for 64 bit events.
(...skipping 13 matching lines...) Expand all
114 // The "name" string as a zero-terminated ASCII string. 140 // The "name" string as a zero-terminated ASCII string.
115 // The id pointer in the machine bitness. 141 // The id pointer in the machine bitness.
116 // The "extra" string as a zero-terminated ASCII string. 142 // The "extra" string as a zero-terminated ASCII string.
117 // Optionally the stack trace, consisting of a DWORD "depth", followed 143 // Optionally the stack trace, consisting of a DWORD "depth", followed
118 // by an array of void* (machine bitness) of length "depth". 144 // by an array of void* (machine bitness) of length "depth".
119 145
120 } // namespace debug 146 } // namespace debug
121 } // namespace base 147 } // namespace base
122 148
123 #endif // BASE_DEBUG_TRACE_EVENT_WIN_H_ 149 #endif // BASE_DEBUG_TRACE_EVENT_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698