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

Side by Side Diff: chrome/browser/history/history_database.cc

Issue 12047042: Add history-view-related UMA metrics and histograms for locally managed users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/history/history_database.h" 5 #include "chrome/browser/history/history_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/rand_util.h" 14 #include "base/rand_util.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/time.h"
16 #include "sql/transaction.h" 17 #include "sql/transaction.h"
17 18
18 #if defined(OS_MACOSX) 19 #if defined(OS_MACOSX)
19 #include "base/mac/mac_util.h" 20 #include "base/mac/mac_util.h"
20 #endif 21 #endif
21 22
22 namespace history { 23 namespace history {
23 24
24 namespace { 25 namespace {
25 26
26 // Current version number. We write databases at the "current" version number, 27 // Current version number. We write databases at the "current" version number,
27 // but any previous version that can read the "compatible" one can make do with 28 // but any previous version that can read the "compatible" one can make do with
28 // or database without *too* many bad effects. 29 // or database without *too* many bad effects.
29 static const int kCurrentVersionNumber = 23; 30 static const int kCurrentVersionNumber = 23;
30 static const int kCompatibleVersionNumber = 16; 31 static const int kCompatibleVersionNumber = 16;
31 static const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; 32 static const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold";
32 33
33 // Key in the meta table used to determine if we need to migrate thumbnails out 34 // Key in the meta table used to determine if we need to migrate thumbnails out
34 // of history. 35 // of history.
35 static const char kNeedsThumbnailMigrationKey[] = "needs_thumbnail_migration"; 36 static const char kNeedsThumbnailMigrationKey[] = "needs_thumbnail_migration";
36 37
37 void ComputeDatabaseMetrics(const FilePath& history_name, 38 void ComputeDatabaseMetrics(const FilePath& history_name,
38 sql::Connection& db) { 39 sql::Connection& db) {
39 if (base::RandInt(1, 100) != 50) 40 if (base::RandInt(1, 100) != 50)
40 return; // Only do this computation sometimes since it can be expensive. 41 return; // Only do this computation sometimes since it can be expensive.
41 42
43 base::TimeTicks start_time = base::TimeTicks::Now();
42 int64 file_size = 0; 44 int64 file_size = 0;
43 if (!file_util::GetFileSize(history_name, &file_size)) 45 if (!file_util::GetFileSize(history_name, &file_size))
44 return; 46 return;
45 int file_mb = static_cast<int>(file_size / (1024 * 1024)); 47 int file_mb = static_cast<int>(file_size / (1024 * 1024));
46 UMA_HISTOGRAM_MEMORY_MB("History.DatabaseFileMB", file_mb); 48 UMA_HISTOGRAM_MEMORY_MB("History.DatabaseFileMB", file_mb);
47 49
48 sql::Statement url_count(db.GetUniqueStatement("SELECT count(*) FROM urls")); 50 sql::Statement url_count(db.GetUniqueStatement("SELECT count(*) FROM urls"));
49 if (!url_count.Step()) 51 if (!url_count.Step())
50 return; 52 return;
51 UMA_HISTOGRAM_COUNTS("History.URLTableCount", url_count.ColumnInt(0)); 53 UMA_HISTOGRAM_COUNTS("History.URLTableCount", url_count.ColumnInt(0));
52 54
53 sql::Statement visit_count(db.GetUniqueStatement( 55 sql::Statement visit_count(db.GetUniqueStatement(
54 "SELECT count(*) FROM visits")); 56 "SELECT count(*) FROM visits"));
55 if (!visit_count.Step()) 57 if (!visit_count.Step())
56 return; 58 return;
57 UMA_HISTOGRAM_COUNTS("History.VisitTableCount", visit_count.ColumnInt(0)); 59 UMA_HISTOGRAM_COUNTS("History.VisitTableCount", visit_count.ColumnInt(0));
60
61 base::Time one_week_ago = base::Time::Now() - base::TimeDelta::FromDays(7);
62 sql::Statement weekly_visit_sql(db.GetUniqueStatement(
63 "SELECT count(*) FROM visits WHERE visit_time > ?"));
64 weekly_visit_sql.BindInt64(0, one_week_ago.ToInternalValue());
65 int weekly_visit_count = weekly_visit_sql.ColumnInt(0);
66 UMA_HISTOGRAM_COUNTS("History.WeeklyVisitCount", weekly_visit_count);
67
68 base::Time one_month_ago = base::Time::Now() - base::TimeDelta::FromDays(30);
69 sql::Statement monthly_visit_sql(db.GetUniqueStatement(
70 "SELECT count(*) FROM visits WHERE visit_time > ? AND visit_time <= ?"));
71 monthly_visit_sql.BindInt64(0, one_month_ago.ToInternalValue());
72 monthly_visit_sql.BindInt64(1, one_week_ago.ToInternalValue());
73 UMA_HISTOGRAM_COUNTS("History.MonthlyVisitCount",
74 monthly_visit_sql.ColumnInt(0) + weekly_visit_count);
75
76 UMA_HISTOGRAM_TIMES("History.DatabaseBasicMetricsTime",
77 base::TimeTicks::Now() - start_time);
78
79 // Compute the advanced metrics even less often, pending timing data showing
80 // that's not necessary.
81 if (base::RandInt(1, 3) == 3) {
sky 2013/01/25 16:33:45 This seems rather expensive. Are we sure we need t
Pam (message me for reviews) 2013/01/25 16:43:08 It's not quite so bad as that, since we're iterati
82 start_time = base::TimeTicks::Now();
83
84 // Collect all URLs visited within the last month.
85 sql::Statement url_sql(db.GetUniqueStatement(
86 "SELECT url, last_visit_time FROM urls WHERE last_visit_time > ?"));
87 url_sql.BindInt64(0, one_month_ago.ToInternalValue());
88
89 // Count URLs (which will always be unique) and unique hosts within the last
90 // week and last month.
91 int week_url_count = 0;
92 int month_url_count = 0;
93 std::set<std::string> week_hosts;
94 std::set<std::string> month_hosts;
95 while (url_sql.Step()) {
96 GURL url(url_sql.ColumnString(0));
97 base::Time visit_time =
98 base::Time::FromInternalValue(url_sql.ColumnInt64(1));
99 ++month_url_count;
100 month_hosts.insert(url.host());
101 if (visit_time > one_week_ago) {
102 ++week_url_count;
103 week_hosts.insert(url.host());
104 }
105 }
106 UMA_HISTOGRAM_COUNTS("History.WeeklyURLCount", week_url_count);
107 UMA_HISTOGRAM_COUNTS_10000("History.WeeklyHostCount", week_hosts.size());
108 UMA_HISTOGRAM_COUNTS("History.MonthlyURLCount", month_url_count);
109 UMA_HISTOGRAM_COUNTS_10000("History.MonthlyHostCount", month_hosts.size());
110 UMA_HISTOGRAM_TIMES("History.DatabaseAdvancedMetricsTime",
111 base::TimeTicks::Now() - start_time);
112 }
58 } 113 }
59 114
60 } // namespace 115 } // namespace
61 116
62 HistoryDatabase::HistoryDatabase() 117 HistoryDatabase::HistoryDatabase()
63 : needs_version_17_migration_(false) { 118 : needs_version_17_migration_(false) {
64 } 119 }
65 120
66 HistoryDatabase::~HistoryDatabase() { 121 HistoryDatabase::~HistoryDatabase() {
67 } 122 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); 426 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);"));
372 427
373 // Erase all the full text index files. These will take a while to update and 428 // Erase all the full text index files. These will take a while to update and
374 // are less important, so we just blow them away. Same with the archived 429 // are less important, so we just blow them away. Same with the archived
375 // database. 430 // database.
376 needs_version_17_migration_ = true; 431 needs_version_17_migration_ = true;
377 } 432 }
378 #endif 433 #endif
379 434
380 } // namespace history 435 } // namespace history
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698