Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: chrome/test/logging/win/file_logger.h

Issue 9584017: New test infrastructure for producing verbose logs in failing tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moved logging_win to logging/win so regular filename_rules work Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/logging/win/OWNERS ('k') | chrome/test/logging/win/file_logger.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_LOGGING_WIN_FILE_LOGGER_H_
6 #define CHROME_TEST_LOGGING_WIN_FILE_LOGGER_H_
7 #pragma once
8
9 #include <guiddef.h>
10
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/string16.h"
14 #include "base/win/event_trace_controller.h"
15
16 class FilePath;
17
18 namespace logging_win {
19
20 // A file logger instance captures LOG messages and trace events emitted via
21 // Event Tracing for Windows (ETW) and sends them to a file. Events can be
22 // pulled from the file sometime later with PrintLogFile or ReadLogFile
23 // (currently in log_file_printer_win.h and log_file_reader_win.h,
24 // respectively).
25 //
26 // Important usage notes (read this):
27 // - Due to the nature of event generation, only one instance of this class may
28 // be initialized at a time.
29 // - This class is not thread safe.
30 // - This class uses facilities that require the process to run with admin
31 // rights; StartLogging() will return false if this is not the case.
32 //
33 // Initializing an instance will add the variable CHROME_ETW_LOGGING=1 to the
34 // system-wide environment if it is not present. In the case where it is not
35 // already present, log messages will not be captured from currently running
36 // instances of Chrome, Chrome Frame, or other providers that generate events
37 // conditionally based on that environment variable.
38 class FileLogger {
39 public:
40 enum EventProviderBits {
41 // Log messages from chrome.exe.
42 CHROME_LOG_PROVIDER = 1 << 0,
43 // Log messages from npchrome_frame.dll.
44 CHROME_FRAME_LOG_PROVIDER = 1 << 1,
45 // Log messages from the current process.
46 CHROME_TESTS_LOG_PROVIDER = 1 << 2,
47 // Trace events.
48 CHROME_TRACE_EVENT_PROVIDER = 1 << 3,
49 };
50
51 static const uint32 kAllEventProviders = (CHROME_LOG_PROVIDER |
52 CHROME_FRAME_LOG_PROVIDER |
53 CHROME_TESTS_LOG_PROVIDER |
54 CHROME_TRACE_EVENT_PROVIDER);
55
56 FileLogger();
57 ~FileLogger();
58
59 // Initializes the instance to collect logs from all supported providers.
60 void Initialize();
61
62 // Initializes the instance to collect logs from the providers present in
63 // the given mask; see EventProviderBits.
64 void Initialize(uint32 event_provider_mask);
65
66 // Starts capturing logs from all providers into |log_file|. The common file
67 // extension for such files is .etl. Returns false if the session could not
68 // be started (e.g., if not running as admin) or if no providers could be
69 // enabled.
70 bool StartLogging(const FilePath& log_file);
71
72 // Stops capturing logs.
73 void StopLogging();
74
75 // Returns true if logs are being captured.
76 bool is_logging() const {
77 return controller_.session_name() && *controller_.session_name();
78 }
79
80 private:
81 // A helper for setting/clearing a variable in the system-wide environment.
82 class ScopedSystemEnvironmentVariable {
83 public:
84 ScopedSystemEnvironmentVariable(const string16& variable,
85 const string16& value);
86 ~ScopedSystemEnvironmentVariable();
87
88 private:
89 static void NotifyOtherProcesses();
90
91 // Non-empty if the variable was inserted into the system-wide environment.
92 string16 variable_;
93 DISALLOW_COPY_AND_ASSIGN(ScopedSystemEnvironmentVariable);
94 };
95
96 bool EnableProviders();
97 void DisableProviders();
98
99 void ConfigureChromeEtwLogging();
100 void RevertChromeEtwLogging();
101
102 static bool is_initialized_;
103
104 scoped_ptr<ScopedSystemEnvironmentVariable> etw_logging_configurator_;
105 base::win::EtwTraceController controller_;
106 uint32 event_provider_mask_;
107
108 DISALLOW_COPY_AND_ASSIGN(FileLogger);
109 };
110
111 } // namespace logging_win
112
113 #endif // CHROME_TEST_LOGGING_WIN_FILE_LOGGER_H_
OLDNEW
« no previous file with comments | « chrome/test/logging/win/OWNERS ('k') | chrome/test/logging/win/file_logger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698