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

Side by Side Diff: chrome/test/base/file_logger_win.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: oops, forgot to add test 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
erikwright (departed) 2012/03/09 18:25:50 I think the _win suffix most commonly applies to t
grt (UTC plus 2) 2012/03/09 20:38:57 All files are now in chrome/test/logging_win, and
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 "base/basictypes.h"
12 #include "base/win/event_trace_controller.h"
13
14 class FilePath;
15
16 // A file logger instance captures LOG messages and trace events emitted via
17 // Event Tracing for Windows (ETW) and sends them to a file. Events can be
18 // pulled from the file sometime later with PrintLogFile or ReadLogFile
19 // (currently in log_file_printer_win.h and log_file_reader_win.h,
20 // respectively).
21 //
22 // Important usage notes (read this):
23 // - Due to the nature of event generation, only one instance of this class may
24 // be initialized at a time.
25 // - This class is not thread safe.
26 // - This class uses facilities that require the process to run with admin
27 // rights; StartLogging() will return false if this is not the case.
28 //
29 // Initializing an instance will add the variable CHROME_ETW_LOGGING=1 to the
30 // system-wide environment if it is not present. In the case where it is not
31 // already present, log messages will not be captured from currently running
32 // instances of Chrome, Chrome Frame, or other providers that generate events
33 // conditionally based on that environment variable.
34 class FileLogger {
erikwright (departed) 2012/03/09 18:25:50 I think the name might be a little vague. Is it no
grt (UTC plus 2) 2012/03/09 20:38:57 What do you think of LogFileWriter, which is consi
35 public:
36 enum EventProviderBits {
37 // Log messages from chrome.exe.
38 CHROME_LOG_PROVIDER = 1 << 0,
39 // Log messages from npchrome_frame.dll.
40 CHROME_FRAME_LOG_PROVIDER = 1 << 1,
41 // Log messages from the current process.
42 CHROME_TESTS_LOG_PROVIDER = 1 << 2,
43 // Trace events.
44 CHROME_TRACE_EVENT_PROVIDER = 1 << 3,
45 };
46
47 static const uint32 kAllEventProviders = (CHROME_LOG_PROVIDER |
48 CHROME_FRAME_LOG_PROVIDER |
49 CHROME_TESTS_LOG_PROVIDER |
50 CHROME_TRACE_EVENT_PROVIDER);
51
52 FileLogger();
53 ~FileLogger();
54
55 // Initializes the instance to collect logs from all supported providers.
56 void Initialize();
57
58 // Initializes the instance to collect logs from the providers present in
59 // the given mask; see EventProviderBits.
60 void Initialize(uint32 event_provider_mask);
61
62 // Removes the system-wide CHROME_ETW_LOGGING=1 variable from the environment
63 // if it was inserted in Initialize().
64 void Uninitialize();
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).
69 bool StartLogging(const FilePath& log_file);
70
71 // Stops capturing logs.
72 void StopLogging();
73
74 // Returns true if logs are being captured.
75 bool is_logging() const {
76 return controller_.session_name() && *controller_.session_name();
77 }
78
79 private:
80 bool EnableProviders();
81 void DisableProviders();
82
83 void ConfigureChromeEtwLogging();
84 void RevertChromeEtwLogging();
85
86 base::win::EtwTraceController controller_;
87 uint32 event_provider_mask_;
88
89 // True if the system-wide variable CHROME_ETW_LOGGING=1 was inserted into the
90 // environment.
91 bool added_chrome_etw_variable_;
92
93 DISALLOW_COPY_AND_ASSIGN(FileLogger);
94 };
95
96 #endif // CHROME_TEST_BASE_FILE_LOGGER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698