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

Unified Diff: components/sync/model_impl/model_type_store_backend.cc

Issue 2696703007: [Sync] Record histogram of ModelTypeStoreBackend initialization result (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/model_impl/model_type_store_backend.cc
diff --git a/components/sync/model_impl/model_type_store_backend.cc b/components/sync/model_impl/model_type_store_backend.cc
index 37ee1c8eb9a5c8507d5584d26f91b39644285b63..7ee2c6aaede1bc2cf08aeb77de1e2caa5db82271 100644
--- a/components/sync/model_impl/model_type_store_backend.cc
+++ b/components/sync/model_impl/model_type_store_backend.cc
@@ -8,6 +8,7 @@
#include "base/files/file_path.h"
#include "base/memory/ptr_util.h"
+#include "base/metrics/histogram_macros.h"
#include "components/sync/protocol/model_type_store_schema_descriptor.pb.h"
#include "third_party/leveldatabase/env_chromium.h"
#include "third_party/leveldatabase/src/helpers/memenv/memenv.h"
@@ -32,6 +33,55 @@ const char ModelTypeStoreBackend::kDBSchemaDescriptorRecordId[] =
base::LazyInstance<ModelTypeStoreBackend::BackendMap>
ModelTypeStoreBackend::backend_map_ = LAZY_INSTANCE_INITIALIZER;
+namespace {
+
+// Different reasons for ModelTypeStoreBackend initialization failure are mapped
+// to these values. The enum is used for recording UMA histogram. Don't reorder,
+// change or delete values.
+enum StoreInitResultForHistogram {
+ STORE_INIT_RESULT_SUCCESS = 0,
+
+ // Following values reflect leveldb initialization errors.
+ STORE_INIT_RESULT_NOT_FOUND,
+ STORE_INIT_RESULT_CORRUPTION,
+ STORE_INIT_RESULT_NOT_SUPPORTED,
+ STORE_INIT_RESULT_INVALID_ARGUMENT,
+ STORE_INIT_RESULT_IO_ERROR,
+
+ // Issues encountered when reading or parsing schema descriptor.
+ STORE_INIT_RESULT_SCHEMA_DESCRIPTOR_ISSUE,
+
+ // Database schema migration failed.
+ STORE_INIT_RESULT_MIGRATION,
+
+ STORE_INIT_RESULT_UNKNOWN,
+ STORE_INIT_RESULT_COUNT
+};
+
+void RecordStoreInitResultHistogram(StoreInitResultForHistogram result) {
+ UMA_HISTOGRAM_ENUMERATION("Sync.ModelTypeStoreInitResult", result,
+ STORE_INIT_RESULT_COUNT);
+}
+
+StoreInitResultForHistogram LevelDbStatusToStoreInitResult(
+ const leveldb::Status& status) {
+ if (status.ok())
+ return STORE_INIT_RESULT_SUCCESS;
+ if (status.IsNotFound())
+ return STORE_INIT_RESULT_NOT_FOUND;
+ if (status.IsCorruption())
+ return STORE_INIT_RESULT_CORRUPTION;
+ if (status.IsNotSupportedError())
+ return STORE_INIT_RESULT_NOT_SUPPORTED;
+ if (status.IsInvalidArgument())
+ return STORE_INIT_RESULT_INVALID_ARGUMENT;
+ if (status.IsIOError())
+ return STORE_INIT_RESULT_IO_ERROR;
+ return STORE_INIT_RESULT_UNKNOWN;
+}
+
+} // namespace
+
ModelTypeStoreBackend::ModelTypeStoreBackend(const std::string& path)
: path_(path) {}
@@ -85,12 +135,14 @@ ModelTypeStore::Result ModelTypeStoreBackend::Init(
leveldb::Status status = leveldb::DB::Open(options, path, &db_raw);
if (!status.ok()) {
DCHECK(db_raw == nullptr);
+ RecordStoreInitResultHistogram(LevelDbStatusToStoreInitResult(status));
return ModelTypeStore::Result::UNSPECIFIED_ERROR;
}
db_.reset(db_raw);
int64_t current_version = GetStoreVersion();
if (current_version == kInvalidSchemaVersion) {
+ RecordStoreInitResultHistogram(STORE_INIT_RESULT_SCHEMA_DESCRIPTOR_ISSUE);
return ModelTypeStore::Result::UNSPECIFIED_ERROR;
}
@@ -98,9 +150,11 @@ ModelTypeStore::Result ModelTypeStoreBackend::Init(
ModelTypeStore::Result result =
Migrate(current_version, kLatestSchemaVersion);
if (result != ModelTypeStore::Result::SUCCESS) {
+ RecordStoreInitResultHistogram(STORE_INIT_RESULT_MIGRATION);
return result;
}
}
+ RecordStoreInitResultHistogram(STORE_INIT_RESULT_SUCCESS);
return ModelTypeStore::Result::SUCCESS;
}
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698