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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/base/file_logger_win.h
diff --git a/chrome/test/base/file_logger_win.h b/chrome/test/base/file_logger_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..9b191c0ce7f182f9972e4ce136e612d582ee70e9
--- /dev/null
+++ b/chrome/test/base/file_logger_win.h
@@ -0,0 +1,96 @@
+// 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
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_TEST_BASE_FILE_LOGGER_WIN_H_
+#define CHROME_TEST_BASE_FILE_LOGGER_WIN_H_
+#pragma once
+
+#include <guiddef.h>
+
+#include "base/basictypes.h"
+#include "base/win/event_trace_controller.h"
+
+class FilePath;
+
+// A file logger instance captures LOG messages and trace events emitted via
+// Event Tracing for Windows (ETW) and sends them to a file. Events can be
+// pulled from the file sometime later with PrintLogFile or ReadLogFile
+// (currently in log_file_printer_win.h and log_file_reader_win.h,
+// respectively).
+//
+// Important usage notes (read this):
+// - Due to the nature of event generation, only one instance of this class may
+// be initialized at a time.
+// - This class is not thread safe.
+// - This class uses facilities that require the process to run with admin
+// rights; StartLogging() will return false if this is not the case.
+//
+// Initializing an instance will add the variable CHROME_ETW_LOGGING=1 to the
+// system-wide environment if it is not present. In the case where it is not
+// already present, log messages will not be captured from currently running
+// instances of Chrome, Chrome Frame, or other providers that generate events
+// conditionally based on that environment variable.
+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
+ public:
+ enum EventProviderBits {
+ // Log messages from chrome.exe.
+ CHROME_LOG_PROVIDER = 1 << 0,
+ // Log messages from npchrome_frame.dll.
+ CHROME_FRAME_LOG_PROVIDER = 1 << 1,
+ // Log messages from the current process.
+ CHROME_TESTS_LOG_PROVIDER = 1 << 2,
+ // Trace events.
+ CHROME_TRACE_EVENT_PROVIDER = 1 << 3,
+ };
+
+ static const uint32 kAllEventProviders = (CHROME_LOG_PROVIDER |
+ CHROME_FRAME_LOG_PROVIDER |
+ CHROME_TESTS_LOG_PROVIDER |
+ CHROME_TRACE_EVENT_PROVIDER);
+
+ FileLogger();
+ ~FileLogger();
+
+ // Initializes the instance to collect logs from all supported providers.
+ void Initialize();
+
+ // Initializes the instance to collect logs from the providers present in
+ // the given mask; see EventProviderBits.
+ void Initialize(uint32 event_provider_mask);
+
+ // Removes the system-wide CHROME_ETW_LOGGING=1 variable from the environment
+ // if it was inserted in Initialize().
+ void Uninitialize();
+
+ // Starts capturing logs from all providers into |log_file|. The common file
+ // extension for such files is .etl. Returns false if the session could not
+ // be started (e.g., if not running as admin).
+ bool StartLogging(const FilePath& log_file);
+
+ // Stops capturing logs.
+ void StopLogging();
+
+ // Returns true if logs are being captured.
+ bool is_logging() const {
+ return controller_.session_name() && *controller_.session_name();
+ }
+
+ private:
+ bool EnableProviders();
+ void DisableProviders();
+
+ void ConfigureChromeEtwLogging();
+ void RevertChromeEtwLogging();
+
+ base::win::EtwTraceController controller_;
+ uint32 event_provider_mask_;
+
+ // True if the system-wide variable CHROME_ETW_LOGGING=1 was inserted into the
+ // environment.
+ bool added_chrome_etw_variable_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileLogger);
+};
+
+#endif // CHROME_TEST_BASE_FILE_LOGGER_WIN_H_

Powered by Google App Engine
This is Rietveld 408576698