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

Side by Side Diff: components/offline_pages/offline_page_model_impl.cc

Issue 2022283003: Record offline histograms with suffix via Histogram::FactoryGet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase again Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/offline_pages/offline_page_model_impl.h" 5 #include "components/offline_pages/offline_page_model_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 int percentage_of_free = static_cast<int>( 128 int percentage_of_free = static_cast<int>(
129 1.0 * storage_stats.total_archives_size / 129 1.0 * storage_stats.total_archives_size /
130 (storage_stats.total_archives_size + storage_stats.free_disk_space) * 130 (storage_stats.total_archives_size + storage_stats.free_disk_space) *
131 100); 131 100);
132 UMA_HISTOGRAM_PERCENTAGE( 132 UMA_HISTOGRAM_PERCENTAGE(
133 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace", 133 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace",
134 percentage_of_free); 134 percentage_of_free);
135 } 135 }
136 } 136 }
137 137
138 void ReportSavePageResultHistogramAfterSave(const ClientId& client_id,
139 SavePageResult result) {
140 // The histogram below is an expansion of the UMA_HISTOGRAM_ENUMERATION
141 // macro adapted to allow for a dynamically suffixed histogram name.
142 // Note: The factory creates and owns the histogram.
143 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet(
144 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult"),
145 1,
146 static_cast<int>(SavePageResult::RESULT_COUNT),
147 static_cast<int>(SavePageResult::RESULT_COUNT) + 1,
148 base::HistogramBase::kUmaTargetedHistogramFlag);
149 histogram->Add(static_cast<int>(result));
150 }
151
152 void ReportPageHistogramAfterSave(const OfflinePageItem& offline_page) {
153 // The histogram below is an expansion of the UMA_HISTOGRAM_TIMES
154 // macro adapted to allow for a dynamically suffixed histogram name.
155 // Note: The factory creates and owns the histogram.
156 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet(
157 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"),
158 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10),
159 50, base::HistogramBase::kUmaTargetedHistogramFlag);
160 histogram->AddTime(base::Time::Now() - offline_page.creation_time);
161
162 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
163 // macro adapted to allow for a dynamically suffixed histogram name.
164 // Note: The factory creates and owns the histogram.
165 // Reported as Kb between 1Kb and 10Mb.
166 histogram = base::Histogram::FactoryGet(
167 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"),
168 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag);
169 histogram->Add(offline_page.file_size / 1024);
170 }
171
172 void ReportPageHistogramsAfterDelete(
173 const std::map<int64_t, OfflinePageItem>& offline_pages,
174 const std::vector<int64_t>& deleted_offline_ids) {
175 const int max_minutes = base::TimeDelta::FromDays(365).InMinutes();
176 base::Time now = base::Time::Now();
177 int64_t total_size = 0;
178 for (int64_t offline_id : deleted_offline_ids) {
179 auto iter = offline_pages.find(offline_id);
180 if (iter == offline_pages.end())
181 continue;
182 total_size += iter->second.file_size;
183 ClientId client_id = iter->second.client_id;
184
185 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
186 // macro adapted to allow for a dynamically suffixed histogram name.
187 // Note: The factory creates and owns the histogram.
188 base::HistogramBase* histogram = base::Histogram::FactoryGet(
189 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"),
190 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
191 histogram->Add((now - iter->second.creation_time).InMinutes());
192
193 histogram = base::Histogram::FactoryGet(
194 AddHistogramSuffix(
195 client_id, "OfflinePages.DeletePage.TimeSinceLastOpen"),
196 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
197 histogram->Add((now - iter->second.last_access_time).InMinutes());
198
199 histogram = base::Histogram::FactoryGet(
200 AddHistogramSuffix(
201 client_id, "OfflinePages.DeletePage.LastOpenToCreated"),
202 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
203 histogram->Add(
204 (iter->second.last_access_time - iter->second.creation_time).
205 InMinutes());
206
207 // Reported as Kb between 1Kb and 10Mb.
208 histogram = base::Histogram::FactoryGet(
209 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"),
210 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag);
211 histogram->Add(iter->second.file_size / 1024);
212
213 histogram = base::Histogram::FactoryGet(
214 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"),
215 1, 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag);
216 histogram->Add(iter->second.access_count);
217 }
218
219 if (deleted_offline_ids.size() > 1) {
220 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count",
221 static_cast<int32_t>(deleted_offline_ids.size()));
222 UMA_HISTOGRAM_MEMORY_KB(
223 "OfflinePages.BatchDelete.TotalPageSize", total_size / 1024);
224 }
225 }
226
227 void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item) {
228 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
229 // macro adapted to allow for a dynamically suffixed histogram name.
230 // Note: The factory creates and owns the histogram.
231 base::HistogramBase* histogram = base::Histogram::FactoryGet(
232 AddHistogramSuffix(
233 offline_page_item.client_id,
234 offline_page_item.access_count == 0 ?
235 "OfflinePages.FirstOpenSinceCreated" :
236 "OfflinePages.OpenSinceLastOpen"),
237 1, kMaxOpenedPageHistogramBucket.InMinutes(), 50,
238 base::HistogramBase::kUmaTargetedHistogramFlag);
239 histogram->Add(
240 (base::Time::Now() - offline_page_item.last_access_time).InMinutes());
241 }
242
138 } // namespace 243 } // namespace
139 244
140 // protected 245 // protected
141 OfflinePageModelImpl::OfflinePageModelImpl() 246 OfflinePageModelImpl::OfflinePageModelImpl()
142 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {} 247 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {}
143 248
144 OfflinePageModelImpl::OfflinePageModelImpl( 249 OfflinePageModelImpl::OfflinePageModelImpl(
145 std::unique_ptr<OfflinePageMetadataStore> store, 250 std::unique_ptr<OfflinePageMetadataStore> store,
146 const base::FilePath& archives_dir, 251 const base::FilePath& archives_dir,
147 const scoped_refptr<base::SequencedTaskRunner>& task_runner) 252 const scoped_refptr<base::SequencedTaskRunner>& task_runner)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { 306 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) {
202 DCHECK(is_loaded_); 307 DCHECK(is_loaded_);
203 auto iter = offline_pages_.find(offline_id); 308 auto iter = offline_pages_.find(offline_id);
204 if (iter == offline_pages_.end()) 309 if (iter == offline_pages_.end())
205 return; 310 return;
206 311
207 // Make a copy of the cached item and update it. The cached item should only 312 // Make a copy of the cached item and update it. The cached item should only
208 // be updated upon the successful store operation. 313 // be updated upon the successful store operation.
209 OfflinePageItem offline_page_item = iter->second; 314 OfflinePageItem offline_page_item = iter->second;
210 315
211 base::Time now = base::Time::Now(); 316 ReportPageHistogramsAfterAccess(offline_page_item);
212 base::TimeDelta time_since_last_accessed =
213 now - offline_page_item.last_access_time;
214 317
215 // When the access account is still zero, the page is opened for the first 318 offline_page_item.last_access_time = base::Time::Now();
216 // time since its creation.
217 UMA_HISTOGRAM_CUSTOM_COUNTS(
218 AddHistogramSuffix(offline_page_item.client_id,
219 (offline_page_item.access_count == 0)
220 ? "OfflinePages.FirstOpenSinceCreated"
221 : "OfflinePages.OpenSinceLastOpen")
222 .c_str(),
223 time_since_last_accessed.InMinutes(), 1,
224 kMaxOpenedPageHistogramBucket.InMinutes(), 50);
225
226 offline_page_item.last_access_time = now;
227 offline_page_item.access_count++; 319 offline_page_item.access_count++;
228 320
229 store_->AddOrUpdateOfflinePage( 321 store_->AddOrUpdateOfflinePage(
230 offline_page_item, 322 offline_page_item,
231 base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone, 323 base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone,
232 weak_ptr_factory_.GetWeakPtr(), offline_page_item)); 324 weak_ptr_factory_.GetWeakPtr(), offline_page_item));
233 } 325 }
234 326
235 void OfflinePageModelImpl::DeletePagesByOfflineId( 327 void OfflinePageModelImpl::DeletePagesByOfflineId(
236 const std::vector<int64_t>& offline_ids, 328 const std::vector<int64_t>& offline_ids,
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 708
617 void OfflinePageModelImpl::OnAddOfflinePageDone( 709 void OfflinePageModelImpl::OnAddOfflinePageDone(
618 OfflinePageArchiver* archiver, 710 OfflinePageArchiver* archiver,
619 const SavePageCallback& callback, 711 const SavePageCallback& callback,
620 const OfflinePageItem& offline_page, 712 const OfflinePageItem& offline_page,
621 bool success) { 713 bool success) {
622 SavePageResult result; 714 SavePageResult result;
623 if (success) { 715 if (success) {
624 offline_pages_[offline_page.offline_id] = offline_page; 716 offline_pages_[offline_page.offline_id] = offline_page;
625 result = SavePageResult::SUCCESS; 717 result = SavePageResult::SUCCESS;
626 UMA_HISTOGRAM_TIMES( 718 ReportPageHistogramAfterSave(offline_page);
627 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime")
628 .c_str(),
629 base::Time::Now() - offline_page.creation_time);
630 // 50 buckets capped between 1Kb and 10Mb.
631 UMA_HISTOGRAM_COUNTS_10000(
632 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize")
633 .c_str(),
634 offline_page.file_size / 1024);
635 } else { 719 } else {
636 result = SavePageResult::STORE_FAILURE; 720 result = SavePageResult::STORE_FAILURE;
637 } 721 }
638 InformSavePageDone(callback, result, offline_page.client_id, 722 InformSavePageDone(callback, result, offline_page.client_id,
639 offline_page.offline_id); 723 offline_page.offline_id);
640 DeletePendingArchiver(archiver); 724 DeletePendingArchiver(archiver);
641 725
642 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); 726 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this));
643 } 727 }
644 728
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 weak_ptr_factory_.GetWeakPtr(), 779 weak_ptr_factory_.GetWeakPtr(),
696 base::Bind(&OfflinePageModelImpl::OnStorageCleared, 780 base::Bind(&OfflinePageModelImpl::OnStorageCleared,
697 weak_ptr_factory_.GetWeakPtr())), 781 weak_ptr_factory_.GetWeakPtr())),
698 kStorageManagerStartingDelay); 782 kStorageManagerStartingDelay);
699 } 783 }
700 784
701 void OfflinePageModelImpl::InformSavePageDone(const SavePageCallback& callback, 785 void OfflinePageModelImpl::InformSavePageDone(const SavePageCallback& callback,
702 SavePageResult result, 786 SavePageResult result,
703 const ClientId& client_id, 787 const ClientId& client_id,
704 int64_t offline_id) { 788 int64_t offline_id) {
705 UMA_HISTOGRAM_ENUMERATION( 789 ReportSavePageResultHistogramAfterSave(client_id, result);
706 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult").c_str(),
707 static_cast<int>(result), static_cast<int>(SavePageResult::RESULT_COUNT));
708 archive_manager_->GetStorageStats( 790 archive_manager_->GetStorageStats(
709 base::Bind(&ReportStorageHistogramsAfterSave)); 791 base::Bind(&ReportStorageHistogramsAfterSave));
710 base::ThreadTaskRunnerHandle::Get()->PostTask( 792 base::ThreadTaskRunnerHandle::Get()->PostTask(
711 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, 793 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded,
712 weak_ptr_factory_.GetWeakPtr(), 794 weak_ptr_factory_.GetWeakPtr(),
713 base::Bind(&OfflinePageModelImpl::OnStorageCleared, 795 base::Bind(&OfflinePageModelImpl::OnStorageCleared,
714 weak_ptr_factory_.GetWeakPtr()))); 796 weak_ptr_factory_.GetWeakPtr())));
715 callback.Run(result, offline_id); 797 callback.Run(result, offline_id);
716 } 798 }
717 799
(...skipping 15 matching lines...) Expand all
733 store_->RemoveOfflinePages( 815 store_->RemoveOfflinePages(
734 offline_ids, 816 offline_ids,
735 base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone, 817 base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone,
736 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); 818 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback));
737 } 819 }
738 820
739 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( 821 void OfflinePageModelImpl::OnRemoveOfflinePagesDone(
740 const std::vector<int64_t>& offline_ids, 822 const std::vector<int64_t>& offline_ids,
741 const DeletePageCallback& callback, 823 const DeletePageCallback& callback,
742 bool success) { 824 bool success) {
825 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids);
826
743 // Delete the offline page from the in memory cache regardless of success in 827 // Delete the offline page from the in memory cache regardless of success in
744 // store. 828 // store.
745 base::Time now = base::Time::Now();
746 int64_t total_size = 0;
747 for (int64_t offline_id : offline_ids) { 829 for (int64_t offline_id : offline_ids) {
748 auto iter = offline_pages_.find(offline_id); 830 auto iter = offline_pages_.find(offline_id);
749 if (iter == offline_pages_.end()) 831 if (iter == offline_pages_.end())
750 continue; 832 continue;
751 total_size += iter->second.file_size;
752 ClientId client_id = iter->second.client_id;
753 UMA_HISTOGRAM_CUSTOM_COUNTS(
754 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime").c_str(),
755 (now - iter->second.creation_time).InMinutes(), 1,
756 base::TimeDelta::FromDays(365).InMinutes(), 100);
757 UMA_HISTOGRAM_CUSTOM_COUNTS(
758 AddHistogramSuffix(client_id,
759 "OfflinePages.DeletePage.TimeSinceLastOpen")
760 .c_str(),
761 (now - iter->second.last_access_time).InMinutes(), 1,
762 base::TimeDelta::FromDays(365).InMinutes(), 100);
763 UMA_HISTOGRAM_CUSTOM_COUNTS(
764 AddHistogramSuffix(client_id,
765 "OfflinePages.DeletePage.LastOpenToCreated")
766 .c_str(),
767 (iter->second.last_access_time - iter->second.creation_time)
768 .InMinutes(),
769 1, base::TimeDelta::FromDays(365).InMinutes(), 100);
770 UMA_HISTOGRAM_MEMORY_KB(
771 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize")
772 .c_str(),
773 iter->second.file_size / 1024);
774 UMA_HISTOGRAM_COUNTS(
775 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount")
776 .c_str(),
777 iter->second.access_count);
778 FOR_EACH_OBSERVER( 833 FOR_EACH_OBSERVER(
779 Observer, observers_, 834 Observer, observers_,
780 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); 835 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id));
781 offline_pages_.erase(iter); 836 offline_pages_.erase(iter);
782 } 837 }
783 if (offline_ids.size() > 1) {
784 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count",
785 static_cast<int32_t>(offline_ids.size()));
786 UMA_HISTOGRAM_MEMORY_KB("OfflinePages.BatchDelete.TotalPageSize",
787 total_size / 1024);
788 }
789 // Deleting multiple pages always succeeds when it gets to this point. 838 // Deleting multiple pages always succeeds when it gets to this point.
790 InformDeletePageDone(callback, (success || offline_ids.size() > 1) 839 InformDeletePageDone(callback, (success || offline_ids.size() > 1)
791 ? DeletePageResult::SUCCESS 840 ? DeletePageResult::SUCCESS
792 : DeletePageResult::STORE_FAILURE); 841 : DeletePageResult::STORE_FAILURE);
793 } 842 }
794 843
795 void OfflinePageModelImpl::InformDeletePageDone( 844 void OfflinePageModelImpl::InformDeletePageDone(
796 const DeletePageCallback& callback, 845 const DeletePageCallback& callback,
797 DeletePageResult result) { 846 DeletePageResult result) {
798 UMA_HISTOGRAM_ENUMERATION("OfflinePages.DeletePageResult", 847 UMA_HISTOGRAM_ENUMERATION("OfflinePages.DeletePageResult",
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { 953 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) {
905 if (!is_loaded_) { 954 if (!is_loaded_) {
906 delayed_tasks_.push_back(task); 955 delayed_tasks_.push_back(task);
907 return; 956 return;
908 } 957 }
909 958
910 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 959 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
911 } 960 }
912 961
913 } // namespace offline_pages 962 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.cc ('k') | components/offline_pages/offline_page_storage_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698