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

Unified Diff: components/browser_watcher/watcher_metrics_provider_win.cc

Issue 717223002: Browser watcher end-end-to-end . (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/lkgr
Patch Set: Address Erik's comments. Created 6 years, 1 month 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: components/browser_watcher/watcher_metrics_provider_win.cc
diff --git a/components/browser_watcher/watcher_metrics_provider_win.cc b/components/browser_watcher/watcher_metrics_provider_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9ea9bdbff30be94b40d8130f6efbe6cb29d5ad2e
--- /dev/null
+++ b/components/browser_watcher/watcher_metrics_provider_win.cc
@@ -0,0 +1,91 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/browser_watcher/watcher_metrics_provider_win.h"
+
+#include "base/metrics/sparse_histogram.h"
+#include "base/process/process_handle.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/win/registry.h"
+
+namespace browser_watcher {
+
+namespace {
+
+// This function does soft matching on the PID recorded in the key only.
+// Due to PID reuse, the possibility exists that the process that's now live
+// is not the same process the data was recorded for. This doesn't matter for
+// this purpose, as eventually the data will be scavenged and reported.
+bool IsLiveProcess(const base::string16& key_name) {
+ int pid = 0;
+ base::StringToInt(key_name, &pid);
+
+ if (pid == 0)
+ return false;
+
+ // This is a very inexpensive check for the common case of our own PID.
+ if (static_cast<base::ProcessId>(pid) == base::GetCurrentProcId())
+ return true;
+
+ // The process is not our own - see whether a process with this PID exists.
+ base::ProcessHandle process = base::kNullProcessHandle;
+ if (base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) {
+ base::CloseProcessHandle(process);
+
+ return true;
+ }
+
+ return false;
+}
+
+} // namespace
+
+const char WatcherMetricsProviderWin::kBrowserExitCodeHistogramName[] =
+ "Stability.BrowserExitCodes";
+
+
+WatcherMetricsProviderWin::WatcherMetricsProviderWin(
+ const base::char16* registry_path) : registry_path_(registry_path) {
+}
+
+WatcherMetricsProviderWin::~WatcherMetricsProviderWin() {
+}
+
+void WatcherMetricsProviderWin::ProvideStabilityMetrics(
+ metrics::SystemProfileProto* system_profile_proto) {
+ base::win::RegKey regkey(HKEY_CURRENT_USER,
+ registry_path_.c_str(),
+ KEY_QUERY_VALUE | KEY_SET_VALUE);
+
+ std::vector<base::string16> to_delete;
+ size_t num = regkey.GetValueCount();
+
+ // Record the exit codes in a sparse histogram, as the range of values
+ // used to report failures is large.
+ base::HistogramBase* exit_code_histogram =
+ // TODO(siggi): is this an acceptable name?
+ base::SparseHistogram::FactoryGet(kBrowserExitCodeHistogramName,
+ base::HistogramBase::kUmaStabilityHistogramFlag);
+
+ for (size_t i = 0; i < num; ++i) {
+ base::string16 name;
+ if (regkey.GetValueNameAt(i, &name) == ERROR_SUCCESS) {
+ DWORD exit_code = 0;
+ if (regkey.ReadValueDW(name.c_str(), &exit_code) == ERROR_SUCCESS) {
+ // Do not report exit codes for processes that are still live, notably
+ // not for our own process.
+ if (exit_code != STILL_ACTIVE || !IsLiveProcess(name)) {
+ to_delete.push_back(name);
+ exit_code_histogram->Add(exit_code);
+ }
+ }
+ }
+ }
+
+ // Delete the values reported above.
+ for (size_t i = 0; i < to_delete.size(); ++i)
+ regkey.DeleteValue(to_delete[i].c_str());
+}
+
+} // namespace browser_watcher

Powered by Google App Engine
This is Rietveld 408576698