This source file includes following definitions.
- GetInstance
- StartTracing
- Resurrect
#include "base/debug/trace_event_win.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
#include <initguid.h>
namespace base {
namespace debug {
using base::win::EtwEventType;
using base::win::EtwMofEvent;
const GUID kChromeTraceProviderName = {
0x3dada31d, 0x19ef, 0x4dc1, 0xb3, 0x45, 0x3, 0x79, 0x27, 0x19, 0x34, 0x22 };
const GUID kTraceEventClass32 = {
0xb967ae67, 0xbb22, 0x49d7, 0x94, 0x6, 0x55, 0xd9, 0x1e, 0xe1, 0xd5, 0x60 };
const GUID kTraceEventClass64 = {
0x97be602d, 0x2930, 0x4ac3, 0x80, 0x46, 0xb6, 0x76, 0x3b, 0x63, 0x1d, 0xfe};
TraceEventETWProvider::TraceEventETWProvider() :
EtwTraceProvider(kChromeTraceProviderName) {
Register();
}
TraceEventETWProvider* TraceEventETWProvider::GetInstance() {
return Singleton<TraceEventETWProvider,
StaticMemorySingletonTraits<TraceEventETWProvider> >::get();
}
bool TraceEventETWProvider::StartTracing() {
return true;
}
void TraceEventETWProvider::TraceEvent(const char* name,
size_t name_len,
char type,
const void* id,
const char* extra,
size_t extra_len) {
if (name == NULL)
name = "";
if (extra == NULL)
extra = "";
EtwEventType etw_type = 0;
switch (type) {
case TRACE_EVENT_PHASE_BEGIN:
etw_type = kTraceEventTypeBegin;
break;
case TRACE_EVENT_PHASE_END:
etw_type = kTraceEventTypeEnd;
break;
case TRACE_EVENT_PHASE_INSTANT:
etw_type = kTraceEventTypeInstant;
break;
default:
NOTREACHED() << "Unknown event type";
etw_type = kTraceEventTypeInstant;
break;
}
EtwMofEvent<5> event(kTraceEventClass32,
etw_type,
TRACE_LEVEL_INFORMATION);
event.SetField(0, name_len + 1, name);
event.SetField(1, sizeof(id), &id);
event.SetField(2, extra_len + 1, extra);
DWORD depth;
void* backtrace[32];
if (enable_flags() & CAPTURE_STACK_TRACE) {
depth = CaptureStackBackTrace(0,
arraysize(backtrace),
backtrace,
NULL);
event.SetField(3, sizeof(depth), &depth);
event.SetField(4, sizeof(backtrace[0]) * depth, backtrace);
}
Log(event.get());
}
void TraceEventETWProvider::Trace(const char* name,
size_t name_len,
char type,
const void* id,
const char* extra,
size_t extra_len) {
TraceEventETWProvider* provider = TraceEventETWProvider::GetInstance();
if (provider && provider->IsTracing()) {
if (name_len == -1)
name_len = (name == NULL) ? 0 : strlen(name);
if (extra_len == -1)
extra_len = (extra == NULL) ? 0 : strlen(extra);
provider->TraceEvent(name, name_len, type, id, extra, extra_len);
}
}
void TraceEventETWProvider::Resurrect() {
StaticMemorySingletonTraits<TraceEventETWProvider>::Resurrect();
}
}
}