Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / test / logging / win / file_logger.h
blobf2a911d4b67f8491ea3d7dbe8f4105be643b890f
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.
5 #ifndef CHROME_TEST_LOGGING_WIN_FILE_LOGGER_H_
6 #define CHROME_TEST_LOGGING_WIN_FILE_LOGGER_H_
8 #include <guiddef.h>
10 #include "base/basictypes.h"
11 #include "base/strings/string16.h"
12 #include "base/win/event_trace_controller.h"
14 namespace base {
15 class FilePath;
18 namespace logging_win {
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).
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 class FileLogger {
33 public:
34 enum EventProviderBits {
35 // Log messages from chrome.exe.
36 CHROME_LOG_PROVIDER = 1 << 0,
37 // Log messages from npchrome_frame.dll.
38 CHROME_FRAME_LOG_PROVIDER = 1 << 1,
39 // Log messages from the current process.
40 CHROME_TESTS_LOG_PROVIDER = 1 << 2,
41 // Trace events.
42 CHROME_TRACE_EVENT_PROVIDER = 1 << 3,
45 static const uint32 kAllEventProviders = (CHROME_LOG_PROVIDER |
46 CHROME_FRAME_LOG_PROVIDER |
47 CHROME_TESTS_LOG_PROVIDER |
48 CHROME_TRACE_EVENT_PROVIDER);
50 FileLogger();
51 ~FileLogger();
53 // Initializes the instance to collect logs from all supported providers.
54 void Initialize();
56 // Initializes the instance to collect logs from the providers present in
57 // the given mask; see EventProviderBits.
58 void Initialize(uint32 event_provider_mask);
60 // Starts capturing logs from all providers into |log_file|. The common file
61 // extension for such files is .etl. Returns false if the session could not
62 // be started (e.g., if not running as admin) or if no providers could be
63 // enabled.
64 bool StartLogging(const base::FilePath& log_file);
66 // Stops capturing logs.
67 void StopLogging();
69 // Returns true if logs are being captured.
70 bool is_logging() const {
71 return controller_.session_name() && *controller_.session_name();
74 private:
75 bool EnableProviders();
76 void DisableProviders();
78 static bool is_initialized_;
80 base::win::EtwTraceController controller_;
81 uint32 event_provider_mask_;
83 DISALLOW_COPY_AND_ASSIGN(FileLogger);
86 } // namespace logging_win
88 #endif // CHROME_TEST_LOGGING_WIN_FILE_LOGGER_H_