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

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

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

Powered by Google App Engine
This is Rietveld 408576698