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

Side by Side Diff: src/platform/crash/crash_reporter.cc

Issue 2037011: Remove the deprecated static metrics APIs. (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: Created 10 years, 7 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
« no previous file with comments | « no previous file | src/platform/metrics/README » ('j') | src/platform/metrics/metrics_library.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "crash/system_logging.h" 10 #include "crash/system_logging.h"
(...skipping 12 matching lines...) Expand all
23 static const char kUncleanShutdownFile[] = 23 static const char kUncleanShutdownFile[] =
24 "/var/lib/crash_reporter/pending_clean_shutdown"; 24 "/var/lib/crash_reporter/pending_clean_shutdown";
25 25
26 // Enumeration of kinds of crashes to be used in the CrashCounter histogram. 26 // Enumeration of kinds of crashes to be used in the CrashCounter histogram.
27 enum CrashKinds { 27 enum CrashKinds {
28 CRASH_KIND_KERNEL = 1, 28 CRASH_KIND_KERNEL = 1,
29 CRASH_KIND_USER = 2, 29 CRASH_KIND_USER = 2,
30 CRASH_KIND_MAX 30 CRASH_KIND_MAX
31 }; 31 };
32 32
33 static MetricsLibrary s_metrics_lib;
33 static SystemLoggingImpl s_system_log; 34 static SystemLoggingImpl s_system_log;
34 35
35 static bool IsMetricsCollectionAllowed() { 36 static bool IsMetricsCollectionAllowed() {
36 // TODO(kmixter): Eventually check system tainted state and 37 // TODO(kmixter): Eventually check system tainted state and
37 // move this down in metrics library where it would be explicitly 38 // move this down in metrics library where it would be explicitly
38 // checked when asked to send stats. 39 // checked when asked to send stats.
39 return true; 40 return true;
40 } 41 }
41 42
42 static void CheckUncleanShutdown() { 43 static void CheckUncleanShutdown() {
43 FilePath unclean_file_path(kUncleanShutdownFile); 44 FilePath unclean_file_path(kUncleanShutdownFile);
44 if (!file_util::PathExists(unclean_file_path)) { 45 if (!file_util::PathExists(unclean_file_path)) {
45 return; 46 return;
46 } 47 }
47 s_system_log.LogWarning("Last shutdown was not clean"); 48 s_system_log.LogWarning("Last shutdown was not clean");
48 if (IsMetricsCollectionAllowed()) { 49 if (IsMetricsCollectionAllowed()) {
49 MetricsLibrary::SendEnumToChrome(std::string(kCrashCounterHistogram), 50 s_metrics_lib.SendEnumToUMA(std::string(kCrashCounterHistogram),
50 CRASH_KIND_KERNEL, 51 CRASH_KIND_KERNEL,
51 CRASH_KIND_MAX); 52 CRASH_KIND_MAX);
52 } 53 }
53 if (!file_util::Delete(unclean_file_path, false)) { 54 if (!file_util::Delete(unclean_file_path, false)) {
54 s_system_log.LogError("Failed to delete unclean shutdown file %s", 55 s_system_log.LogError("Failed to delete unclean shutdown file %s",
55 kUncleanShutdownFile); 56 kUncleanShutdownFile);
56 } 57 }
57 } 58 }
58 59
59 static bool PrepareUncleanShutdownCheck() { 60 static bool PrepareUncleanShutdownCheck() {
60 static const char empty[] = ""; 61 static const char empty[] = "";
61 FilePath file_path(kUncleanShutdownFile); 62 FilePath file_path(kUncleanShutdownFile);
62 file_util::CreateDirectory(file_path.DirName()); 63 file_util::CreateDirectory(file_path.DirName());
63 return file_util::WriteFile(file_path, empty, 0) == 0; 64 return file_util::WriteFile(file_path, empty, 0) == 0;
64 } 65 }
65 66
66 static void SignalCleanShutdown() { 67 static void SignalCleanShutdown() {
67 s_system_log.LogInfo("Clean shutdown signalled"); 68 s_system_log.LogInfo("Clean shutdown signalled");
68 file_util::Delete(FilePath(kUncleanShutdownFile), false); 69 file_util::Delete(FilePath(kUncleanShutdownFile), false);
69 } 70 }
70 71
71 static void CountUserCrash() { 72 static void CountUserCrash() {
72 CHECK(IsMetricsCollectionAllowed()); 73 CHECK(IsMetricsCollectionAllowed());
73 MetricsLibrary::SendEnumToChrome(std::string(kCrashCounterHistogram), 74 s_metrics_lib.SendEnumToUMA(std::string(kCrashCounterHistogram),
74 CRASH_KIND_USER, 75 CRASH_KIND_USER,
75 CRASH_KIND_MAX); 76 CRASH_KIND_MAX);
76 } 77 }
77 78
78 int main(int argc, char *argv[]) { 79 int main(int argc, char *argv[]) {
79 google::ParseCommandLineFlags(&argc, &argv, true); 80 google::ParseCommandLineFlags(&argc, &argv, true);
80 FilePath my_path(argv[0]); 81 FilePath my_path(argv[0]);
81 file_util::AbsolutePath(&my_path); 82 file_util::AbsolutePath(&my_path);
83 s_metrics_lib.Init();
82 s_system_log.Initialize(my_path.BaseName().value().c_str()); 84 s_system_log.Initialize(my_path.BaseName().value().c_str());
83 UserCollector user_collector; 85 UserCollector user_collector;
84 user_collector.Initialize(CountUserCrash, 86 user_collector.Initialize(CountUserCrash,
85 my_path.value(), 87 my_path.value(),
86 IsMetricsCollectionAllowed, 88 IsMetricsCollectionAllowed,
87 &s_system_log); 89 &s_system_log);
88 90
89 if (FLAGS_init) { 91 if (FLAGS_init) {
90 CHECK(!FLAGS_clean_shutdown) << "Incompatible options"; 92 CHECK(!FLAGS_clean_shutdown) << "Incompatible options";
91 user_collector.Enable(); 93 user_collector.Enable();
(...skipping 14 matching lines...) Expand all
106 108
107 // Handle a specific user space crash. 109 // Handle a specific user space crash.
108 CHECK(FLAGS_signal != -1) << "Signal must be set"; 110 CHECK(FLAGS_signal != -1) << "Signal must be set";
109 CHECK(FLAGS_pid != -1) << "PID must be set"; 111 CHECK(FLAGS_pid != -1) << "PID must be set";
110 CHECK(FLAGS_exec != "") << "Executable name must be set"; 112 CHECK(FLAGS_exec != "") << "Executable name must be set";
111 113
112 user_collector.HandleCrash(FLAGS_signal, FLAGS_pid, FLAGS_exec); 114 user_collector.HandleCrash(FLAGS_signal, FLAGS_pid, FLAGS_exec);
113 115
114 return 0; 116 return 0;
115 } 117 }
OLDNEW
« no previous file with comments | « no previous file | src/platform/metrics/README » ('j') | src/platform/metrics/metrics_library.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698