Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: base/trace_event_win.cc

Issue 3945002: Move debug-related stuff from base to the base/debug directory and use the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/trace_event_win.h ('k') | base/trace_event_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 #include "base/trace_event_win.h"
5
6 #include "base/logging.h"
7 #include "base/singleton.h"
8 #include <initguid.h> // NOLINT
9
10 namespace base {
11
12 // {3DADA31D-19EF-4dc1-B345-037927193422}
13 const GUID kChromeTraceProviderName = {
14 0x3dada31d, 0x19ef, 0x4dc1, 0xb3, 0x45, 0x3, 0x79, 0x27, 0x19, 0x34, 0x22 };
15
16 // {B967AE67-BB22-49d7-9406-55D91EE1D560}
17 const GUID kTraceEventClass32 = {
18 0xb967ae67, 0xbb22, 0x49d7, 0x94, 0x6, 0x55, 0xd9, 0x1e, 0xe1, 0xd5, 0x60 };
19
20 // {97BE602D-2930-4ac3-8046-B6763B631DFE}
21 const GUID kTraceEventClass64 = {
22 0x97be602d, 0x2930, 0x4ac3, 0x80, 0x46, 0xb6, 0x76, 0x3b, 0x63, 0x1d, 0xfe};
23
24
25 TraceLog::TraceLog() : EtwTraceProvider(base::kChromeTraceProviderName) {
26 Register();
27 }
28
29 TraceLog* TraceLog::Get() {
30 return Singleton<TraceLog, StaticMemorySingletonTraits<TraceLog>>::get();
31 }
32
33 bool TraceLog::StartTracing() {
34 return true;
35 }
36
37 void TraceLog::TraceEvent(const char* name,
38 size_t name_len,
39 base::TraceLog::EventType type,
40 const void* id,
41 const char* extra,
42 size_t extra_len) {
43 // Make sure we don't touch NULL.
44 if (name == NULL)
45 name = "";
46 if (extra == NULL)
47 extra = "";
48
49 EtwEventType etw_type = 0;
50 switch (type) {
51 case base::TraceLog::EVENT_BEGIN:
52 etw_type = base::kTraceEventTypeBegin;
53 break;
54 case base::TraceLog::EVENT_END:
55 etw_type = base::kTraceEventTypeEnd;
56 break;
57
58 case base::TraceLog::EVENT_INSTANT:
59 etw_type = base::kTraceEventTypeInstant;
60 break;
61
62 default:
63 NOTREACHED() << "Unknown event type";
64 etw_type = base::kTraceEventTypeInstant;
65 break;
66 }
67
68 EtwMofEvent<5> event(base::kTraceEventClass32,
69 etw_type,
70 TRACE_LEVEL_INFORMATION);
71 event.SetField(0, name_len + 1, name);
72 event.SetField(1, sizeof(id), &id);
73 event.SetField(2, extra_len + 1, extra);
74
75 // See whether we're to capture a backtrace.
76 void* backtrace[32];
77 if (enable_flags() & base::CAPTURE_STACK_TRACE) {
78 DWORD hash = 0;
79 DWORD depth = CaptureStackBackTrace(0,
80 arraysize(backtrace),
81 backtrace,
82 &hash);
83 event.SetField(3, sizeof(depth), &depth);
84 event.SetField(4, sizeof(backtrace[0]) * depth, backtrace);
85 }
86
87 // Trace the event.
88 Log(event.get());
89 }
90
91 void TraceLog::Trace(const char* name,
92 size_t name_len,
93 EventType type,
94 const void* id,
95 const char* extra,
96 size_t extra_len) {
97 TraceLog* provider = TraceLog::Get();
98 if (provider && provider->IsTracing()) {
99 // Compute the name & extra lengths if not supplied already.
100 if (name_len == -1)
101 name_len = (name == NULL) ? 0 : strlen(name);
102 if (extra_len == -1)
103 extra_len = (extra == NULL) ? 0 : strlen(extra);
104
105 provider->TraceEvent(name, name_len, type, id, extra, extra_len);
106 }
107 }
108
109 void TraceLog::Resurrect() {
110 StaticMemorySingletonTraits<TraceLog>::Resurrect();
111 }
112
113 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event_win.h ('k') | base/trace_event_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698