diff --git a/CHANGELOG.md b/CHANGELOG.md index 22846573b..8dd450dcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Removed the `SENTRY_PERFORMANCE_MONITORING` compile flag requirement to access performance monitoring in the Sentry SDK. Performance monitoring is now available to everybody who has opted into the experimental API. - New API to check whether the application has crashed in the previous run: `sentry_get_crashed_last_run()` and `sentry_clear_crashed_last_run()` ([#685](https://github.com/getsentry/sentry-native/pull/685)). - Allow overriding the SDK name at build time - set the `SENTRY_SDK_NAME` CMake cache variable. +- More aggressively prune the Crashpad database. ([#698](https://github.com/getsentry/sentry-native/pull/698)) **Internal**: diff --git a/src/backends/sentry_backend_crashpad.cpp b/src/backends/sentry_backend_crashpad.cpp index dcebd9c7e..c3b20a95f 100644 --- a/src/backends/sentry_backend_crashpad.cpp +++ b/src/backends/sentry_backend_crashpad.cpp @@ -31,6 +31,7 @@ extern "C" { #include "client/crash_report_database.h" #include "client/crashpad_client.h" #include "client/crashpad_info.h" +#include "client/prune_crash_reports.h" #include "client/settings.h" #if defined(__GNUC__) @@ -426,6 +427,22 @@ sentry__crashpad_backend_last_crash(sentry_backend_t *backend) return crash_time; } +static void +sentry__crashpad_backend_prune_database(sentry_backend_t *backend) +{ + crashpad_state_t *data = (crashpad_state_t *)backend->data; + + // We want to eagerly clean up reports older than 2 days, and limit the + // complete database to a maximum of 8M. That might still be a lot for + // an embedded use-case, but minidumps on desktop can sometimes be quite + // large. + data->db->CleanDatabase(60 * 60 * 24 * 2); + crashpad::BinaryPruneCondition condition(crashpad::BinaryPruneCondition::OR, + new crashpad::DatabaseSizePruneCondition(1024 * 8), + new crashpad::AgePruneCondition(2)); + crashpad::PruneCrashReportDatabase(data->db, &condition); +} + sentry_backend_t * sentry__backend_new(void) { @@ -451,6 +468,7 @@ sentry__backend_new(void) backend->user_consent_changed_func = sentry__crashpad_backend_user_consent_changed; backend->get_last_crash_func = sentry__crashpad_backend_last_crash; + backend->prune_database_func = sentry__crashpad_backend_prune_database; backend->data = data; backend->can_capture_after_shutdown = true; diff --git a/src/sentry_backend.h b/src/sentry_backend.h index bb954272a..0c6969278 100644 --- a/src/sentry_backend.h +++ b/src/sentry_backend.h @@ -25,6 +25,7 @@ struct sentry_backend_s { const sentry_options_t *options); void (*user_consent_changed_func)(sentry_backend_t *); uint64_t (*get_last_crash_func)(sentry_backend_t *); + void (*prune_database_func)(sentry_backend_t *); void *data; bool can_capture_after_shutdown; }; diff --git a/src/sentry_core.c b/src/sentry_core.c index 6bcdf8fe1..b476a6693 100644 --- a/src/sentry_core.c +++ b/src/sentry_core.c @@ -182,7 +182,11 @@ sentry_init(sentry_options_t *options) // after initializing the transport, we will submit all the unsent envelopes // and handle remaining sessions. + SENTRY_TRACE("processing and pruning old runs"); sentry__process_old_runs(options, last_crash); + if (backend && backend->prune_database_func) { + backend->prune_database_func(backend); + } if (options->auto_session_tracking) { sentry_start_session();