| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 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_ | |
| 8 #pragma once | |
| 9 | |
| 10 #include <string> | |
| 11 #include "base/event_trace_provider_win.h" | |
| 12 | |
| 13 #define TRACE_EVENT_BEGIN(name, id, extra) \ | |
| 14 base::TraceLog::Trace(name, \ | |
| 15 base::TraceLog::EVENT_BEGIN, \ | |
| 16 reinterpret_cast<const void*>(id), \ | |
| 17 extra); | |
| 18 | |
| 19 #define TRACE_EVENT_END(name, id, extra) \ | |
| 20 base::TraceLog::Trace(name, \ | |
| 21 base::TraceLog::EVENT_END, \ | |
| 22 reinterpret_cast<const void*>(id), \ | |
| 23 extra); | |
| 24 | |
| 25 #define TRACE_EVENT_INSTANT(name, id, extra) \ | |
| 26 base::TraceLog::Trace(name, \ | |
| 27 base::TraceLog::EVENT_INSTANT, \ | |
| 28 reinterpret_cast<const void*>(id), \ | |
| 29 extra); | |
| 30 | |
| 31 // Fwd. | |
| 32 template <typename Type> | |
| 33 struct StaticMemorySingletonTraits; | |
| 34 | |
| 35 namespace base { | |
| 36 | |
| 37 // This EtwTraceProvider subclass implements ETW logging | |
| 38 // for the macros above on Windows. | |
| 39 class TraceLog : public EtwTraceProvider { | |
| 40 public: | |
| 41 enum EventType { | |
| 42 EVENT_BEGIN, | |
| 43 EVENT_END, | |
| 44 EVENT_INSTANT | |
| 45 }; | |
| 46 | |
| 47 // Start logging trace events. | |
| 48 // This is a noop in this implementation. | |
| 49 static bool StartTracing(); | |
| 50 | |
| 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, | |
| 59 size_t name_len, | |
| 60 EventType type, | |
| 61 const void* id, | |
| 62 const char* extra, | |
| 63 size_t extra_len); | |
| 64 | |
| 65 // Allows passing extra as a std::string for convenience. | |
| 66 static void Trace(const char* name, | |
| 67 EventType type, | |
| 68 const void* id, | |
| 69 const std::string& extra) { | |
| 70 return Trace(name, -1, type, id, extra.c_str(), extra.length()); | |
| 71 } | |
| 72 | |
| 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, | |
| 76 EventType type, | |
| 77 const void* id, | |
| 78 const char* extra) { | |
| 79 return Trace(name, -1, type, id, extra, -1); | |
| 80 } | |
| 81 | |
| 82 // Retrieves the singleton. | |
| 83 // Note that this may return NULL post-AtExit processing. | |
| 84 static TraceLog* Get(); | |
| 85 | |
| 86 // Returns true iff tracing is turned on. | |
| 87 bool IsTracing() { | |
| 88 return enable_level() >= TRACE_LEVEL_INFORMATION; | |
| 89 } | |
| 90 | |
| 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, | |
| 97 size_t name_len, | |
| 98 base::TraceLog::EventType type, | |
| 99 const void* id, | |
| 100 const char* extra, | |
| 101 size_t extra_len); | |
| 102 | |
| 103 // Exposed for unittesting only, allows resurrecting our | |
| 104 // singleton instance post-AtExit processing. | |
| 105 static void Resurrect(); | |
| 106 | |
| 107 private: | |
| 108 // Ensure only the provider can construct us. | |
| 109 friend struct StaticMemorySingletonTraits<TraceLog>; | |
| 110 TraceLog(); | |
| 111 | |
| 112 DISALLOW_COPY_AND_ASSIGN(TraceLog); | |
| 113 }; | |
| 114 | |
| 115 // The ETW trace provider GUID. | |
| 116 extern const GUID kChromeTraceProviderName; | |
| 117 | |
| 118 // The ETW event class GUID for 32 bit events. | |
| 119 extern const GUID kTraceEventClass32; | |
| 120 | |
| 121 // The ETW event class GUID for 64 bit events. | |
| 122 extern const GUID kTraceEventClass64; | |
| 123 | |
| 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; | |
| 128 | |
| 129 // If this flag is set in enable flags | |
| 130 enum TraceEventFlags { | |
| 131 CAPTURE_STACK_TRACE = 0x0001, | |
| 132 }; | |
| 133 | |
| 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". | |
| 140 | |
| 141 // Forward decl. | |
| 142 struct TraceLogSingletonTraits; | |
| 143 | |
| 144 } // namespace base | |
| 145 | |
| 146 #endif // BASE_TRACE_EVENT_WIN_H_ | |
| OLD | NEW |