Upstream Chromium UMA integration

Unmodified from https://codereview.chromium.org/2308763002/ other than
to add empty arguments to test code (that doesn't build in Chrome).

Requires https://chromium-review.googlesource.com/c/386236/.

Rolls mini_chromium to include:
438bd4f4 Add stub of persistent_histogram_allocator.h

R=mark@chromium.org
BUG=crashpad:100

Change-Id: Ibc88338ae2fd40a5a4ade7ff098be2bc19511543
Reviewed-on: https://chromium-review.googlesource.com/386084
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Scott Graham 2016-09-16 13:21:50 -07:00
parent 0c29022090
commit 27aeb2c9da
7 changed files with 52 additions and 2 deletions

2
DEPS
View File

@ -25,7 +25,7 @@ deps = {
'93cc6e2c23e4d5ebd179f388e67aa907d0dfd43d',
'crashpad/third_party/mini_chromium/mini_chromium':
Var('chromium_git') + '/chromium/mini_chromium@' +
'7800285e83df4286981bb933e3335edade7c8308',
'438bd4f4d8d38dd5c31e78a0d605cc4cf6be5229',
'buildtools':
Var('chromium_git') + '/chromium/buildtools.git@' +
'f8fc76ea5ce4a60cda2fa5d7df3d4a62935b3113',

View File

@ -55,6 +55,9 @@ class CrashpadClient {
//! \param[in] handler The path to a Crashpad handler executable.
//! \param[in] database The path to a Crashpad database. The handler will be
//! started with this path as its `--database` argument.
//! \param[in] metrics_dir The path to an already existing directory where
//! metrics files can be stored. The handler will be started with this
//! path as its `--metrics-dir` argument.
//! \param[in] url The URL of an upload server. The handler will be started
//! with this URL as its `--url` argument.
//! \param[in] annotations Process annotations to set in each crash report.
@ -72,6 +75,7 @@ class CrashpadClient {
//! \return `true` on success, `false` on failure with a message logged.
bool StartHandler(const base::FilePath& handler,
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,

View File

@ -121,6 +121,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
static base::mac::ScopedMachSendRight InitialStart(
const base::FilePath& handler,
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
@ -159,6 +160,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
if (!CommonStart(handler,
database,
metrics_dir,
url,
annotations,
arguments,
@ -170,7 +172,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
if (handler_restarter &&
handler_restarter->StartRestartThread(
handler, database, url, annotations, arguments)) {
handler, database, metrics_dir, url, annotations, arguments)) {
// The thread owns the object now.
ignore_result(handler_restarter.release());
}
@ -201,6 +203,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
// be called again for another try.
CommonStart(handler_,
database_,
metrics_dir_,
url_,
annotations_,
arguments_,
@ -216,6 +219,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
: NotifyServer::DefaultInterface(),
handler_(),
database_(),
metrics_dir_(),
url_(),
annotations_(),
arguments_(),
@ -244,6 +248,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
//! rendezvous with it via ChildPortHandshake.
static bool CommonStart(const base::FilePath& handler,
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
@ -320,6 +325,9 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
if (!database.value().empty()) {
argv.push_back(FormatArgumentString("database", database.value()));
}
if (!metrics_dir.value().empty()) {
argv.push_back(FormatArgumentString("metrics-dir", metrics_dir.value()));
}
if (!url.empty()) {
argv.push_back(FormatArgumentString("url", url));
}
@ -445,11 +453,13 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
bool StartRestartThread(const base::FilePath& handler,
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments) {
handler_ = handler;
database_ = database;
metrics_dir_ = metrics_dir;
url_ = url;
annotations_ = annotations;
arguments_ = arguments;
@ -501,6 +511,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
base::FilePath handler_;
base::FilePath database_;
base::FilePath metrics_dir_;
std::string url_;
std::map<std::string, std::string> annotations_;
std::vector<std::string> arguments_;
@ -522,6 +533,7 @@ CrashpadClient::~CrashpadClient() {
bool CrashpadClient::StartHandler(
const base::FilePath& handler,
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
@ -534,6 +546,7 @@ bool CrashpadClient::StartHandler(
base::mac::ScopedMachSendRight exception_port(
HandlerStarter::InitialStart(handler,
database,
metrics_dir,
url,
annotations,
arguments,

View File

@ -200,6 +200,7 @@ CrashpadClient::~CrashpadClient() {
bool CrashpadClient::StartHandler(
const base::FilePath& handler,
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
@ -232,6 +233,11 @@ bool CrashpadClient::StartHandler(
database.value()),
&command_line);
}
if (!metrics_dir.value().empty()) {
AppendCommandLineArgument(
FormatArgumentString("metrics-dir", metrics_dir.value()),
&command_line);
}
if (!url.empty()) {
AppendCommandLineArgument(FormatArgumentString("url",
base::UTF8ToUTF16(url)),

View File

@ -31,6 +31,7 @@ void StartAndUseHandler() {
CrashpadClient client;
ASSERT_TRUE(client.StartHandler(handler_path,
temp_dir.path(),
base::FilePath(),
"",
std::map<std::string, std::string>(),
std::vector<std::string>(),

View File

@ -27,6 +27,7 @@
#include "base/files/file_path.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/metrics/persistent_histogram_allocator.h"
#include "base/scoped_generic.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
@ -78,6 +79,7 @@ void Usage(const base::FilePath& me) {
" --handshake-handle=HANDLE\n"
" create a new pipe and send its name via HANDLE\n"
#endif // OS_MACOSX
" --metrics-dir=DIR store metrics files in DIR (only in Chromium)\n"
" --no-rate-limit don't rate limit crash uploads\n"
#if defined(OS_MACOSX)
" --reset-own-crash-exception-port-to-system-default\n"
@ -136,6 +138,7 @@ int HandlerMain(int argc, char* argv[]) {
#elif defined(OS_WIN)
kOptionHandshakeHandle,
#endif // OS_MACOSX
kOptionMetrics,
kOptionNoRateLimit,
#if defined(OS_MACOSX)
kOptionResetOwnCrashExceptionPortToSystemDefault,
@ -153,6 +156,7 @@ int HandlerMain(int argc, char* argv[]) {
std::map<std::string, std::string> annotations;
std::string url;
const char* database;
const char* metrics;
#if defined(OS_MACOSX)
int handshake_fd;
std::string mach_service;
@ -179,6 +183,7 @@ int HandlerMain(int argc, char* argv[]) {
#elif defined(OS_WIN)
{"handshake-handle", required_argument, nullptr, kOptionHandshakeHandle},
#endif // OS_MACOSX
{"metrics-dir", required_argument, nullptr, kOptionMetrics},
{"no-rate-limit", no_argument, nullptr, kOptionNoRateLimit},
#if defined(OS_MACOSX)
{"reset-own-crash-exception-port-to-system-default",
@ -243,6 +248,10 @@ int HandlerMain(int argc, char* argv[]) {
break;
}
#endif // OS_MACOSX
case kOptionMetrics: {
options.metrics = optarg;
break;
}
case kOptionNoRateLimit: {
options.rate_limit = false;
break;
@ -386,6 +395,19 @@ int HandlerMain(int argc, char* argv[]) {
}
#endif // OS_MACOSX
base::GlobalHistogramAllocator* histogram_allocator = nullptr;
if (options.metrics) {
const base::FilePath metrics_dir(
ToolSupport::CommandLineArgumentToFilePathStringType(options.metrics));
static const char kMetricsName[] = "CrashpadMetrics";
const size_t kMetricsFileSize = 1 << 20;
if (base::GlobalHistogramAllocator::CreateWithActiveFileInDir(
metrics_dir, kMetricsFileSize, 0, kMetricsName)) {
histogram_allocator = base::GlobalHistogramAllocator::Get();
histogram_allocator->CreateTrackingHistograms(kMetricsName);
}
}
std::unique_ptr<CrashReportDatabase> database(CrashReportDatabase::Initialize(
base::FilePath(ToolSupport::CommandLineArgumentToFilePathStringType(
options.database))));
@ -412,6 +434,9 @@ int HandlerMain(int argc, char* argv[]) {
upload_thread.Stop();
prune_thread.Stop();
if (histogram_allocator)
histogram_allocator->DeletePersistentLocation();
return EXIT_SUCCESS;
}

View File

@ -178,6 +178,7 @@ int CrashyMain(int argc, wchar_t* argv[]) {
} else if (argc == 3) {
if (!client.StartHandler(base::FilePath(argv[1]),
base::FilePath(argv[2]),
base::FilePath(),
std::string(),
std::map<std::string, std::string>(),
std::vector<std::string>(),