| Index: webkit/quota/quota_temporary_storage_evictor.cc
|
| diff --git a/webkit/quota/quota_temporary_storage_evictor.cc b/webkit/quota/quota_temporary_storage_evictor.cc
|
| index d9e9fec0b33739aff562d48e31ae6e5e00561d3f..97862aa8f95402c7db9211faebd60ab8f299477b 100644
|
| --- a/webkit/quota/quota_temporary_storage_evictor.cc
|
| +++ b/webkit/quota/quota_temporary_storage_evictor.cc
|
| @@ -64,19 +64,59 @@ void QuotaTemporaryStorageEvictor::GetStatistics(
|
| statistics_.num_skipped_eviction_rounds;
|
| }
|
|
|
| -void QuotaTemporaryStorageEvictor::ReportHistogram() {
|
| - UMA_HISTOGRAM_COUNTS("Quota.ErrorsOnEvictingOrigin",
|
| - statistics_.num_errors_on_evicting_origin);
|
| - UMA_HISTOGRAM_COUNTS("Quota.ErrorsOnGettingUsageAndQuota",
|
| - statistics_.num_errors_on_getting_usage_and_quota);
|
| - UMA_HISTOGRAM_COUNTS("Quota.EvictedOrigins",
|
| - statistics_.num_evicted_origins);
|
| - UMA_HISTOGRAM_COUNTS("Quota.EvictionRounds",
|
| - statistics_.num_eviction_rounds);
|
| - UMA_HISTOGRAM_COUNTS("Quota.SkippedEvictionRounds",
|
| - statistics_.num_skipped_eviction_rounds);
|
| -
|
| - statistics_ = Statistics();
|
| +void QuotaTemporaryStorageEvictor::ReportPerRoundHistogram() {
|
| + base::Time now = base::Time::Now();
|
| + UMA_HISTOGRAM_TIMES("Quota.TimeSpentToAEvictionRound",
|
| + now - round_statistics_.start_time);
|
| + if (!time_of_end_of_last_round_.is_null())
|
| + UMA_HISTOGRAM_MINUTES("Quota.TimeDeltaOfEvictionRounds",
|
| + now - time_of_end_of_last_round_);
|
| + UMA_HISTOGRAM_MBYTES("Quota.AmountOfOverageOfTemporaryGlobalStorage",
|
| + round_statistics_.amount_of_usage_overage);
|
| + UMA_HISTOGRAM_MBYTES("Quota.AmountOfShortageOfDiskspace",
|
| + round_statistics_.amount_of_diskspace_shortage);
|
| + UMA_HISTOGRAM_MBYTES("Quota.EvictedBytesPerRound",
|
| + round_statistics_.usage_on_beginning_of_round -
|
| + round_statistics_.usage_on_end_of_round);
|
| + UMA_HISTOGRAM_COUNTS("Quota.NumberOfEvictedOriginsPerRound",
|
| + round_statistics_.num_evicted_origins);
|
| + round_statistics_ = EvictionRoundStatistics();
|
| +}
|
| +
|
| +void QuotaTemporaryStorageEvictor::ReportPerHourHistogram() {
|
| + Statistics stats(statistics_);
|
| + stats -= reported_hourly_statistics_;
|
| + reported_hourly_statistics_ = statistics_;
|
| +
|
| + UMA_HISTOGRAM_COUNTS("Quota.ErrorsOnEvictingOriginPerHour",
|
| + stats.num_errors_on_evicting_origin);
|
| + UMA_HISTOGRAM_COUNTS("Quota.ErrorsOnGettingUsageAndQuotaPerHour",
|
| + stats.num_errors_on_getting_usage_and_quota);
|
| + UMA_HISTOGRAM_COUNTS("Quota.EvictedOriginsPerHour",
|
| + stats.num_evicted_origins);
|
| + UMA_HISTOGRAM_COUNTS("Quota.EvictionRoundsPerHour",
|
| + stats.num_eviction_rounds);
|
| + UMA_HISTOGRAM_COUNTS("Quota.SkippedEvictionRoundsPerHour",
|
| + stats.num_skipped_eviction_rounds);
|
| +}
|
| +
|
| +void QuotaTemporaryStorageEvictor::OnEvictionRoundStarted() {
|
| + if (round_statistics_.started)
|
| + return;
|
| + round_statistics_.started = true;
|
| + round_statistics_.start_time = base::Time::Now();
|
| + ++statistics_.num_eviction_rounds;
|
| +}
|
| +
|
| +void QuotaTemporaryStorageEvictor::OnEvictionRoundFinished() {
|
| + // Check if skipped round
|
| + if (round_statistics_.num_evicted_origins) {
|
| + ReportPerRoundHistogram();
|
| + time_of_last_nonskipped_round_ = base::Time::Now();
|
| + } else {
|
| + ++statistics_.num_skipped_eviction_rounds;
|
| + round_statistics_ = EvictionRoundStatistics();
|
| + }
|
| }
|
|
|
| void QuotaTemporaryStorageEvictor::Start() {
|
| @@ -86,21 +126,19 @@ void QuotaTemporaryStorageEvictor::Start() {
|
| if (histogram_timer_.IsRunning())
|
| return;
|
| histogram_timer_.Start(kHistogramReportInterval, this,
|
| - &QuotaTemporaryStorageEvictor::ReportHistogram);
|
| + &QuotaTemporaryStorageEvictor::ReportPerHourHistogram);
|
| }
|
|
|
| void QuotaTemporaryStorageEvictor::StartEvictionTimerWithDelay(int delay_ms) {
|
| if (eviction_timer_.IsRunning())
|
| return;
|
| - num_evicted_origins_in_round_ = 0;
|
| - usage_on_beginning_of_round_ = -1;
|
| - time_of_beginning_of_round_ = base::Time::Now();
|
| - ++statistics_.num_eviction_rounds;
|
| eviction_timer_.Start(base::TimeDelta::FromMilliseconds(delay_ms), this,
|
| &QuotaTemporaryStorageEvictor::ConsiderEviction);
|
| }
|
|
|
| void QuotaTemporaryStorageEvictor::ConsiderEviction() {
|
| + OnEvictionRoundStarted();
|
| +
|
| // Get usage and disk space, then continue.
|
| quota_eviction_handler_->GetUsageAndQuotaForEviction(callback_factory_.
|
| NewCallback(
|
| @@ -121,49 +159,39 @@ void QuotaTemporaryStorageEvictor::OnGotUsageAndQuotaForEviction(
|
| if (status != kQuotaStatusOk)
|
| ++statistics_.num_errors_on_getting_usage_and_quota;
|
|
|
| - int64 amount_to_evict = std::max(
|
| - usage - static_cast<int64>(quota * kUsageRatioToStartEviction),
|
| + int64 amount_of_usage_overage = std::max(
|
| + static_cast<int64>(0),
|
| + usage - static_cast<int64>(quota * kUsageRatioToStartEviction));
|
| + round_statistics_.put_usage_overage(amount_of_usage_overage);
|
| +
|
| + int64 amount_of_diskspace_shortage = std::max(
|
| + static_cast<int64>(0),
|
| min_available_disk_space_to_start_eviction_ - available_disk_space);
|
| + round_statistics_.put_diskspace_shortage(amount_of_diskspace_shortage);
|
| + round_statistics_.put_usage(usage);
|
| +
|
| + int64 amount_to_evict = std::max(amount_of_usage_overage,
|
| + amount_of_diskspace_shortage);
|
| if (status == kQuotaStatusOk && amount_to_evict > 0) {
|
| // Space is getting tight. Get the least recently used origin and continue.
|
| // TODO(michaeln): if the reason for eviction is low physical disk space,
|
| // make 'unlimited' origins subject to eviction too.
|
| -
|
| - if (usage_on_beginning_of_round_ < 0) {
|
| - usage_on_beginning_of_round_ = usage;
|
| - UMA_HISTOGRAM_MBYTES("Quota.TemporaryStorageSizeToEvict",
|
| - amount_to_evict);
|
| - }
|
| -
|
| quota_eviction_handler_->GetLRUOrigin(kStorageTypeTemporary,
|
| callback_factory_.NewCallback(
|
| &QuotaTemporaryStorageEvictor::OnGotLRUOrigin));
|
| - } else if (repeated_eviction_) {
|
| - // No action required, sleep for a while and check again later.
|
| - if (num_evicted_origins_in_round_ == 0) {
|
| - ++statistics_.num_skipped_eviction_rounds;
|
| - } else if (usage_on_beginning_of_round_ >= 0) {
|
| - int64 evicted_bytes = usage_on_beginning_of_round_ - usage;
|
| - base::Time now = base::Time::Now();
|
| - UMA_HISTOGRAM_MBYTES("Quota.EvictedBytesPerRound", evicted_bytes);
|
| - UMA_HISTOGRAM_COUNTS("Quota.NumberOfEvictedOriginsPerRound",
|
| - num_evicted_origins_in_round_);
|
| - UMA_HISTOGRAM_TIMES("Quota.TimeSpentToAEvictionRound",
|
| - now - time_of_beginning_of_round_);
|
| - if (!time_of_end_of_last_round_.is_null()) {
|
| - UMA_HISTOGRAM_MINUTES("Quota.TimeDeltaOfEvictionRounds",
|
| - now - time_of_end_of_last_round_);
|
| + } else {
|
| + if (repeated_eviction_) {
|
| + // No action required, sleep for a while and check again later.
|
| + if (statistics_.num_errors_on_getting_usage_and_quota <
|
| + kThresholdOfErrorsToStopEviction) {
|
| + StartEvictionTimerWithDelay(interval_ms_);
|
| + } else {
|
| + // TODO(dmikurube): Try restarting eviction after a while.
|
| + LOG(WARNING) << "Stopped eviction of temporary storage due to errors "
|
| + "in GetUsageAndQuotaForEviction.";
|
| }
|
| - time_of_end_of_last_round_ = now;
|
| - }
|
| - if (statistics_.num_errors_on_getting_usage_and_quota <
|
| - kThresholdOfErrorsToStopEviction) {
|
| - StartEvictionTimerWithDelay(interval_ms_);
|
| - } else {
|
| - // TODO(dmikurube): Try restarting eviction after a while.
|
| - LOG(WARNING) << "Stopped eviction of temporary storage due to errors "
|
| - "in GetUsageAndQuotaForEviction.";
|
| }
|
| + OnEvictionRoundFinished();
|
| }
|
|
|
| // TODO(dmikurube): Add error handling for the case status != kQuotaStatusOk.
|
| @@ -175,6 +203,7 @@ void QuotaTemporaryStorageEvictor::OnGotLRUOrigin(const GURL& origin) {
|
| if (origin.is_empty()) {
|
| if (repeated_eviction_)
|
| StartEvictionTimerWithDelay(interval_ms_);
|
| + OnEvictionRoundFinished();
|
| return;
|
| }
|
|
|
| @@ -195,7 +224,7 @@ void QuotaTemporaryStorageEvictor::OnEvictionComplete(
|
|
|
| if (status == kQuotaStatusOk) {
|
| ++statistics_.num_evicted_origins;
|
| - ++num_evicted_origins_in_round_;
|
| + ++round_statistics_.num_evicted_origins;
|
| // We many need to get rid of more space so reconsider immediately.
|
| ConsiderEviction();
|
| } else {
|
| @@ -204,6 +233,7 @@ void QuotaTemporaryStorageEvictor::OnEvictionComplete(
|
| // Sleep for a while and retry again until we see too many errors.
|
| StartEvictionTimerWithDelay(interval_ms_);
|
| }
|
| + OnEvictionRoundFinished();
|
| }
|
| }
|
|
|
|
|