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
3 // found in the LICENSE file.
5 // This file contains the Windows-specific declarations for trace_event.h.
6 #ifndef BASE_TRACE_EVENT_WIN_H_
7 #define BASE_TRACE_EVENT_WIN_H_
11 #include "base/event_trace_provider_win.h"
13 #define TRACE_EVENT_BEGIN(name, id, extra) \
14 base::TraceLog::Trace(name, \
15 base::TraceLog::EVENT_BEGIN, \
16 reinterpret_cast<const void*>(id), \
19 #define TRACE_EVENT_END(name, id, extra) \
20 base::TraceLog::Trace(name, \
21 base::TraceLog::EVENT_END, \
22 reinterpret_cast<const void*>(id), \
25 #define TRACE_EVENT_INSTANT(name, id, extra) \
26 base::TraceLog::Trace(name, \
27 base::TraceLog::EVENT_INSTANT, \
28 reinterpret_cast<const void*>(id), \
32 template <typename Type
>
33 struct StaticMemorySingletonTraits
;
37 // This EtwTraceProvider subclass implements ETW logging
38 // for the macros above on Windows.
39 class TraceLog
: public EtwTraceProvider
{
47 // Start logging trace events.
48 // This is a noop in this implementation.
49 static bool StartTracing();
51 // Trace begin/end/instant events, this is the bottleneck implementation
52 // all the others defer to.
53 // Allowing the use of std::string for name or extra is a convenience,
54 // whereas passing name or extra as a const char* avoids the construction
55 // of temporary std::string instances.
56 // If -1 is passed for name_len or extra_len, the strlen of the string will
57 // be used for length.
58 static void Trace(const char* name
,
65 // Allows passing extra as a std::string for convenience.
66 static void Trace(const char* name
,
69 const std::string
& extra
) {
70 return Trace(name
, -1, type
, id
, extra
.c_str(), extra
.length());
73 // Allows passing extra as a const char* to avoid constructing temporary
74 // std::string instances where not needed.
75 static void Trace(const char* name
,
79 return Trace(name
, -1, type
, id
, extra
, -1);
82 // Retrieves the singleton.
83 // Note that this may return NULL post-AtExit processing.
84 static TraceLog
* Get();
86 // Returns true iff tracing is turned on.
88 return enable_level() >= TRACE_LEVEL_INFORMATION
;
91 // Emit a trace of type |type| containing |name|, |id|, and |extra|.
92 // Note: |name| and |extra| must be NULL, or a zero-terminated string of
93 // length |name_len| or |extra_len| respectively.
94 // Note: if name_len or extra_len are -1, the length of the corresponding
95 // string will be used.
96 void TraceEvent(const char* name
,
98 base::TraceLog::EventType type
,
103 // Exposed for unittesting only, allows resurrecting our
104 // singleton instance post-AtExit processing.
105 static void Resurrect();
108 // Ensure only the provider can construct us.
109 friend struct StaticMemorySingletonTraits
<TraceLog
>;
112 DISALLOW_COPY_AND_ASSIGN(TraceLog
);
115 // The ETW trace provider GUID.
116 extern const GUID kChromeTraceProviderName
;
118 // The ETW event class GUID for 32 bit events.
119 extern const GUID kTraceEventClass32
;
121 // The ETW event class GUID for 64 bit events.
122 extern const GUID kTraceEventClass64
;
124 // The ETW event types, IDs 0x00-0x09 are reserved, so start at 0x10.
125 const EtwEventType kTraceEventTypeBegin
= 0x10;
126 const EtwEventType kTraceEventTypeEnd
= 0x11;
127 const EtwEventType kTraceEventTypeInstant
= 0x12;
129 // If this flag is set in enable flags
130 enum TraceEventFlags
{
131 CAPTURE_STACK_TRACE
= 0x0001,
134 // The event format consists of:
135 // The "name" string as a zero-terminated ASCII string.
136 // The id pointer in the machine bitness.
137 // The "extra" string as a zero-terminated ASCII string.
138 // Optionally the stack trace, consisting of a DWORD "depth", followed
139 // by an array of void* (machine bitness) of length "depth".
142 struct TraceLogSingletonTraits
;
146 #endif // BASE_TRACE_EVENT_WIN_H_