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

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_count(db.GetUniqueStatement(
63 "SELECT count(*) FROM visits WHERE visit_time > ?"));
64 weekly_visit_count.BindInt64(0, one_week_ago.ToInternalValue());
65 UMA_HISTOGRAM_COUNTS("History.WeeklyVisitCount",
66 weekly_visit_count.ColumnInt(0));
67
68 base::Time one_month_ago = base::Time::Now() - base::TimeDelta::FromDays(30);
69 sql::Statement monthly_visit_count(db.GetUniqueStatement(
70 "SELECT count(*) FROM visits WHERE visit_time > ?"));
71 monthly_visit_count.BindInt64(0, one_month_ago.ToInternalValue());
72 UMA_HISTOGRAM_COUNTS("History.MonthlyVisitCount",
73 monthly_visit_count.ColumnInt(0));
74
75 UMA_HISTOGRAM_TIMES("History.DatabaseBasicMetricsTime",
76 base::TimeTicks::Now() - start_time);
Scott Hess - ex-Googler 2013/01/23 22:15:37 Overall looks good. Just a couple questions. Fir
58 } 77 }
59 78
60 } // namespace 79 } // namespace
61 80
62 HistoryDatabase::HistoryDatabase() 81 HistoryDatabase::HistoryDatabase()
63 : needs_version_17_migration_(false) { 82 : needs_version_17_migration_(false) {
64 } 83 }
65 84
66 HistoryDatabase::~HistoryDatabase() { 85 HistoryDatabase::~HistoryDatabase() {
67 } 86 }
(...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);")); 390 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);"));
372 391
373 // Erase all the full text index files. These will take a while to update and 392 // 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 393 // are less important, so we just blow them away. Same with the archived
375 // database. 394 // database.
376 needs_version_17_migration_ = true; 395 needs_version_17_migration_ = true;
377 } 396 }
378 #endif 397 #endif
379 398
380 } // namespace history 399 } // 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