Revert of Revert of Roll src/third_party/skia 8bcc7a0:724ae28 (patchset #1 id:1 of...
[chromium-blink-merge.git] / base / trace_event / trace_event_win.h
blob416136155490f9fd94971b90b0ca4ead8492a69c
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_
9 #include <string>
11 #include "base/base_export.h"
12 #include "base/trace_event/trace_event.h"
13 #include "base/win/event_trace_provider.h"
15 // Fwd.
16 template <typename Type>
17 struct StaticMemorySingletonTraits;
19 namespace base {
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 {
25 public:
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,
40 size_t name_len,
41 char type,
42 const void* id,
43 const char* extra,
44 size_t extra_len);
46 // Allows passing extra as a std::string for convenience.
47 static void Trace(const char* name,
48 char type,
49 const void* id,
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,
57 char type,
58 const void* id,
59 const char* extra) {
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.
68 bool IsTracing() {
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,
78 size_t name_len,
79 char type,
80 const void* id,
81 const char* extra,
82 size_t extra_len);
84 // Exposed for unittesting only, allows resurrecting our
85 // singleton instance post-AtExit processing.
86 static void Resurrect();
88 private:
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
123 } // namespace base
125 #endif // BASE_TRACE_EVENT_TRACE_EVENT_WIN_H_