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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014 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 #include "components/browser_watcher/watcher_metrics_provider_win.h"
6
7 #include "base/metrics/sparse_histogram.h"
8 #include "base/process/process_handle.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/win/registry.h"
11
12 namespace browser_watcher {
13
14 namespace {
15
16 // This function does soft matching on the PID recorded in the key only.
17 // Due to PID reuse, the possibility exists that the process that's now live
18 // is not the same process the data was recorded for. This doesn't matter for
19 // this purpose, as eventually the data will be scavenged and reported.
20 bool IsLiveProcess(const base::string16& key_name) {
21 int pid = 0;
22 base::StringToInt(key_name, &pid);
23
24 if (pid == 0)
25 return false;
26
27 // This is a very inexpensive check for the common case of our own PID.
28 if (static_cast<base::ProcessId>(pid) == base::GetCurrentProcId())
29 return true;
30
31 // The process is not our own - see whether a process with this PID exists.
32 base::ProcessHandle process = base::kNullProcessHandle;
33 if (base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) {
34 base::CloseProcessHandle(process);
35
36 return true;
37 }
38
39 return false;
40 }
41
42 } // namespace
43
44 const char WatcherMetricsProviderWin::kBrowserExitCodeHistogramName[] =
45 "Stability.BrowserExitCodes";
46
47
48 WatcherMetricsProviderWin::WatcherMetricsProviderWin(
49 const base::char16* registry_path) : registry_path_(registry_path) {
50 }
51
52 WatcherMetricsProviderWin::~WatcherMetricsProviderWin() {
53 }
54
55 void WatcherMetricsProviderWin::ProvideStabilityMetrics(
56 metrics::SystemProfileProto* system_profile_proto) {
57 base::win::RegKey regkey(HKEY_CURRENT_USER,
58 registry_path_.c_str(),
59 KEY_QUERY_VALUE | KEY_SET_VALUE);
60
61 std::vector<base::string16> to_delete;
62 size_t num = regkey.GetValueCount();
63
64 // Record the exit codes in a sparse histogram, as the range of values
65 // used to report failures is large.
66 base::HistogramBase* exit_code_histogram =
67 // TODO(siggi): is this an acceptable name?
68 base::SparseHistogram::FactoryGet(kBrowserExitCodeHistogramName,
69 base::HistogramBase::kUmaStabilityHistogramFlag);
70
71 for (size_t i = 0; i < num; ++i) {
72 base::string16 name;
73 if (regkey.GetValueNameAt(i, &name) == ERROR_SUCCESS) {
74 DWORD exit_code = 0;
75 if (regkey.ReadValueDW(name.c_str(), &exit_code) == ERROR_SUCCESS) {
76 // Do not report exit codes for processes that are still live, notably
77 // not for our own process.
78 if (exit_code != STILL_ACTIVE || !IsLiveProcess(name)) {
79 to_delete.push_back(name);
80 exit_code_histogram->Add(exit_code);
81 }
82 }
83 }
84 }
85
86 // Delete the values reported above.
87 for (size_t i = 0; i < to_delete.size(); ++i)
88 regkey.DeleteValue(to_delete[i].c_str());
89 }
90
91 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698