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

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

Issue 2028383002: Revert of Record offline histograms with suffix via Histogram::FactoryGet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
243 } // namespace 138 } // namespace
244 139
245 // protected 140 // protected
246 OfflinePageModelImpl::OfflinePageModelImpl() 141 OfflinePageModelImpl::OfflinePageModelImpl()
247 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {} 142 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {}
248 143
249 OfflinePageModelImpl::OfflinePageModelImpl( 144 OfflinePageModelImpl::OfflinePageModelImpl(
250 std::unique_ptr<OfflinePageMetadataStore> store, 145 std::unique_ptr<OfflinePageMetadataStore> store,
251 const base::FilePath& archives_dir, 146 const base::FilePath& archives_dir,
252 const scoped_refptr<base::SequencedTaskRunner>& task_runner) 147 const scoped_refptr<base::SequencedTaskRunner>& task_runner)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) { 201 void OfflinePageModelImpl::MarkPageAccessed(int64_t offline_id) {
307 DCHECK(is_loaded_); 202 DCHECK(is_loaded_);
308 auto iter = offline_pages_.find(offline_id); 203 auto iter = offline_pages_.find(offline_id);
309 if (iter == offline_pages_.end()) 204 if (iter == offline_pages_.end())
310 return; 205 return;
311 206
312 // Make a copy of the cached item and update it. The cached item should only 207 // Make a copy of the cached item and update it. The cached item should only
313 // be updated upon the successful store operation. 208 // be updated upon the successful store operation.
314 OfflinePageItem offline_page_item = iter->second; 209 OfflinePageItem offline_page_item = iter->second;
315 210
316 ReportPageHistogramsAfterAccess(offline_page_item); 211 base::Time now = base::Time::Now();
212 base::TimeDelta time_since_last_accessed =
213 now - offline_page_item.last_access_time;
317 214
318 offline_page_item.last_access_time = base::Time::Now(); 215 // When the access account is still zero, the page is opened for the first
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;
319 offline_page_item.access_count++; 227 offline_page_item.access_count++;
320 228
321 store_->AddOrUpdateOfflinePage( 229 store_->AddOrUpdateOfflinePage(
322 offline_page_item, 230 offline_page_item,
323 base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone, 231 base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone,
324 weak_ptr_factory_.GetWeakPtr(), offline_page_item)); 232 weak_ptr_factory_.GetWeakPtr(), offline_page_item));
325 } 233 }
326 234
327 void OfflinePageModelImpl::DeletePagesByOfflineId( 235 void OfflinePageModelImpl::DeletePagesByOfflineId(
328 const std::vector<int64_t>& offline_ids, 236 const std::vector<int64_t>& offline_ids,
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 616
709 void OfflinePageModelImpl::OnAddOfflinePageDone( 617 void OfflinePageModelImpl::OnAddOfflinePageDone(
710 OfflinePageArchiver* archiver, 618 OfflinePageArchiver* archiver,
711 const SavePageCallback& callback, 619 const SavePageCallback& callback,
712 const OfflinePageItem& offline_page, 620 const OfflinePageItem& offline_page,
713 bool success) { 621 bool success) {
714 SavePageResult result; 622 SavePageResult result;
715 if (success) { 623 if (success) {
716 offline_pages_[offline_page.offline_id] = offline_page; 624 offline_pages_[offline_page.offline_id] = offline_page;
717 result = SavePageResult::SUCCESS; 625 result = SavePageResult::SUCCESS;
718 ReportPageHistogramAfterSave(offline_page); 626 UMA_HISTOGRAM_TIMES(
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);
719 } else { 635 } else {
720 result = SavePageResult::STORE_FAILURE; 636 result = SavePageResult::STORE_FAILURE;
721 } 637 }
722 InformSavePageDone(callback, result, offline_page.client_id, 638 InformSavePageDone(callback, result, offline_page.client_id,
723 offline_page.offline_id); 639 offline_page.offline_id);
724 DeletePendingArchiver(archiver); 640 DeletePendingArchiver(archiver);
725 641
726 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); 642 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this));
727 } 643 }
728 644
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 weak_ptr_factory_.GetWeakPtr(), 695 weak_ptr_factory_.GetWeakPtr(),
780 base::Bind(&OfflinePageModelImpl::OnStorageCleared, 696 base::Bind(&OfflinePageModelImpl::OnStorageCleared,
781 weak_ptr_factory_.GetWeakPtr())), 697 weak_ptr_factory_.GetWeakPtr())),
782 kStorageManagerStartingDelay); 698 kStorageManagerStartingDelay);
783 } 699 }
784 700
785 void OfflinePageModelImpl::InformSavePageDone(const SavePageCallback& callback, 701 void OfflinePageModelImpl::InformSavePageDone(const SavePageCallback& callback,
786 SavePageResult result, 702 SavePageResult result,
787 const ClientId& client_id, 703 const ClientId& client_id,
788 int64_t offline_id) { 704 int64_t offline_id) {
789 ReportSavePageResultHistogramAfterSave(client_id, result); 705 UMA_HISTOGRAM_ENUMERATION(
706 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult").c_str(),
707 static_cast<int>(result), static_cast<int>(SavePageResult::RESULT_COUNT));
790 archive_manager_->GetStorageStats( 708 archive_manager_->GetStorageStats(
791 base::Bind(&ReportStorageHistogramsAfterSave)); 709 base::Bind(&ReportStorageHistogramsAfterSave));
792 base::ThreadTaskRunnerHandle::Get()->PostTask( 710 base::ThreadTaskRunnerHandle::Get()->PostTask(
793 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, 711 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded,
794 weak_ptr_factory_.GetWeakPtr(), 712 weak_ptr_factory_.GetWeakPtr(),
795 base::Bind(&OfflinePageModelImpl::OnStorageCleared, 713 base::Bind(&OfflinePageModelImpl::OnStorageCleared,
796 weak_ptr_factory_.GetWeakPtr()))); 714 weak_ptr_factory_.GetWeakPtr())));
797 callback.Run(result, offline_id); 715 callback.Run(result, offline_id);
798 } 716 }
799 717
(...skipping 15 matching lines...) Expand all
815 store_->RemoveOfflinePages( 733 store_->RemoveOfflinePages(
816 offline_ids, 734 offline_ids,
817 base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone, 735 base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone,
818 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); 736 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback));
819 } 737 }
820 738
821 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( 739 void OfflinePageModelImpl::OnRemoveOfflinePagesDone(
822 const std::vector<int64_t>& offline_ids, 740 const std::vector<int64_t>& offline_ids,
823 const DeletePageCallback& callback, 741 const DeletePageCallback& callback,
824 bool success) { 742 bool success) {
825 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids);
826
827 // Delete the offline page from the in memory cache regardless of success in 743 // Delete the offline page from the in memory cache regardless of success in
828 // store. 744 // store.
745 base::Time now = base::Time::Now();
746 int64_t total_size = 0;
829 for (int64_t offline_id : offline_ids) { 747 for (int64_t offline_id : offline_ids) {
830 auto iter = offline_pages_.find(offline_id); 748 auto iter = offline_pages_.find(offline_id);
831 if (iter == offline_pages_.end()) 749 if (iter == offline_pages_.end())
832 continue; 750 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);
833 FOR_EACH_OBSERVER( 778 FOR_EACH_OBSERVER(
834 Observer, observers_, 779 Observer, observers_,
835 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); 780 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id));
836 offline_pages_.erase(iter); 781 offline_pages_.erase(iter);
837 } 782 }
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 }
838 // Deleting multiple pages always succeeds when it gets to this point. 789 // Deleting multiple pages always succeeds when it gets to this point.
839 InformDeletePageDone(callback, (success || offline_ids.size() > 1) 790 InformDeletePageDone(callback, (success || offline_ids.size() > 1)
840 ? DeletePageResult::SUCCESS 791 ? DeletePageResult::SUCCESS
841 : DeletePageResult::STORE_FAILURE); 792 : DeletePageResult::STORE_FAILURE);
842 } 793 }
843 794
844 void OfflinePageModelImpl::InformDeletePageDone( 795 void OfflinePageModelImpl::InformDeletePageDone(
845 const DeletePageCallback& callback, 796 const DeletePageCallback& callback,
846 DeletePageResult result) { 797 DeletePageResult result) {
847 UMA_HISTOGRAM_ENUMERATION("OfflinePages.DeletePageResult", 798 UMA_HISTOGRAM_ENUMERATION("OfflinePages.DeletePageResult",
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { 904 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) {
954 if (!is_loaded_) { 905 if (!is_loaded_) {
955 delayed_tasks_.push_back(task); 906 delayed_tasks_.push_back(task);
956 return; 907 return;
957 } 908 }
958 909
959 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 910 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
960 } 911 }
961 912
962 } // namespace offline_pages 913 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.h ('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