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

Side by Side Diff: components/history/core/browser/top_sites_backend.cc

Issue 1005873011: Only record the execution time during startup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a static member to make sure the histogram is recorded only once. Created 5 years, 8 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/history/core/browser/top_sites_backend.h" 5 #include "components/history/core/browser/top_sites_backend.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/task/cancelable_task_tracker.h" 14 #include "base/task/cancelable_task_tracker.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "components/history/core/browser/top_sites_database.h" 17 #include "components/history/core/browser/top_sites_database.h"
18 #include "sql/connection.h" 18 #include "sql/connection.h"
19 19
20 namespace history { 20 namespace history {
21 21
22 TopSitesBackend::HistogramRecording TopSitesBackend::histogram_recorded_ =
23 HISTOGRAM_RECORDING_NOT_YET;
24
25 // static
26 void TopSitesBackend::IncraseHistogramRecordingStatus() {
27 if (histogram_recorded_ == HISTOGRAM_RECORDING_NOT_YET) {
28 histogram_recorded_ = HISTOGRAM_RECORDING_IN_PROGRESS;
29 } else if (histogram_recorded_ == HISTOGRAM_RECORDING_IN_PROGRESS) {
30 histogram_recorded_ = HISTOGRAM_RECORDING_DONE;
31 }
32 }
33
22 TopSitesBackend::TopSitesBackend( 34 TopSitesBackend::TopSitesBackend(
23 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner) 35 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner)
24 : db_(new TopSitesDatabase()), db_task_runner_(db_task_runner) { 36 : db_(new TopSitesDatabase()), db_task_runner_(db_task_runner) {
25 DCHECK(db_task_runner_); 37 DCHECK(db_task_runner_);
26 } 38 }
27 39
28 void TopSitesBackend::Init(const base::FilePath& path) { 40 void TopSitesBackend::Init(const base::FilePath& path) {
29 db_path_ = path; 41 db_path_ = path;
30 db_task_runner_->PostTask( 42 db_task_runner_->PostTask(
31 FROM_HERE, base::Bind(&TopSitesBackend::InitDBOnDBThread, this, path)); 43 FROM_HERE, base::Bind(&TopSitesBackend::InitDBOnDBThread, this, path));
32 } 44 }
33 45
34 void TopSitesBackend::Shutdown() { 46 void TopSitesBackend::Shutdown() {
35 db_task_runner_->PostTask( 47 db_task_runner_->PostTask(
36 FROM_HERE, base::Bind(&TopSitesBackend::ShutdownDBOnDBThread, this)); 48 FROM_HERE, base::Bind(&TopSitesBackend::ShutdownDBOnDBThread, this));
37 } 49 }
38 50
39 void TopSitesBackend::GetMostVisitedThumbnails( 51 void TopSitesBackend::GetMostVisitedThumbnails(
40 const GetMostVisitedThumbnailsCallback& callback, 52 const GetMostVisitedThumbnailsCallback& callback,
41 base::CancelableTaskTracker* tracker) { 53 base::CancelableTaskTracker* tracker) {
42 scoped_refptr<MostVisitedThumbnails> thumbnails = new MostVisitedThumbnails(); 54 scoped_refptr<MostVisitedThumbnails> thumbnails = new MostVisitedThumbnails();
43 tracker->PostTaskAndReply( 55 tracker->PostTaskAndReply(
44 db_task_runner_.get(), FROM_HERE, 56 db_task_runner_.get(), FROM_HERE,
45 base::Bind(&TopSitesBackend::GetMostVisitedThumbnailsOnDBThread, this, 57 base::Bind(&TopSitesBackend::GetMostVisitedThumbnailsOnDBThread, this,
46 thumbnails), 58 thumbnails),
47 base::Bind(callback, thumbnails)); 59 base::Bind(callback, thumbnails));
48 } 60 }
49 61
50 void TopSitesBackend::UpdateTopSites(const TopSitesDelta& delta) { 62 void TopSitesBackend::UpdateTopSites(const TopSitesDelta& delta,
63 const CallLocation location) {
51 db_task_runner_->PostTask( 64 db_task_runner_->PostTask(
52 FROM_HERE, 65 FROM_HERE,
53 base::Bind(&TopSitesBackend::UpdateTopSitesOnDBThread, this, delta)); 66 base::Bind(&TopSitesBackend::UpdateTopSitesOnDBThread, this, delta,
67 location));
54 } 68 }
55 69
56 void TopSitesBackend::SetPageThumbnail(const MostVisitedURL& url, 70 void TopSitesBackend::SetPageThumbnail(const MostVisitedURL& url,
57 int url_rank, 71 int url_rank,
58 const Images& thumbnail) { 72 const Images& thumbnail) {
59 db_task_runner_->PostTask( 73 db_task_runner_->PostTask(
60 FROM_HERE, base::Bind(&TopSitesBackend::SetPageThumbnailOnDBThread, this, 74 FROM_HERE, base::Bind(&TopSitesBackend::SetPageThumbnailOnDBThread, this,
61 url, url_rank, thumbnail)); 75 url, url_rank, thumbnail));
62 } 76 }
63 77
(...skipping 30 matching lines...) Expand all
94 void TopSitesBackend::GetMostVisitedThumbnailsOnDBThread( 108 void TopSitesBackend::GetMostVisitedThumbnailsOnDBThread(
95 scoped_refptr<MostVisitedThumbnails> thumbnails) { 109 scoped_refptr<MostVisitedThumbnails> thumbnails) {
96 DCHECK(db_task_runner_->BelongsToCurrentThread()); 110 DCHECK(db_task_runner_->BelongsToCurrentThread());
97 111
98 if (db_) { 112 if (db_) {
99 db_->GetPageThumbnails(&(thumbnails->most_visited), 113 db_->GetPageThumbnails(&(thumbnails->most_visited),
100 &(thumbnails->url_to_images_map)); 114 &(thumbnails->url_to_images_map));
101 } 115 }
102 } 116 }
103 117
104 void TopSitesBackend::UpdateTopSitesOnDBThread(const TopSitesDelta& delta) { 118 void TopSitesBackend::UpdateTopSitesOnDBThread(
119 const TopSitesDelta& delta, const CallLocation location) {
105 TRACE_EVENT0("startup", "history::TopSitesBackend::UpdateTopSitesOnDBThread"); 120 TRACE_EVENT0("startup", "history::TopSitesBackend::UpdateTopSitesOnDBThread");
106 121
107 if (!db_) 122 if (!db_)
108 return; 123 return;
109 124
110 // TODO(yiyaoliu): Remove the histogram and related code when crbug/223430 is 125 // TODO(yiyaoliu): Remove the histogram and related code when crbug/223430 is
111 // fixed. 126 // fixed.
112 base::TimeTicks begin_time = base::TimeTicks::Now(); 127 base::TimeTicks begin_time = base::TimeTicks::Now();
113 128
114 for (size_t i = 0; i < delta.deleted.size(); ++i) 129 for (size_t i = 0; i < delta.deleted.size(); ++i)
115 db_->RemoveURL(delta.deleted[i]); 130 db_->RemoveURL(delta.deleted[i]);
116 131
117 for (size_t i = 0; i < delta.added.size(); ++i) 132 for (size_t i = 0; i < delta.added.size(); ++i)
118 db_->SetPageThumbnail(delta.added[i].url, delta.added[i].rank, Images()); 133 db_->SetPageThumbnail(delta.added[i].url, delta.added[i].rank, Images());
119 134
120 for (size_t i = 0; i < delta.moved.size(); ++i) 135 for (size_t i = 0; i < delta.moved.size(); ++i)
121 db_->UpdatePageRank(delta.moved[i].url, delta.moved[i].rank); 136 db_->UpdatePageRank(delta.moved[i].url, delta.moved[i].rank);
122 137
123 UMA_HISTOGRAM_TIMES("History.UpdateTopSitesOnDBThreadTime", 138 // If this is initiated from TopSitesImpl::OnGotMostVisitedThumbnails, and
124 base::TimeTicks::Now() - begin_time); 139 // |histogram_recorded_| indicates that the histogram recording is in
140 // progress, records the function execution time.
141 if (location == CALL_LOCATION_FROM_ON_GOT_MOST_VISITED_THUMBNAILS &&
142 histogram_recorded_ == HISTOGRAM_RECORDING_IN_PROGRESS) {
143 UMA_HISTOGRAM_TIMES("History.UpdateTopSitesOnDBThread_Startup_Time",
144 base::TimeTicks::Now() - begin_time);
145 IncraseHistogramRecordingStatus();
146 }
125 } 147 }
126 148
127 void TopSitesBackend::SetPageThumbnailOnDBThread(const MostVisitedURL& url, 149 void TopSitesBackend::SetPageThumbnailOnDBThread(const MostVisitedURL& url,
128 int url_rank, 150 int url_rank,
129 const Images& thumbnail) { 151 const Images& thumbnail) {
130 if (!db_) 152 if (!db_)
131 return; 153 return;
132 154
133 db_->SetPageThumbnail(url, url_rank, thumbnail); 155 db_->SetPageThumbnail(url, url_rank, thumbnail);
134 } 156 }
135 157
136 void TopSitesBackend::ResetDatabaseOnDBThread(const base::FilePath& file_path) { 158 void TopSitesBackend::ResetDatabaseOnDBThread(const base::FilePath& file_path) {
137 DCHECK(db_task_runner_->BelongsToCurrentThread()); 159 DCHECK(db_task_runner_->BelongsToCurrentThread());
138 db_.reset(NULL); 160 db_.reset(NULL);
139 sql::Connection::Delete(db_path_); 161 sql::Connection::Delete(db_path_);
140 db_.reset(new TopSitesDatabase()); 162 db_.reset(new TopSitesDatabase());
141 InitDBOnDBThread(db_path_); 163 InitDBOnDBThread(db_path_);
142 } 164 }
143 165
144 } // namespace history 166 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698