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..97b1c3f95021743d12de2b836a6f3b3f3ab461f6 |
| --- /dev/null |
| +++ b/chrome/test/base/file_logger_win.h |
| @@ -0,0 +1,77 @@ |
| +// 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 <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/win/event_trace_controller.h" |
| + |
| +class FilePath; |
| + |
| +// A file logger instance captures LOG messages emitted as events 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. |
| +class FileLogger { |
|
erikwright (departed)
2012/03/02 20:47:59
I wonder if you really need separate steps for con
grt (UTC plus 2)
2012/03/02 21:22:43
Yup, the collector does. Initialize happens just
erikwright (departed)
2012/03/03 02:04:56
OK. One thing to consider is whether you simplify
grt (UTC plus 2)
2012/03/03 02:31:59
That's a good point. I understand where you're co
|
| + public: |
| + FileLogger(); |
| + ~FileLogger(); |
| + |
| + // Initializes the instance to collect logs from the default set of providers: |
| + // - chrome.exe |
| + // - npchrome_frame.dll |
| + // - this test binary. |
| + // The system-wide variable CHROME_ETW_LOGGING=1 is added to the environment |
| + // if it is not present. |
| + void Initialize(); |
| + |
| + // Initializes the instance to collect logs from the given providers. |
| + void Initialize(const GUID* const* provider_names, size_t provider_count); |
| + |
| + // 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. |
| + 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(); |
| + |
| + std::vector<GUID> provider_names_; |
| + base::win::EtwTraceController controller_; |
| + |
| + // 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_ |