From 8361935de89a5092cfb54245e55e454981f99f11 Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Wed, 2 Dec 2015 14:38:43 -0800 Subject: [PATCH] crash_reporter: use libmetricscollectorservice for user crash event reports Drop dependencies on D-Bus. Bug: 25929888 Change-Id: Ie21c2feee098887ebb2dac14c866e28689e9343e --- crash_reporter/Android.mk | 15 ++++++------ crash_reporter/crash_reporter.cc | 40 ++++++++++---------------------- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/crash_reporter/Android.mk b/crash_reporter/Android.mk index 81cb458f5..565963cbc 100644 --- a/crash_reporter/Android.mk +++ b/crash_reporter/Android.mk @@ -43,11 +43,12 @@ LOCAL_CPP_EXTENSION := $(crash_reporter_cpp_extension) LOCAL_C_INCLUDES := $(crash_reporter_includes) LOCAL_RTTI_FLAG := -frtti LOCAL_SHARED_LIBRARIES := libchrome \ + libbinder \ libbrillo \ libcutils \ - libdbus \ libmetrics \ libpcrecpp +LOCAL_STATIC_LIBRARIES := libmetricscollectorservice LOCAL_SRC_FILES := $(crash_reporter_src) include $(BUILD_STATIC_LIBRARY) @@ -60,18 +61,19 @@ LOCAL_C_INCLUDES := $(crash_reporter_includes) LOCAL_REQUIRED_MODULES := core2md \ crash_reporter_logs.conf \ crash_sender \ - crash_server \ - dbus-send + crash_server LOCAL_INIT_RC := crash_reporter.rc LOCAL_RTTI_FLAG := -frtti LOCAL_SHARED_LIBRARIES := libchrome \ + libbinder \ libbrillo \ libcutils \ - libdbus \ libmetrics \ - libpcrecpp + libpcrecpp \ + libutils LOCAL_SRC_FILES := crash_reporter.cc -LOCAL_STATIC_LIBRARIES := libcrash +LOCAL_STATIC_LIBRARIES := libcrash \ + libmetricscollectorservice include $(BUILD_EXECUTABLE) # Crash sender script. @@ -140,7 +142,6 @@ LOCAL_CPP_EXTENSION := $(crash_reporter_cpp_extension) LOCAL_SHARED_LIBRARIES := libchrome \ libbrillo \ libcutils \ - libdbus \ libpcrecpp LOCAL_SRC_FILES := $(crash_reporter_test_src) LOCAL_STATIC_LIBRARIES := libcrash libgmock diff --git a/crash_reporter/crash_reporter.cc b/crash_reporter/crash_reporter.cc index 3955fe54b..26ffa3803 100644 --- a/crash_reporter/crash_reporter.cc +++ b/crash_reporter/crash_reporter.cc @@ -25,10 +25,13 @@ #include #include #include +#include #include -#include #include +#include #include +#include + #include "kernel_collector.h" #include "kernel_warning_collector.h" @@ -37,8 +40,6 @@ #include "user_collector.h" static const char kCrashCounterHistogram[] = "Logging.CrashCounter"; -static const char kUserCrashSignal[] = - "org.chromium.CrashReporter.UserCrash"; static const char kKernelCrashDetected[] = "/var/run/kernel-crash-detected"; static const char kUncleanShutdownDetected[] = "/var/run/unclean-shutdown-detected"; @@ -56,6 +57,7 @@ enum CrashKinds { static MetricsLibrary s_metrics_lib; +using android::brillo::metrics::IMetricsCollectorService; using base::FilePath; using base::StringPrintf; @@ -88,32 +90,14 @@ static void CountUncleanShutdown() { static void CountUserCrash() { SendCrashMetrics(kCrashKindUser, "user"); - // Announce through D-Bus whenever a user crash happens. This is - // used by the metrics daemon to log active use time between - // crashes. - // - // We run in the background in case dbus-daemon itself is crashed - // and not responding. This allows us to not block and potentially - // deadlock on a dbus-daemon crash. If dbus-daemon crashes without - // restarting, each crash will fork off a lot of dbus-send - // processes. Such a system is in a unusable state and will need - // to be restarted anyway. - // - // Note: This will mean that the dbus-send process will become a zombie and - // reparent to init for reaping, but that's OK -- see above. + // Tell the metrics collector about the user crash, in order to log active + // use time between crashes. + MetricsCollectorServiceClient metrics_collector_service; - brillo::ProcessImpl dbus_send; - dbus_send.AddArg("/system/bin/dbus-send"); - dbus_send.AddArg("--type=signal"); - dbus_send.AddArg("--system"); - dbus_send.AddArg("/"); - dbus_send.AddArg(kUserCrashSignal); - bool status = dbus_send.Start(); - if (status) { - dbus_send.Release(); - } else { - PLOG(WARNING) << "Sending UserCrash DBus signal failed"; - } + if (metrics_collector_service.Init()) + metrics_collector_service.notifyUserCrash(); + else + LOG(ERROR) << "Failed to send user crash notification to metrics_collector"; }