Hide Google logo and custom launcher page in app list for non-Google search engines.
[chromium-blink-merge.git] / base / trace_event / trace_event_win.cc
blobebb55c844923daf84b80472cd53a6bffaff7c599
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 #include "base/trace_event/trace_event_win.h"
7 #include "base/logging.h"
8 #include "base/memory/singleton.h"
9 #include <initguid.h> // NOLINT
11 namespace base {
12 namespace trace_event {
14 using base::win::EtwEventType;
15 using base::win::EtwMofEvent;
17 // {3DADA31D-19EF-4dc1-B345-037927193422}
18 const GUID kChromeTraceProviderName = {
19 0x3dada31d, 0x19ef, 0x4dc1, 0xb3, 0x45, 0x3, 0x79, 0x27, 0x19, 0x34, 0x22 };
21 // {B967AE67-BB22-49d7-9406-55D91EE1D560}
22 const GUID kTraceEventClass32 = {
23 0xb967ae67, 0xbb22, 0x49d7, 0x94, 0x6, 0x55, 0xd9, 0x1e, 0xe1, 0xd5, 0x60 };
25 // {97BE602D-2930-4ac3-8046-B6763B631DFE}
26 const GUID kTraceEventClass64 = {
27 0x97be602d, 0x2930, 0x4ac3, 0x80, 0x46, 0xb6, 0x76, 0x3b, 0x63, 0x1d, 0xfe};
30 TraceEventETWProvider::TraceEventETWProvider() :
31 EtwTraceProvider(kChromeTraceProviderName) {
32 Register();
35 TraceEventETWProvider* TraceEventETWProvider::GetInstance() {
36 return Singleton<TraceEventETWProvider,
37 StaticMemorySingletonTraits<TraceEventETWProvider> >::get();
40 bool TraceEventETWProvider::StartTracing() {
41 return true;
44 void TraceEventETWProvider::TraceEvent(const char* name,
45 size_t name_len,
46 char type,
47 const void* id,
48 const char* extra,
49 size_t extra_len) {
50 // Make sure we don't touch NULL.
51 if (name == NULL)
52 name = "";
53 if (extra == NULL)
54 extra = "";
56 EtwEventType etw_type = 0;
57 switch (type) {
58 case TRACE_EVENT_PHASE_BEGIN:
59 etw_type = kTraceEventTypeBegin;
60 break;
61 case TRACE_EVENT_PHASE_END:
62 etw_type = kTraceEventTypeEnd;
63 break;
65 case TRACE_EVENT_PHASE_INSTANT:
66 etw_type = kTraceEventTypeInstant;
67 break;
69 default:
70 NOTREACHED() << "Unknown event type";
71 etw_type = kTraceEventTypeInstant;
72 break;
75 EtwMofEvent<5> event(kTraceEventClass32,
76 etw_type,
77 TRACE_LEVEL_INFORMATION);
78 event.SetField(0, name_len + 1, name);
79 event.SetField(1, sizeof(id), &id);
80 event.SetField(2, extra_len + 1, extra);
82 // These variables are declared here so that they are not out of scope when
83 // the event is logged.
84 DWORD depth;
85 void* backtrace[32];
87 // See whether we're to capture a backtrace.
88 if (enable_flags() & CAPTURE_STACK_TRACE) {
89 depth = CaptureStackBackTrace(0,
90 arraysize(backtrace),
91 backtrace,
92 NULL);
93 event.SetField(3, sizeof(depth), &depth);
94 event.SetField(4, sizeof(backtrace[0]) * depth, backtrace);
97 // Trace the event.
98 Log(event.get());
101 void TraceEventETWProvider::Trace(const char* name,
102 size_t name_len,
103 char type,
104 const void* id,
105 const char* extra,
106 size_t extra_len) {
107 TraceEventETWProvider* provider = TraceEventETWProvider::GetInstance();
108 if (provider && provider->IsTracing()) {
109 // Compute the name & extra lengths if not supplied already.
110 if (name_len == kUseStrlen)
111 name_len = (name == NULL) ? 0 : strlen(name);
112 if (extra_len == kUseStrlen)
113 extra_len = (extra == NULL) ? 0 : strlen(extra);
115 provider->TraceEvent(name, name_len, type, id, extra, extra_len);
119 void TraceEventETWProvider::Resurrect() {
120 StaticMemorySingletonTraits<TraceEventETWProvider>::Resurrect();
123 } // namespace trace_event
124 } // namespace base