Chromium Code Reviews| OLD | NEW |
|---|---|
| 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) { | |
| 82 start_time = base::TimeTicks::Now(); | |
| 83 sql::Statement url_sql(db.GetUniqueStatement( | |
| 84 "SELECT url, last_visit_time FROM urls WHERE last_visit_time > ? " | |
| 85 "ORDER BY last_visit_time DESC")); | |
|
Scott Hess - ex-Googler
2013/01/24 17:30:52
I don't see an index on last_visit_time, so it see
Pam (message me for reviews)
2013/01/25 08:07:48
Makes sense. Thanks for knowing way more about the
Scott Hess - ex-Googler
2013/01/25 16:15:49
Unlike a server db like MYSQL, asking SQLite to do
| |
| 86 url_sql.BindInt64(0, one_month_ago.ToInternalValue()); | |
| 87 | |
| 88 bool saved_weekly_counts = false; | |
| 89 int url_count = 0; | |
| 90 std::set<std::string> hosts; | |
| 91 while (url_sql.Step()) { | |
| 92 GURL url(url_sql.ColumnString(0)); | |
| 93 base::Time visit_time = | |
| 94 base::Time::FromInternalValue(url_sql.ColumnInt64(1)); | |
| 95 if (!saved_weekly_counts && visit_time < one_week_ago) { | |
|
Scott Hess - ex-Googler
2013/01/24 17:30:52
Pedantic Man wants visit_time <= one_week_ago to m
Pam (message me for reviews)
2013/01/25 08:07:48
Now moot. The new > here matches the > for visits.
| |
| 96 UMA_HISTOGRAM_COUNTS("History.WeeklyURLCount", url_count); | |
| 97 UMA_HISTOGRAM_COUNTS_10000("History.WeeklyHostCount", hosts.size()); | |
| 98 saved_weekly_counts = true; | |
| 99 } | |
| 100 ++url_count; | |
| 101 hosts.insert(url.host()); | |
| 102 } | |
| 103 UMA_HISTOGRAM_COUNTS("History.MonthlyURLCount", url_count); | |
| 104 UMA_HISTOGRAM_COUNTS_10000("History.MonthlyHostCount", hosts.size()); | |
| 105 UMA_HISTOGRAM_TIMES("History.DatabaseAdvancedMetricsTime", | |
| 106 base::TimeTicks::Now() - start_time); | |
| 107 } | |
| 58 } | 108 } |
| 59 | 109 |
| 60 } // namespace | 110 } // namespace |
| 61 | 111 |
| 62 HistoryDatabase::HistoryDatabase() | 112 HistoryDatabase::HistoryDatabase() |
| 63 : needs_version_17_migration_(false) { | 113 : needs_version_17_migration_(false) { |
| 64 } | 114 } |
| 65 | 115 |
| 66 HistoryDatabase::~HistoryDatabase() { | 116 HistoryDatabase::~HistoryDatabase() { |
| 67 } | 117 } |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); | 421 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);")); |
| 372 | 422 |
| 373 // Erase all the full text index files. These will take a while to update and | 423 // 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 | 424 // are less important, so we just blow them away. Same with the archived |
| 375 // database. | 425 // database. |
| 376 needs_version_17_migration_ = true; | 426 needs_version_17_migration_ = true; |
| 377 } | 427 } |
| 378 #endif | 428 #endif |
| 379 | 429 |
| 380 } // namespace history | 430 } // namespace history |
| OLD | NEW |