-
-
Notifications
You must be signed in to change notification settings - Fork 200
feat: offline caching (inproc & breakpad) #1490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
536c4a1
5742eda
6c75ccf
8f3ffd5
3410b6c
799d219
3c40494
a37ac86
20815bd
ef96547
e96d9d4
93aefb2
f4936d5
7eddee4
8d40ec1
b28663f
ab62f90
7bc7856
9e09bd0
747edb1
b1a4671
b101fce
2e1c63b
e0cb46e
317968c
e30846f
1d565d6
76a5f81
f0e5075
25da5e1
fc0f6cc
57cb740
fd3c257
8a17813
5ece6d5
6a80d77
dd0ef77
bbfb4d2
43450d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -744,19 +744,70 @@ crashpad_backend_last_crash(sentry_backend_t *backend) | |
| return crash_time; | ||
| } | ||
|
|
||
| class CachePruneCondition final : public crashpad::PruneCondition { | ||
| public: | ||
| CachePruneCondition(size_t max_items, size_t max_size, time_t max_age) | ||
| : max_items_(max_items) | ||
| , item_count_(0) | ||
| , max_size_(max_size) | ||
| , measured_size_(0) | ||
| , max_age_(max_age) | ||
| , oldest_report_time_(time(nullptr) - max_age) | ||
| { | ||
| } | ||
|
|
||
| bool | ||
| ShouldPruneReport( | ||
| const crashpad::CrashReportDatabase::Report &report) override | ||
| { | ||
| ++item_count_; | ||
| measured_size_ += static_cast<size_t>(report.total_size); | ||
|
|
||
| bool by_items = max_items_ > 0 && item_count_ > max_items_; | ||
| bool by_size = max_size_ > 0 && measured_size_ > max_size_; | ||
| bool by_age | ||
| = max_age_ > 0 && report.creation_time < oldest_report_time_; | ||
| return by_items || by_size || by_age; | ||
| } | ||
|
|
||
| private: | ||
| const size_t max_items_; | ||
| size_t item_count_; | ||
| const size_t max_size_; | ||
| size_t measured_size_; | ||
| const time_t max_age_; | ||
| const time_t oldest_report_time_; | ||
| }; | ||
|
|
||
| static void | ||
| crashpad_backend_prune_database(sentry_backend_t *backend) | ||
| { | ||
| auto *data = static_cast<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)); | ||
| // For backwards compatibility, default to the parameters that were used | ||
| // before the offline caching API was introduced. We wanted to eagerly | ||
| // clean up reports older than 2 days, and limit the complete database | ||
| // to a maximum of 8M. That might still have been a lot for an embedded | ||
| // use-case, but minidumps on desktop can sometimes be quite large. | ||
| time_t max_age = 2 * 24 * 60 * 60; // 2 days | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe extracting these constants somewhere would make sense (instead of keeping them as crashpad-only defaults in a function)?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are just some legacy defaults that were used by the crashpad backend before offline caching was introduced. These defaults are specific to the crashpad backend and are not used anywhere else. The idea is to retain full backwards compatibility by using the old legacy defaults unless the user opts in for offline caching. I updated the comments - I hope it's clear now :) |
||
| size_t max_size = 8 * 1024 * 1024; // 8 MB | ||
| size_t max_items = 0; | ||
|
|
||
| // When offline caching is enabled, the user has full control over these | ||
| // parameters via the cache_max_* options. | ||
| SENTRY_WITH_OPTIONS (options) { | ||
| if (options->cache_keep) { | ||
| max_age = options->cache_max_age; | ||
| max_size = options->cache_max_size; | ||
| max_items = options->cache_max_items; | ||
| } | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (max_age > 0) { | ||
| data->db->CleanDatabase(max_age); | ||
| } | ||
|
|
||
| CachePruneCondition condition(max_items, max_size, max_age); | ||
| crashpad::PruneCrashReportDatabase(data->db, &condition); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.