Chromium Code Reviews| Index: chrome/test/base/file_logger_win.h |
| diff --git a/chrome/test/base/file_logger_win.h b/chrome/test/base/file_logger_win.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e1126bc24cbfd3c136e4af29b410ba50b667d36b |
| --- /dev/null |
| +++ b/chrome/test/base/file_logger_win.h |
| @@ -0,0 +1,97 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_TEST_BASE_FILE_LOGGER_WIN_H_ |
| +#define CHROME_TEST_BASE_FILE_LOGGER_WIN_H_ |
| +#pragma once |
| + |
| +#include <guiddef.h> |
| + |
| +#include <ostream> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/win/event_trace_controller.h" |
| + |
| +class FilePath; |
| + |
| +// A file logger instance captures LOG messages and trace events emitted via |
| +// Event Tracing for Windows (ETW) and sends them to a file. The contents of |
| +// such a file can be sent to an output stream sometime later. Due to the |
| +// nature of event generation, only one instance of this class may be |
| +// initialized at a time. This class is not thread safe. This class uses |
|
robertshield
2012/03/05 19:20:54
Place the "not thread safe" message on a separate
grt (UTC plus 2)
2012/03/06 03:24:57
Done.
|
| +// facilities that require the process to run with admin rights; StartLogging() |
| +// will return false if this is not the case. |
| +// |
| +// Initializing an instance will add the variable CHROME_ETW_LOGGING=1 to the |
| +// system-wide environment if it is not present. In the case where it is not |
| +// already present, log messages will not be captured from currently running |
| +// instances of Chrome, Chrome Frame, or other providers that generate events |
| +// conditionally based on that environment variable. |
| +class FileLogger { |
| + public: |
| + enum EventProviderBits { |
| + // Log messages from chrome.exe. |
| + CHROME_LOG_PROVIDER = 1 << 0, |
| + // Log messages from npchrome_frame.dll. |
| + CHROME_FRAME_LOG_PROVIDER = 1 << 1, |
| + // Log messages from the current process. |
| + CHROME_TESTS_LOG_PROVIDER = 1 << 2, |
| + // Trace events. |
| + CHROME_TRACE_EVENT_PROVIDER = 1 << 3, |
| + }; |
| + |
| + static const uint32 kAllEventProviders = (CHROME_LOG_PROVIDER | |
| + CHROME_FRAME_LOG_PROVIDER | |
| + CHROME_TESTS_LOG_PROVIDER | |
| + CHROME_TRACE_EVENT_PROVIDER); |
| + |
| + FileLogger(); |
| + ~FileLogger(); |
| + |
| + // Initializes the instance to collect logs from all supported providers. |
| + void Initialize(); |
| + |
| + // Initializes the instance to collect logs from the providers present in |
| + // the given mask; see EventProviderBits. |
| + void Initialize(uint32 event_provider_mask); |
| + |
| + // Removes the system-wide CHROME_ETW_LOGGING=1 variable from the environment |
| + // if it was inserted in Initialize(). |
| + void Uninitialize(); |
| + |
| + // Starts capturing logs from all providers into |log_file|. The common file |
| + // extension for such files is .etl. Returns false if the session could not |
| + // be started (e.g., if not running as admin). |
| + bool StartLogging(const FilePath& log_file); |
| + |
| + // Stops capturing logs. |
| + void StopLogging(); |
| + |
| + // Returns true if logs are being captured. |
| + bool is_logging() const { |
| + return controller_.session_name() && *controller_.session_name(); |
| + } |
| + |
| + // Dumps all messages in |log_file|, which must have been produced by an |
| + // instance of this class, to |out|. |
| + static void DumpLogFile(const FilePath& log_file, std::ostream& out); |
| + |
| + private: |
| + bool EnableProviders(); |
| + void DisableProviders(); |
| + |
| + void ConfigureChromeEtwLogging(); |
| + void RevertChromeEtwLogging(); |
| + |
| + base::win::EtwTraceController controller_; |
| + uint32 event_provider_mask_; |
| + |
| + // True if the system-wide variable CHROME_ETW_LOGGING=1 was inserted into the |
| + // environment. |
| + bool added_chrome_etw_variable_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FileLogger); |
| +}; |
| + |
| +#endif // CHROME_TEST_BASE_FILE_LOGGER_WIN_H_ |