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 | |
13 #include "base/basictypes.h" | |
14 #include "base/win/event_trace_controller.h" | |
15 | |
16 class FilePath; | |
17 | |
18 // A file logger instance captures LOG messages and trace events emitted via | |
19 // Event Tracing for Windows (ETW) and sends them to a file. The contents of | |
20 // such a file can be sent to an output stream sometime later. Due to the | |
21 // nature of event generation, only one instance of this class may be | |
22 // 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.
| |
23 // facilities that require the process to run with admin rights; StartLogging() | |
24 // will return false if this is not the case. | |
25 // | |
26 // Initializing an instance will add the variable CHROME_ETW_LOGGING=1 to the | |
27 // system-wide environment if it is not present. In the case where it is not | |
28 // already present, log messages will not be captured from currently running | |
29 // instances of Chrome, Chrome Frame, or other providers that generate events | |
30 // conditionally based on that environment variable. | |
31 class FileLogger { | |
32 public: | |
33 enum EventProviderBits { | |
34 // Log messages from chrome.exe. | |
35 CHROME_LOG_PROVIDER = 1 << 0, | |
36 // Log messages from npchrome_frame.dll. | |
37 CHROME_FRAME_LOG_PROVIDER = 1 << 1, | |
38 // Log messages from the current process. | |
39 CHROME_TESTS_LOG_PROVIDER = 1 << 2, | |
40 // Trace events. | |
41 CHROME_TRACE_EVENT_PROVIDER = 1 << 3, | |
42 }; | |
43 | |
44 static const uint32 kAllEventProviders = (CHROME_LOG_PROVIDER | | |
45 CHROME_FRAME_LOG_PROVIDER | | |
46 CHROME_TESTS_LOG_PROVIDER | | |
47 CHROME_TRACE_EVENT_PROVIDER); | |
48 | |
49 FileLogger(); | |
50 ~FileLogger(); | |
51 | |
52 // Initializes the instance to collect logs from all supported providers. | |
53 void Initialize(); | |
54 | |
55 // Initializes the instance to collect logs from the providers present in | |
56 // the given mask; see EventProviderBits. | |
57 void Initialize(uint32 event_provider_mask); | |
58 | |
59 // Removes the system-wide CHROME_ETW_LOGGING=1 variable from the environment | |
60 // if it was inserted in Initialize(). | |
61 void Uninitialize(); | |
62 | |
63 // Starts capturing logs from all providers into |log_file|. The common file | |
64 // extension for such files is .etl. Returns false if the session could not | |
65 // be started (e.g., if not running as admin). | |
66 bool StartLogging(const FilePath& log_file); | |
67 | |
68 // Stops capturing logs. | |
69 void StopLogging(); | |
70 | |
71 // Returns true if logs are being captured. | |
72 bool is_logging() const { | |
73 return controller_.session_name() && *controller_.session_name(); | |
74 } | |
75 | |
76 // Dumps all messages in |log_file|, which must have been produced by an | |
77 // instance of this class, to |out|. | |
78 static void DumpLogFile(const FilePath& log_file, std::ostream& out); | |
79 | |
80 private: | |
81 bool EnableProviders(); | |
82 void DisableProviders(); | |
83 | |
84 void ConfigureChromeEtwLogging(); | |
85 void RevertChromeEtwLogging(); | |
86 | |
87 base::win::EtwTraceController controller_; | |
88 uint32 event_provider_mask_; | |
89 | |
90 // True if the system-wide variable CHROME_ETW_LOGGING=1 was inserted into the | |
91 // environment. | |
92 bool added_chrome_etw_variable_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(FileLogger); | |
95 }; | |
96 | |
97 #endif // CHROME_TEST_BASE_FILE_LOGGER_WIN_H_ | |
OLD | NEW |