Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 #ifndef CHROME_TEST_BASE_FILE_LOGGER_WIN_H_ | |
| 6 #define CHROME_TEST_BASE_FILE_LOGGER_WIN_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <guiddef.h> | |
| 10 | |
| 11 #include <ostream> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/basictypes.h" | |
| 15 #include "base/win/event_trace_controller.h" | |
| 16 | |
| 17 class FilePath; | |
| 18 | |
| 19 // A file logger instance captures LOG messages emitted as events via Event | |
| 20 // Tracing for Windows (ETW) and sends them to a file. The contents of such a | |
| 21 // file can be sent to an output stream sometime later. Due to the nature of | |
| 22 // event generation, only one instance of this class may be initialized at a | |
| 23 // time. | |
| 24 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
| |
| 25 public: | |
| 26 FileLogger(); | |
| 27 ~FileLogger(); | |
| 28 | |
| 29 // Initializes the instance to collect logs from the default set of providers: | |
| 30 // - chrome.exe | |
| 31 // - npchrome_frame.dll | |
| 32 // - this test binary. | |
| 33 // The system-wide variable CHROME_ETW_LOGGING=1 is added to the environment | |
| 34 // if it is not present. | |
| 35 void Initialize(); | |
| 36 | |
| 37 // Initializes the instance to collect logs from the given providers. | |
| 38 void Initialize(const GUID* const* provider_names, size_t provider_count); | |
| 39 | |
| 40 // Removes the system-wide CHROME_ETW_LOGGING=1 variable from the environment | |
| 41 // if it was inserted in Initialize(). | |
| 42 void Uninitialize(); | |
| 43 | |
| 44 // Starts capturing logs from all providers into |log_file|. The common file | |
| 45 // extension for such files is .etl. | |
| 46 bool StartLogging(const FilePath& log_file); | |
| 47 | |
| 48 // Stops capturing logs. | |
| 49 void StopLogging(); | |
| 50 | |
| 51 // Returns true if logs are being captured. | |
| 52 bool is_logging() const { | |
| 53 return controller_.session_name() && *controller_.session_name(); | |
| 54 } | |
| 55 | |
| 56 // Dumps all messages in |log_file|, which must have been produced by an | |
| 57 // instance of this class, to |out|. | |
| 58 static void DumpLogFile(const FilePath& log_file, std::ostream& out); | |
| 59 | |
| 60 private: | |
| 61 bool EnableProviders(); | |
| 62 void DisableProviders(); | |
| 63 | |
| 64 void ConfigureChromeEtwLogging(); | |
| 65 void RevertChromeEtwLogging(); | |
| 66 | |
| 67 std::vector<GUID> provider_names_; | |
| 68 base::win::EtwTraceController controller_; | |
| 69 | |
| 70 // True if the system-wide variable CHROME_ETW_LOGGING=1 was inserted into the | |
| 71 // environment. | |
| 72 bool added_chrome_etw_variable_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(FileLogger); | |
| 75 }; | |
| 76 | |
| 77 #endif // CHROME_TEST_BASE_FILE_LOGGER_WIN_H_ | |
| OLD | NEW |