Commit e397eb2c authored by Jered Gray's avatar Jered Gray Committed by Commit Bot

Add histograms for HintCacheLevelDBStore

UMA histograms have been added to HintCacheLevelDBStore for tracking the result
of loading the metadata and for tracking status changes within the store.

Change-Id: Iac6cbb37284e48a557469c0fcb13e57f33f97599
Reviewed-on: https://chromium-review.googlesource.com/c/1432893Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Commit-Queue: Jered Gray <jegray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625842}
parent 54ad225c
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "components/previews/content/hint_cache_leveldb_store.h" #include "components/previews/content/hint_cache_leveldb_store.h"
#include "base/metrics/histogram_macros.h"
#include "components/leveldb_proto/public/proto_database_provider.h" #include "components/leveldb_proto/public/proto_database_provider.h"
namespace previews { namespace previews {
...@@ -28,6 +29,43 @@ constexpr size_t kDatabaseWriteBufferSizeBytes = 128 * 1024; ...@@ -28,6 +29,43 @@ constexpr size_t kDatabaseWriteBufferSizeBytes = 128 * 1024;
// "[EntryType::kComponentHint]_[component_version]_[host]" // "[EntryType::kComponentHint]_[component_version]_[host]"
constexpr char kKeySectionDelimiter = '_'; constexpr char kKeySectionDelimiter = '_';
// Enumerates the possible outcomes of loading metadata. Used in UMA histograms,
// so the order of enumerators should not be changed.
//
// Keep in sync with PreviewsHintCacheLevelDBStoreProcessMetadataResult in
// tools/metrics/histograms/enums.xml.
enum class PreviewsHintCacheLevelDBStoreLoadMetadataResult {
kSuccess = 0,
kLoadMetadataFailed = 1,
kSchemaMetadataMissing = 2,
kSchemaMetadataWrongVersion = 3,
kComponentMetadataMissing = 4,
kMaxValue = kComponentMetadataMissing,
};
// Util class for recording the result of loading the metadata. The result is
// recorded when it goes out of scope and its destructor is called.
class ScopedLoadMetadataResultRecorder {
public:
ScopedLoadMetadataResultRecorder()
: result_(PreviewsHintCacheLevelDBStoreLoadMetadataResult::kSuccess) {}
~ScopedLoadMetadataResultRecorder() {
UMA_HISTOGRAM_ENUMERATION(
"Previews.HintCacheLevelDBStore.LoadMetadataResult", result_);
}
void set_result(PreviewsHintCacheLevelDBStoreLoadMetadataResult result) {
result_ = result;
}
private:
PreviewsHintCacheLevelDBStoreLoadMetadataResult result_;
};
void RecordStatusChange(HintCacheLevelDBStore::Status status) {
UMA_HISTOGRAM_ENUMERATION("Previews.HintCacheLevelDBStore.Status", status);
}
} // namespace } // namespace
HintCacheLevelDBStore::HintCacheLevelDBStore( HintCacheLevelDBStore::HintCacheLevelDBStore(
...@@ -46,7 +84,9 @@ HintCacheLevelDBStore::HintCacheLevelDBStore( ...@@ -46,7 +84,9 @@ HintCacheLevelDBStore::HintCacheLevelDBStore(
database_(std::move(database)), database_(std::move(database)),
status_(Status::kUninitialized), status_(Status::kUninitialized),
component_data_update_in_flight_(false), component_data_update_in_flight_(false),
weak_ptr_factory_(this) {} weak_ptr_factory_(this) {
RecordStatusChange(status_);
}
HintCacheLevelDBStore::~HintCacheLevelDBStore() { HintCacheLevelDBStore::~HintCacheLevelDBStore() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
...@@ -268,15 +308,16 @@ void HintCacheLevelDBStore::UpdateStatus(Status new_status) { ...@@ -268,15 +308,16 @@ void HintCacheLevelDBStore::UpdateStatus(Status new_status) {
// The status can never transition from Status::kFailed. // The status can never transition from Status::kFailed.
DCHECK(status_ != Status::kFailed || new_status == Status::kFailed); DCHECK(status_ != Status::kFailed || new_status == Status::kFailed);
// If the database transitions into a failed state from a non-failed state, // If the status is not changing, simply return; the remaining logic handles
// then fully destroy it. This ensures that it'll have a clean state the next // status changes.
// time it is created. if (status_ == new_status) {
bool destroy_database = return;
status_ != Status::kFailed && new_status == Status::kFailed; }
status_ = new_status; status_ = new_status;
RecordStatusChange(status_);
if (destroy_database) { if (status_ == Status::kFailed) {
database_->Destroy( database_->Destroy(
base::BindOnce(&HintCacheLevelDBStore::OnDatabaseDestroyed, base::BindOnce(&HintCacheLevelDBStore::OnDatabaseDestroyed,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
...@@ -401,7 +442,14 @@ void HintCacheLevelDBStore::OnLoadMetadata( ...@@ -401,7 +442,14 @@ void HintCacheLevelDBStore::OnLoadMetadata(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(metadata_entries); DCHECK(metadata_entries);
// Create a scoped load metadata result recorder. It records the result when
// its destructor is called.
ScopedLoadMetadataResultRecorder result_recorder;
if (!success) { if (!success) {
result_recorder.set_result(
PreviewsHintCacheLevelDBStoreLoadMetadataResult::kLoadMetadataFailed);
UpdateStatus(Status::kFailed); UpdateStatus(Status::kFailed);
std::move(callback).Run(); std::move(callback).Run();
return; return;
...@@ -414,6 +462,16 @@ void HintCacheLevelDBStore::OnLoadMetadata( ...@@ -414,6 +462,16 @@ void HintCacheLevelDBStore::OnLoadMetadata(
if (schema_entry == metadata_entries->end() || if (schema_entry == metadata_entries->end() ||
!schema_entry->second.has_version() || !schema_entry->second.has_version() ||
schema_entry->second.version() != kStoreSchemaVersion) { schema_entry->second.version() != kStoreSchemaVersion) {
if (schema_entry == metadata_entries->end()) {
result_recorder.set_result(
PreviewsHintCacheLevelDBStoreLoadMetadataResult::
kSchemaMetadataMissing);
} else {
result_recorder.set_result(
PreviewsHintCacheLevelDBStoreLoadMetadataResult::
kSchemaMetadataWrongVersion);
}
PurgeDatabase(std::move(callback)); PurgeDatabase(std::move(callback));
return; return;
} }
...@@ -425,6 +483,9 @@ void HintCacheLevelDBStore::OnLoadMetadata( ...@@ -425,6 +483,9 @@ void HintCacheLevelDBStore::OnLoadMetadata(
if (component_entry != metadata_entries->end()) { if (component_entry != metadata_entries->end()) {
DCHECK(component_entry->second.has_version()); DCHECK(component_entry->second.has_version());
SetComponentVersion(base::Version(component_entry->second.version())); SetComponentVersion(base::Version(component_entry->second.version()));
} else {
result_recorder.set_result(PreviewsHintCacheLevelDBStoreLoadMetadataResult::
kComponentMetadataMissing);
} }
UpdateStatus(Status::kAvailable); UpdateStatus(Status::kAvailable);
......
...@@ -33,6 +33,22 @@ class HintCacheLevelDBStore : public HintCacheStore { ...@@ -33,6 +33,22 @@ class HintCacheLevelDBStore : public HintCacheStore {
using StoreEntryProtoDatabase = using StoreEntryProtoDatabase =
leveldb_proto::ProtoDatabase<previews::proto::StoreEntry>; leveldb_proto::ProtoDatabase<previews::proto::StoreEntry>;
// Status of the store. The store begins in kUninitialized, transitions to
// kInitializing after Initialize() is called, and transitions to kAvailable
// if initialization successfully completes. In the case where anything fails,
// the store transitions to kFailed, at which point it is fully purged and
// becomes unusable.
//
// Keep in sync with PreviewsHintCacheLevelDBStoreStatus in
// tools/metrics/histograms/enums.xml.
enum class Status {
kUninitialized = 0,
kInitializing = 1,
kAvailable = 2,
kFailed = 3,
kMaxValue = kFailed,
};
HintCacheLevelDBStore( HintCacheLevelDBStore(
const base::FilePath& database_dir, const base::FilePath& database_dir,
scoped_refptr<base::SequencedTaskRunner> store_task_runner); scoped_refptr<base::SequencedTaskRunner> store_task_runner);
...@@ -66,18 +82,6 @@ class HintCacheLevelDBStore : public HintCacheStore { ...@@ -66,18 +82,6 @@ class HintCacheLevelDBStore : public HintCacheStore {
leveldb_proto::ProtoDatabase<previews::proto::StoreEntry>::KeyEntryVector; leveldb_proto::ProtoDatabase<previews::proto::StoreEntry>::KeyEntryVector;
using EntryMap = std::map<EntryKey, previews::proto::StoreEntry>; using EntryMap = std::map<EntryKey, previews::proto::StoreEntry>;
// Status of the store. The store begins in kUninitialized, transitions to
// kInitializing after Initialize() is called, and transitions to kAvailable
// if initialization successfully completes. In the case where anything fails,
// the store transitions to kFailed, at which point it is fully purged and
// becomes unusable.
enum class Status {
kUninitialized,
kInitializing,
kAvailable,
kFailed,
};
// Entry types within the store appear at the start of the keys of entries. // Entry types within the store appear at the start of the keys of entries.
// These values are converted into strings within the key: a key starting with // These values are converted into strings within the key: a key starting with
// "1_" signifies a metadata entry and one starting with "2_" signifies a // "1_" signifies a metadata entry and one starting with "2_" signifies a
......
...@@ -43377,6 +43377,21 @@ Called by update_net_trust_anchors.py.--> ...@@ -43377,6 +43377,21 @@ Called by update_net_trust_anchors.py.-->
<int value="15" label="Device was reported as offline."/> <int value="15" label="Device was reported as offline."/>
</enum> </enum>
<enum name="PreviewsHintCacheLevelDBStoreLoadMetadataResult">
<int value="0" label="Success"/>
<int value="1" label="LoadMetadataFailed"/>
<int value="2" label="SchemaMetadataMissing"/>
<int value="3" label="SchemaMetadataWrongVersion"/>
<int value="4" label="ComponentMetadataMissing"/>
</enum>
<enum name="PreviewsHintCacheLevelDBStoreStatus">
<int value="0" label="Unitialized"/>
<int value="1" label="Initializing"/>
<int value="2" label="Available"/>
<int value="3" label="Failed"/>
</enum>
<enum name="PreviewsInfoBarAction"> <enum name="PreviewsInfoBarAction">
<int value="0" label="Infobar shown"/> <int value="0" label="Infobar shown"/>
<int value="1" label="Infobar 'Load original' clicked"/> <int value="1" label="Infobar 'Load original' clicked"/>
...@@ -88146,6 +88146,23 @@ uploading your change for review. ...@@ -88146,6 +88146,23 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Previews.HintCacheLevelDBStore.LoadMetadataResult"
enum="PreviewsHintCacheLevelDBStoreLoadMetadataResult">
<owner>jegray@chromium.org</owner>
<summary>
Records the result of loading the metadata while initializing the
HintCacheLevelDBStore.
</summary>
</histogram>
<histogram name="Previews.HintCacheLevelDBStore.Status"
enum="PreviewsHintCacheLevelDBStoreStatus">
<owner>jegray@chromium.org</owner>
<summary>
Records each status change within the HintCacheLevelDBStore.
</summary>
</histogram>
<histogram name="Previews.InfoBarAction" enum="PreviewsInfoBarAction"> <histogram name="Previews.InfoBarAction" enum="PreviewsInfoBarAction">
<owner>bengr@chromium.org</owner> <owner>bengr@chromium.org</owner>
<owner>tbansal@chromium.org</owner> <owner>tbansal@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