Commit 07b37254 authored by Wei-Yin Chen (陳威尹)'s avatar Wei-Yin Chen (陳威尹) Committed by Commit Bot

Add UMA for history report

Add the following UMA metrics:
- Search.HistoryReport.DeltaFile.LastSeqNo
- Search.HistoryReport.DeltaFile.LevelDBEntries
- Search.HistoryReport.UsageReportsBuffer.LevelDBEntries

These are health checking signals to see if Icing-related levelDBs
could grow too big.

Bug: 857345
Change-Id: Icfc67b3442864a1c31b15427de40b406ea674ff7
Reviewed-on: https://chromium-review.googlesource.com/1117937Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573559}
parent 666b2983
...@@ -8,10 +8,12 @@ ...@@ -8,10 +8,12 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/trace_event/process_memory_dump.h" #include "base/trace_event/process_memory_dump.h"
#include "chrome/browser/android/history_report/delta_file_commons.h" #include "chrome/browser/android/history_report/delta_file_commons.h"
#include "chrome/browser/android/history_report/usage_report_util.h"
#include "third_party/leveldatabase/env_chromium.h" #include "third_party/leveldatabase/env_chromium.h"
#include "third_party/leveldatabase/leveldb_chrome.h" #include "third_party/leveldatabase/leveldb_chrome.h"
#include "third_party/leveldatabase/src/include/leveldb/comparator.h" #include "third_party/leveldatabase/src/include/leveldb/comparator.h"
...@@ -109,13 +111,20 @@ bool DeltaFileBackend::Init() { ...@@ -109,13 +111,20 @@ bool DeltaFileBackend::Init() {
} }
status = leveldb_env::OpenDB(options, path, &db_); status = leveldb_env::OpenDB(options, path, &db_);
} }
if (status.ok()) { if (!status.ok()) {
CHECK(db_); LOG(WARNING) << "Unable to open " << path_.value() << ": "
return true; << status.ToString();
return false;
} }
LOG(WARNING) << "Unable to open " << path_.value() << ": " CHECK(db_);
<< status.ToString();
return false; UMA_HISTOGRAM_COUNTS_1M("Search.HistoryReport.DeltaFile.LevelDBEntries",
usage_report_util::DatabaseEntries(db_.get()));
UMA_HISTOGRAM_COUNTS_1M("Search.HistoryReport.DeltaFile.LastSeqNo",
GetLastSeqNo(db_.get()));
return true;
} }
bool DeltaFileBackend::EnsureInitialized() { bool DeltaFileBackend::EnsureInitialized() {
......
...@@ -32,7 +32,7 @@ class DeltaFileService { ...@@ -32,7 +32,7 @@ class DeltaFileService {
explicit DeltaFileService(const base::FilePath& dir); explicit DeltaFileService(const base::FilePath& dir);
virtual ~DeltaFileService(); virtual ~DeltaFileService();
// Adds new addtion entry to delta file. // Adds new addition entry to delta file.
virtual void PageAdded(const GURL& url); virtual void PageAdded(const GURL& url);
// Adds new deletion entry to delta file. // Adds new deletion entry to delta file.
void PageDeleted(const GURL& url); void PageDeleted(const GURL& url);
......
// Copyright 2015 The Chromium Authors. All rights reserved. // Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -10,6 +9,9 @@ ...@@ -10,6 +9,9 @@
#include "chrome/browser/android/proto/delta_file.pb.h" #include "chrome/browser/android/proto/delta_file.pb.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
#include "third_party/leveldatabase/src/include/leveldb/db.h"
#include "third_party/leveldatabase/src/include/leveldb/iterator.h"
#include "third_party/leveldatabase/src/include/leveldb/options.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace history_report { namespace history_report {
...@@ -46,5 +48,15 @@ bool ShouldIgnoreUrl(const GURL& url) { ...@@ -46,5 +48,15 @@ bool ShouldIgnoreUrl(const GURL& url) {
return false; return false;
} }
int DatabaseEntries(leveldb::DB* db) {
std::unique_ptr<leveldb::Iterator> db_iter(
db->NewIterator(leveldb::ReadOptions()));
int count = 0;
for (db_iter->SeekToFirst(); db_iter->Valid(); db_iter->Next())
count++;
return count;
}
} // namespace usage_report_util } // namespace usage_report_util
} // namespace history_report } // namespace history_report
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include<string> #include<string>
#include "third_party/leveldatabase/src/include/leveldb/db.h"
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
class GURL; class GURL;
...@@ -23,6 +24,8 @@ bool IsTypedVisit(ui::PageTransition visit_transition); ...@@ -23,6 +24,8 @@ bool IsTypedVisit(ui::PageTransition visit_transition);
bool ShouldIgnoreUrl(const GURL& url); bool ShouldIgnoreUrl(const GURL& url);
int DatabaseEntries(leveldb::DB* db);
} // namespace usage_report_util } // namespace usage_report_util
} // namespace history_report } // namespace history_report
......
...@@ -55,12 +55,17 @@ bool UsageReportsBufferBackend::Init() { ...@@ -55,12 +55,17 @@ bool UsageReportsBufferBackend::Init() {
} }
status = leveldb_env::OpenDB(options, path, &db_); status = leveldb_env::OpenDB(options, path, &db_);
} }
if (status.ok()) { if (!status.ok()) {
CHECK(db_); LOG(WARNING) << "Unable to open " << path << ": " << status.ToString();
return true; return false;
} }
LOG(WARNING) << "Unable to open " << path << ": " << status.ToString(); CHECK(db_);
return false;
UMA_HISTOGRAM_COUNTS_1M(
"Search.HistoryReport.UsageReportsBuffer.LevelDBEntries",
usage_report_util::DatabaseEntries(db_.get()));
return true;
} }
void UsageReportsBufferBackend::AddVisit(const std::string& id, void UsageReportsBufferBackend::AddVisit(const std::string& id,
...@@ -138,11 +143,7 @@ std::string UsageReportsBufferBackend::Dump() { ...@@ -138,11 +143,7 @@ std::string UsageReportsBufferBackend::Dump() {
return dump; return dump;
} }
dump.append("num pending entries="); dump.append("num pending entries=");
leveldb::ReadOptions options; dump.append(base::IntToString(usage_report_util::DatabaseEntries(db_.get())));
int num_entries = 0;
std::unique_ptr<leveldb::Iterator> db_it(db_->NewIterator(options));
for (db_it->SeekToFirst(); db_it->Valid(); db_it->Next()) num_entries++;
dump.append(base::IntToString(num_entries));
dump.append("]"); dump.append("]");
return dump; return dump;
} }
...@@ -171,4 +172,3 @@ bool UsageReportsBufferBackend::OnMemoryDump( ...@@ -171,4 +172,3 @@ bool UsageReportsBufferBackend::OnMemoryDump(
} }
} // namespace history_report } // namespace history_report
...@@ -12,14 +12,25 @@ package history_report; ...@@ -12,14 +12,25 @@ package history_report;
message DeltaFileEntry { message DeltaFileEntry {
// Next ID to use: 4 // Next ID to use: 4
// |seq_no| is an auto increment sequence number, used as the key.
optional int64 seq_no = 1; optional int64 seq_no = 1;
// |type| can only be "add" or "del".
optional string type = 2; optional string type = 2;
optional string url = 3; optional string url = 3;
} }
message UsageReport { message UsageReport {
// Next ID to use: 4 // Next ID to use: 4
// |id| is derived from the URL, and the length doesn't exceed 256 chars.
// DeltaFileEntry and UsageReport can be joined by |id| this way.
optional string id = 1; optional string id = 1;
optional int64 timestamp_ms = 2; optional int64 timestamp_ms = 2;
// Whether the navigation is PAGE_TRANSITION_TYPED and not redirected.
optional bool typed_visit = 3; optional bool typed_visit = 3;
} }
...@@ -88382,6 +88382,36 @@ uploading your change for review. ...@@ -88382,6 +88382,36 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Search.HistoryReport.DeltaFile.LastSeqNo" units="count"
expires_after="M71">
<owner>wychen@chromium.org</owner>
<owner>yusufo@chromium.org</owner>
<summary>
The last sequential number in the delta file for Icing. This is measured on
cold start.
</summary>
</histogram>
<histogram name="Search.HistoryReport.DeltaFile.LevelDBEntries" units="entries"
expires_after="2019-06-01">
<owner>wychen@chromium.org</owner>
<owner>yusufo@chromium.org</owner>
<summary>
The number of entries in the delta file level DB for Icing. This is measured
on cold start.
</summary>
</histogram>
<histogram name="Search.HistoryReport.UsageReportsBuffer.LevelDBEntries"
units="entries" expires_after="2019-06-01">
<owner>wychen@chromium.org</owner>
<owner>yusufo@chromium.org</owner>
<summary>
The number of entries in the usage report level DB for Icing. This is
measured on cold start.
</summary>
</histogram>
<histogram name="Search.IcingContextReportingStatus" <histogram name="Search.IcingContextReportingStatus"
enum="IcingContextReportingStatus"> enum="IcingContextReportingStatus">
<owner>joaodasilva@chromium.org</owner> <owner>joaodasilva@chromium.org</owner>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment