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

Side by Side Diff: base/event_trace_controller_win.cc

Issue 4517004: Move Windows-specific Event Tracing for Windows implementation to base/win. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixed another ETW user in Chrome Frame Created 10 years, 1 month 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/event_trace_controller_win.h ('k') | base/event_trace_controller_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 //
5 // Implementation of a Windows event trace controller class.
6 #include "base/event_trace_controller_win.h"
7 #include "base/logging.h"
8
9 EtwTraceProperties::EtwTraceProperties() {
10 memset(buffer_, 0, sizeof(buffer_));
11 EVENT_TRACE_PROPERTIES* prop = get();
12
13 prop->Wnode.BufferSize = sizeof(buffer_);
14 prop->Wnode.Flags = WNODE_FLAG_TRACED_GUID;
15 prop->LoggerNameOffset = sizeof(EVENT_TRACE_PROPERTIES);
16 prop->LogFileNameOffset = sizeof(EVENT_TRACE_PROPERTIES) +
17 sizeof(wchar_t) * kMaxStringLen;
18 }
19
20 HRESULT EtwTraceProperties::SetLoggerName(const wchar_t* logger_name) {
21 size_t len = wcslen(logger_name) + 1;
22 if (kMaxStringLen < len)
23 return E_INVALIDARG;
24
25 memcpy(buffer_ + get()->LoggerNameOffset,
26 logger_name,
27 sizeof(wchar_t) * len);
28 return S_OK;
29 }
30
31 HRESULT EtwTraceProperties::SetLoggerFileName(const wchar_t* logger_file_name) {
32 size_t len = wcslen(logger_file_name) + 1;
33 if (kMaxStringLen < len)
34 return E_INVALIDARG;
35
36 memcpy(buffer_ + get()->LogFileNameOffset,
37 logger_file_name,
38 sizeof(wchar_t) * len);
39 return S_OK;
40 }
41
42 EtwTraceController::EtwTraceController() : session_(NULL) {
43 }
44
45 EtwTraceController::~EtwTraceController() {
46 Stop(NULL);
47 }
48
49 HRESULT EtwTraceController::Start(const wchar_t* session_name,
50 EtwTraceProperties* prop) {
51 DCHECK(NULL == session_ && session_name_.empty());
52 EtwTraceProperties ignore;
53 if (prop == NULL)
54 prop = &ignore;
55
56 HRESULT hr = Start(session_name, prop, &session_);
57 if (SUCCEEDED(hr))
58 session_name_ = session_name;
59
60 return hr;
61 }
62
63 HRESULT EtwTraceController::StartFileSession(const wchar_t* session_name,
64 const wchar_t* logfile_path, bool realtime) {
65 DCHECK(NULL == session_ && session_name_.empty());
66
67 EtwTraceProperties prop;
68 prop.SetLoggerFileName(logfile_path);
69 EVENT_TRACE_PROPERTIES& p = *prop.get();
70 p.Wnode.ClientContext = 1; // QPC timer accuracy.
71 p.LogFileMode = EVENT_TRACE_FILE_MODE_SEQUENTIAL; // Sequential log.
72 if (realtime)
73 p.LogFileMode |= EVENT_TRACE_REAL_TIME_MODE;
74
75 p.MaximumFileSize = 100; // 100M file size.
76 p.FlushTimer = 30; // 30 seconds flush lag.
77 return Start(session_name, &prop);
78 }
79
80 HRESULT EtwTraceController::StartRealtimeSession(const wchar_t* session_name,
81 size_t buffer_size) {
82 DCHECK(NULL == session_ && session_name_.empty());
83 EtwTraceProperties prop;
84 EVENT_TRACE_PROPERTIES& p = *prop.get();
85 p.LogFileMode = EVENT_TRACE_REAL_TIME_MODE | EVENT_TRACE_USE_PAGED_MEMORY;
86 p.FlushTimer = 1; // flush every second.
87 p.BufferSize = 16; // 16 K buffers.
88 p.LogFileNameOffset = 0;
89 return Start(session_name, &prop);
90 }
91
92 HRESULT EtwTraceController::EnableProvider(REFGUID provider, UCHAR level,
93 ULONG flags) {
94 ULONG error = ::EnableTrace(TRUE, flags, level, &provider, session_);
95 return HRESULT_FROM_WIN32(error);
96 }
97
98 HRESULT EtwTraceController::DisableProvider(REFGUID provider) {
99 ULONG error = ::EnableTrace(FALSE, 0, 0, &provider, session_);
100 return HRESULT_FROM_WIN32(error);
101 }
102
103 HRESULT EtwTraceController::Stop(EtwTraceProperties* properties) {
104 EtwTraceProperties ignore;
105 if (properties == NULL)
106 properties = &ignore;
107
108 ULONG error = ::ControlTrace(session_, NULL, properties->get(),
109 EVENT_TRACE_CONTROL_STOP);
110 if (ERROR_SUCCESS != error)
111 return HRESULT_FROM_WIN32(error);
112
113 session_ = NULL;
114 session_name_.clear();
115 return S_OK;
116 }
117
118 HRESULT EtwTraceController::Flush(EtwTraceProperties* properties) {
119 EtwTraceProperties ignore;
120 if (properties == NULL)
121 properties = &ignore;
122
123 ULONG error = ::ControlTrace(session_, NULL, properties->get(),
124 EVENT_TRACE_CONTROL_FLUSH);
125 if (ERROR_SUCCESS != error)
126 return HRESULT_FROM_WIN32(error);
127
128 return S_OK;
129 }
130
131 HRESULT EtwTraceController::Start(const wchar_t* session_name,
132 EtwTraceProperties* properties, TRACEHANDLE* session_handle) {
133 DCHECK(properties != NULL);
134 ULONG err = ::StartTrace(session_handle, session_name, properties->get());
135 return HRESULT_FROM_WIN32(err);
136 }
137
138 HRESULT EtwTraceController::Query(const wchar_t* session_name,
139 EtwTraceProperties* properties) {
140 ULONG err = ::ControlTrace(NULL, session_name, properties->get(),
141 EVENT_TRACE_CONTROL_QUERY);
142 return HRESULT_FROM_WIN32(err);
143 };
144
145 HRESULT EtwTraceController::Update(const wchar_t* session_name,
146 EtwTraceProperties* properties) {
147 DCHECK(properties != NULL);
148 ULONG err = ::ControlTrace(NULL, session_name, properties->get(),
149 EVENT_TRACE_CONTROL_UPDATE);
150 return HRESULT_FROM_WIN32(err);
151 }
152
153 HRESULT EtwTraceController::Stop(const wchar_t* session_name,
154 EtwTraceProperties* properties) {
155 DCHECK(properties != NULL);
156 ULONG err = ::ControlTrace(NULL, session_name, properties->get(),
157 EVENT_TRACE_CONTROL_STOP);
158 return HRESULT_FROM_WIN32(err);
159 }
160
161 HRESULT EtwTraceController::Flush(const wchar_t* session_name,
162 EtwTraceProperties* properties) {
163 DCHECK(properties != NULL);
164 ULONG err = ::ControlTrace(NULL, session_name, properties->get(),
165 EVENT_TRACE_CONTROL_FLUSH);
166 return HRESULT_FROM_WIN32(err);
167 }
OLDNEW
« no previous file with comments | « base/event_trace_controller_win.h ('k') | base/event_trace_controller_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698