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
3 // found in the LICENSE file.
5 // This file contains the Windows-specific declarations for trace_event.h.
6 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_WIN_H_
7 #define BASE_TRACE_EVENT_TRACE_EVENT_WIN_H_
11 #include "base/base_export.h"
12 #include "base/trace_event/trace_event.h"
13 #include "base/win/event_trace_provider.h"
16 template <typename Type
>
17 struct StaticMemorySingletonTraits
;
20 namespace trace_event
{
22 // This EtwTraceProvider subclass implements ETW logging
23 // for the macros above on Windows.
24 class BASE_EXPORT TraceEventETWProvider
: public base::win::EtwTraceProvider
{
26 static const size_t kUseStrlen
= static_cast<size_t>(-1);
28 // Start logging trace events.
29 // This is a noop in this implementation.
30 static bool StartTracing();
32 // Trace begin/end/instant events, this is the bottleneck implementation
33 // all the others defer to.
34 // Allowing the use of std::string for name or extra is a convenience,
35 // whereas passing name or extra as a const char* avoids the construction
36 // of temporary std::string instances.
37 // If kUseStrlen is passed for name_len or extra_len, the strlen of the string
38 // will be used for length.
39 static void Trace(const char* name
,
46 // Allows passing extra as a std::string for convenience.
47 static void Trace(const char* name
,
50 const std::string
& extra
) {
51 return Trace(name
, kUseStrlen
, type
, id
, extra
.c_str(), extra
.length());
54 // Allows passing extra as a const char* to avoid constructing temporary
55 // std::string instances where not needed.
56 static void Trace(const char* name
,
60 return Trace(name
, kUseStrlen
, type
, id
, extra
, kUseStrlen
);
63 // Retrieves the singleton.
64 // Note that this may return NULL post-AtExit processing.
65 static TraceEventETWProvider
* GetInstance();
67 // Returns true iff tracing is turned on.
69 return enable_level() >= TRACE_LEVEL_INFORMATION
;
72 // Emit a trace of type |type| containing |name|, |id|, and |extra|.
73 // Note: |name| and |extra| must be NULL, or a zero-terminated string of
74 // length |name_len| or |extra_len| respectively.
75 // Note: if name_len or extra_len are kUseStrlen, the length of the
76 // corresponding string will be used.
77 void TraceEvent(const char* name
,
84 // Exposed for unittesting only, allows resurrecting our
85 // singleton instance post-AtExit processing.
86 static void Resurrect();
89 // Ensure only the provider can construct us.
90 friend struct StaticMemorySingletonTraits
<TraceEventETWProvider
>;
91 TraceEventETWProvider();
93 DISALLOW_COPY_AND_ASSIGN(TraceEventETWProvider
);
96 // The ETW trace provider GUID.
97 BASE_EXPORT
extern const GUID kChromeTraceProviderName
;
99 // The ETW event class GUID for 32 bit events.
100 BASE_EXPORT
extern const GUID kTraceEventClass32
;
102 // The ETW event class GUID for 64 bit events.
103 BASE_EXPORT
extern const GUID kTraceEventClass64
;
105 // The ETW event types, IDs 0x00-0x09 are reserved, so start at 0x10.
106 const base::win::EtwEventType kTraceEventTypeBegin
= 0x10;
107 const base::win::EtwEventType kTraceEventTypeEnd
= 0x11;
108 const base::win::EtwEventType kTraceEventTypeInstant
= 0x12;
110 // If this flag is set in enable flags
111 enum TraceEventETWFlags
{
112 CAPTURE_STACK_TRACE
= 0x0001,
115 // The event format consists of:
116 // The "name" string as a zero-terminated ASCII string.
117 // The id pointer in the machine bitness.
118 // The "extra" string as a zero-terminated ASCII string.
119 // Optionally the stack trace, consisting of a DWORD "depth", followed
120 // by an array of void* (machine bitness) of length "depth".
122 } // namespace trace_event
125 #endif // BASE_TRACE_EVENT_TRACE_EVENT_WIN_H_