Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(644)

Unified Diff: components/offline_pages/offline_page_model.cc

Issue 2022283003: Record offline histograms with suffix via Histogram::FactoryGet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change to use Histogram::FactoryGet Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/offline_page_model.cc
diff --git a/components/offline_pages/offline_page_model.cc b/components/offline_pages/offline_page_model.cc
index af39f37a8fd0d318eb0679a3ab940a786be1617e..6f4ecbf5f945d7e1f861e3959cd199e1e98e2f20 100644
--- a/components/offline_pages/offline_page_model.cc
+++ b/components/offline_pages/offline_page_model.cc
@@ -19,6 +19,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "components/offline_pages/archive_manager.h"
+#include "components/offline_pages/client_namespace_constants.h"
dewittj 2016/05/31 23:12:01 This can be removed once you finish porting Offlin
jianli 2016/05/31 23:50:08 Done.
#include "components/offline_pages/client_policy_controller.h"
#include "components/offline_pages/offline_page_item.h"
#include "components/offline_pages/offline_page_storage_manager.h"
@@ -122,6 +123,90 @@ void ReportStorageHistogramsAfterDelete(
}
}
+void ReportPageHistogramAfterSave(const ClientId& client_id,
+ SavePageResult result) {
+ // The histogram below is an expansion of the UMA_HISTOGRAM_ENUMERATION
+ // macro adapted to allow for a dynamically suffixed histogram name.
+ // Note: The factory creates and owns the histogram.
+ base::HistogramBase* histogram = base::LinearHistogram::FactoryGet(
+ AddHistogramSuffix(client_id, "OfflinePages.SavePageResult"),
+ 1,
+ static_cast<int>(SavePageResult::RESULT_COUNT),
+ static_cast<int>(SavePageResult::RESULT_COUNT) + 1,
+ base::HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add(static_cast<int>(result));
+}
+
+void ReportPageHistogramsAfterDelete(
+ const std::map<int64_t, OfflinePageItem>& offline_pages,
+ const std::vector<int64_t>& deleted_offline_ids) {
+ const int max_minutes = base::TimeDelta::FromDays(365).InMinutes();
+ base::Time now = base::Time::Now();
+ int64_t total_size = 0;
+ for (int64_t offline_id : deleted_offline_ids) {
+ auto iter = offline_pages.find(offline_id);
+ if (iter == offline_pages.end())
+ continue;
+ total_size += iter->second.file_size;
+ ClientId client_id = iter->second.client_id;
+
+ // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
+ // macro adapted to allow for a dynamically suffixed histogram name.
+ // Note: The factory creates and owns the histogram.
+ base::HistogramBase* histogram = base::Histogram::FactoryGet(
+ AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"),
+ 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add((now - iter->second.creation_time).InMinutes());
+
+ histogram = base::Histogram::FactoryGet(
+ AddHistogramSuffix(
+ client_id, "OfflinePages.DeletePage.TimeSinceLastOpen"),
+ 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add((now - iter->second.last_access_time).InMinutes());
+
+ histogram = base::Histogram::FactoryGet(
+ AddHistogramSuffix(
+ client_id, "OfflinePages.DeletePage.LastOpenToCreated"),
+ 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add(
+ (iter->second.last_access_time - iter->second.creation_time).
+ InMinutes());
+
+ histogram = base::Histogram::FactoryGet(
+ AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"),
+ 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add(iter->second.file_size / 1024);
+
+ histogram = base::Histogram::FactoryGet(
+ AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"),
+ 1, 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add(iter->second.access_count);
+ }
+
+ if (deleted_offline_ids.size() > 1) {
+ UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count",
+ static_cast<int32_t>(deleted_offline_ids.size()));
+ UMA_HISTOGRAM_MEMORY_KB(
+ "OfflinePages.BatchDelete.TotalPageSize", total_size / 1024);
+ }
+}
+
+void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item) {
+ // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
+ // macro adapted to allow for a dynamically suffixed histogram name.
+ // Note: The factory creates and owns the histogram.
+ base::HistogramBase* histogram = base::Histogram::FactoryGet(
+ AddHistogramSuffix(
+ offline_page_item.client_id,
+ offline_page_item.access_count == 0 ?
+ "OfflinePages.FirstOpenSinceCreated" :
+ "OfflinePages.OpenSinceLastOpen"),
+ 1, kMaxOpenedPageHistogramBucket.InMinutes(), 50,
+ base::HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add(
+ (base::Time::Now() - offline_page_item.last_access_time).InMinutes());
+}
+
} // namespace
// static
@@ -201,22 +286,9 @@ void OfflinePageModel::MarkPageAccessed(int64_t offline_id) {
// be updated upon the successful store operation.
OfflinePageItem offline_page_item = iter->second;
- base::Time now = base::Time::Now();
- base::TimeDelta time_since_last_accessed =
- now - offline_page_item.last_access_time;
-
- // When the access account is still zero, the page is opened for the first
- // time since its creation.
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- AddHistogramSuffix(
- offline_page_item.client_id,
- (offline_page_item.access_count == 0) ?
- "OfflinePages.FirstOpenSinceCreated" :
- "OfflinePages.OpenSinceLastOpen").c_str(),
- time_since_last_accessed.InMinutes(), 1,
- kMaxOpenedPageHistogramBucket.InMinutes(), 50);
-
- offline_page_item.last_access_time = now;
+ ReportPageHistogramsAfterAccess(offline_page_item);
+
+ offline_page_item.last_access_time = base::Time::Now();
offline_page_item.access_count++;
store_->AddOrUpdateOfflinePage(
@@ -602,14 +674,25 @@ void OfflinePageModel::OnAddOfflinePageDone(OfflinePageArchiver* archiver,
if (success) {
offline_pages_[offline_page.offline_id] = offline_page;
result = SavePageResult::SUCCESS;
- UMA_HISTOGRAM_TIMES(
- AddHistogramSuffix(
- offline_page.client_id, "OfflinePages.SavePageTime").c_str(),
- base::Time::Now() - offline_page.creation_time);
- // 50 buckets capped between 1Kb and 10Mb.
- UMA_HISTOGRAM_COUNTS_10000(AddHistogramSuffix(
- offline_page.client_id, "OfflinePages.PageSize").c_str(),
- offline_page.file_size / 1024);
+ if (offline_page.client_id.name_space == kBookmarkNamespace) {
+ UMA_HISTOGRAM_TIMES("OfflinePages.SavePageTime.bookmark",
dewittj 2016/05/31 22:38:45 should port this to Histogram::FactoryGet as well.
jianli 2016/05/31 23:50:08 Done.
+ base::Time::Now() - offline_page.creation_time);
+ // 50 buckets capped between 1Kb and 10Mb.
+ UMA_HISTOGRAM_COUNTS_10000("OfflinePages.PageSize.bookmark",
+ offline_page.file_size / 1024);
+ } else if (offline_page.client_id.name_space == kLastNNamespace) {
+ UMA_HISTOGRAM_TIMES("OfflinePages.SavePageTime.last_n",
+ base::Time::Now() - offline_page.creation_time);
+ // 50 buckets capped between 1Kb and 10Mb.
+ UMA_HISTOGRAM_COUNTS_10000("OfflinePages.PageSize.last_n",
+ offline_page.file_size / 1024);
+ } else {
+ UMA_HISTOGRAM_TIMES("OfflinePages.SavePageTime",
+ base::Time::Now() - offline_page.creation_time);
+ // 50 buckets capped between 1Kb and 10Mb.
+ UMA_HISTOGRAM_COUNTS_10000("OfflinePages.PageSize",
+ offline_page.file_size / 1024);
+ }
} else {
result = SavePageResult::STORE_FAILURE;
}
@@ -672,10 +755,7 @@ void OfflinePageModel::InformSavePageDone(const SavePageCallback& callback,
SavePageResult result,
const ClientId& client_id,
int64_t offline_id) {
- UMA_HISTOGRAM_ENUMERATION(
- AddHistogramSuffix(client_id, "OfflinePages.SavePageResult").c_str(),
- static_cast<int>(result),
- static_cast<int>(SavePageResult::RESULT_COUNT));
+ ReportPageHistogramAfterSave(client_id, result);
archive_manager_->GetStorageStats(
base::Bind(&ReportStorageHistogramsAfterSave));
callback.Run(result, offline_id);
@@ -705,56 +785,20 @@ void OfflinePageModel::OnRemoveOfflinePagesDone(
const std::vector<int64_t>& offline_ids,
const DeletePageCallback& callback,
bool success) {
+ ReportPageHistogramsAfterDelete(offline_pages_, offline_ids);
+
// Delete the offline page from the in memory cache regardless of success in
// store.
- base::Time now = base::Time::Now();
- int64_t total_size = 0;
for (int64_t offline_id : offline_ids) {
auto iter = offline_pages_.find(offline_id);
if (iter == offline_pages_.end())
continue;
- total_size += iter->second.file_size;
- ClientId client_id = iter->second.client_id;
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- AddHistogramSuffix(client_id, "OfflinePages.PageLifetime").c_str(),
- (now - iter->second.creation_time).InMinutes(),
- 1,
- base::TimeDelta::FromDays(365).InMinutes(),
- 100);
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- AddHistogramSuffix(
- client_id, "OfflinePages.DeletePage.TimeSinceLastOpen").c_str(),
- (now - iter->second.last_access_time).InMinutes(),
- 1,
- base::TimeDelta::FromDays(365).InMinutes(),
- 100);
- UMA_HISTOGRAM_CUSTOM_COUNTS(
- AddHistogramSuffix(
- client_id, "OfflinePages.DeletePage.LastOpenToCreated").c_str(),
- (iter->second.last_access_time - iter->second.creation_time).
- InMinutes(),
- 1,
- base::TimeDelta::FromDays(365).InMinutes(),
- 100);
- UMA_HISTOGRAM_MEMORY_KB(
- AddHistogramSuffix(
- client_id, "OfflinePages.DeletePage.PageSize").c_str(),
- iter->second.file_size / 1024);
- UMA_HISTOGRAM_COUNTS(
- AddHistogramSuffix(
- client_id, "OfflinePages.DeletePage.AccessCount").c_str(),
- iter->second.access_count);
FOR_EACH_OBSERVER(
Observer, observers_,
OfflinePageDeleted(iter->second.offline_id, iter->second.client_id));
offline_pages_.erase(iter);
}
- if (offline_ids.size() > 1) {
- UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count",
- static_cast<int32_t>(offline_ids.size()));
- UMA_HISTOGRAM_MEMORY_KB(
- "OfflinePages.BatchDelete.TotalPageSize", total_size / 1024);
- }
+
// Deleting multiple pages always succeeds when it gets to this point.
InformDeletePageDone(callback, (success || offline_ids.size() > 1)
? DeletePageResult::SUCCESS

Powered by Google App Engine
This is Rietveld 408576698