Tweak/Wontfix a few tests that we could care less about.
[chromium-blink-merge.git] / base / event_trace_controller_win.cc
blobcb15150311ac85473993fd432c71c794226c8d3a
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"
9 EtwTraceController::EtwTraceController() : session_(NULL) {
12 EtwTraceController::~EtwTraceController() {
13 Stop(NULL);
16 HRESULT EtwTraceController::Start(const wchar_t* session_name,
17 EtwTraceProperties* prop) {
18 DCHECK(NULL == session_ && session_name_.empty());
19 EtwTraceProperties ignore;
20 if (prop == NULL)
21 prop = &ignore;
23 HRESULT hr = Start(session_name, prop, &session_);
24 if (SUCCEEDED(hr))
25 session_name_ = session_name;
27 return hr;
30 HRESULT EtwTraceController::StartFileSession(const wchar_t* session_name,
31 const wchar_t* logfile_path, bool realtime) {
32 DCHECK(NULL == session_ && session_name_.empty());
34 EtwTraceProperties prop;
35 prop.SetLoggerFileName(logfile_path);
36 EVENT_TRACE_PROPERTIES& p = *prop.get();
37 p.Wnode.ClientContext = 1; // QPC timer accuracy.
38 p.LogFileMode = EVENT_TRACE_FILE_MODE_SEQUENTIAL; // Sequential log.
39 if (realtime)
40 p.LogFileMode |= EVENT_TRACE_REAL_TIME_MODE;
42 p.MaximumFileSize = 100; // 100M file size.
43 p.FlushTimer = 30; // 30 seconds flush lag.
44 return Start(session_name, &prop);
47 HRESULT EtwTraceController::StartRealtimeSession(const wchar_t* session_name,
48 size_t buffer_size) {
49 DCHECK(NULL == session_ && session_name_.empty());
50 EtwTraceProperties prop;
51 EVENT_TRACE_PROPERTIES& p = *prop.get();
52 p.LogFileMode = EVENT_TRACE_REAL_TIME_MODE | EVENT_TRACE_USE_PAGED_MEMORY;
53 p.FlushTimer = 1; // flush every second.
54 p.BufferSize = 16; // 16 K buffers.
55 p.LogFileNameOffset = 0;
56 return Start(session_name, &prop);
59 HRESULT EtwTraceController::EnableProvider(REFGUID provider, UCHAR level,
60 ULONG flags) {
61 ULONG error = ::EnableTrace(TRUE, flags, level, &provider, session_);
62 return HRESULT_FROM_WIN32(error);
65 HRESULT EtwTraceController::DisableProvider(REFGUID provider) {
66 ULONG error = ::EnableTrace(FALSE, 0, 0, &provider, session_);
67 return HRESULT_FROM_WIN32(error);
70 HRESULT EtwTraceController::Stop(EtwTraceProperties* properties) {
71 EtwTraceProperties ignore;
72 if (properties == NULL)
73 properties = &ignore;
75 ULONG error = ::ControlTrace(session_, NULL, properties->get(),
76 EVENT_TRACE_CONTROL_STOP);
77 if (ERROR_SUCCESS != error)
78 return HRESULT_FROM_WIN32(error);
80 session_ = NULL;
81 session_name_.clear();
82 return S_OK;
85 HRESULT EtwTraceController::Flush(EtwTraceProperties* properties) {
86 EtwTraceProperties ignore;
87 if (properties == NULL)
88 properties = &ignore;
90 ULONG error = ::ControlTrace(session_, NULL, properties->get(),
91 EVENT_TRACE_CONTROL_FLUSH);
92 if (ERROR_SUCCESS != error)
93 return HRESULT_FROM_WIN32(error);
95 return S_OK;
98 HRESULT EtwTraceController::Start(const wchar_t* session_name,
99 EtwTraceProperties* properties, TRACEHANDLE* session_handle) {
100 ULONG err = ::StartTrace(session_handle, session_name, properties->get());
101 return HRESULT_FROM_WIN32(err);
104 HRESULT EtwTraceController::Query(const wchar_t* session_name,
105 EtwTraceProperties* properties) {
106 ULONG err = ::ControlTrace(NULL, session_name, properties->get(),
107 EVENT_TRACE_CONTROL_QUERY);
108 return HRESULT_FROM_WIN32(err);
111 HRESULT EtwTraceController::Update(const wchar_t* session_name,
112 EtwTraceProperties* properties) {
113 ULONG err = ::ControlTrace(NULL, session_name, properties->get(),
114 EVENT_TRACE_CONTROL_UPDATE);
115 return HRESULT_FROM_WIN32(err);
118 HRESULT EtwTraceController::Stop(const wchar_t* session_name,
119 EtwTraceProperties* properties) {
120 ULONG err = ::ControlTrace(NULL, session_name, properties->get(),
121 EVENT_TRACE_CONTROL_STOP);
122 return HRESULT_FROM_WIN32(err);
125 HRESULT EtwTraceController::Flush(const wchar_t* session_name,
126 EtwTraceProperties* properties) {
127 ULONG err = ::ControlTrace(NULL, session_name, properties->get(),
128 EVENT_TRACE_CONTROL_FLUSH);
129 return HRESULT_FROM_WIN32(err);