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