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

Unified Diff: components/metrics/persisted_logs.cc

Issue 2588873002: Delegate PersistedLogs metrics recording (Closed)
Patch Set: Histogram description Created 4 years 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
Index: components/metrics/persisted_logs.cc
diff --git a/components/metrics/persisted_logs.cc b/components/metrics/persisted_logs.cc
index 12d3a6821885aac896df975787e81447889f8c43..a407a0d46970e04f192011fd047bf7545d84c668 100644
--- a/components/metrics/persisted_logs.cc
+++ b/components/metrics/persisted_logs.cc
@@ -14,6 +14,7 @@
#include "base/sha1.h"
#include "base/strings/string_number_conversions.h"
#include "base/timer/elapsed_timer.h"
+#include "components/metrics/persisted_logs_metrics.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "third_party/zlib/google/compression_utils.h"
@@ -26,13 +27,6 @@ const char kLogHashKey[] = "hash";
const char kLogTimestampKey[] = "timestamp";
const char kLogDataKey[] = "data";
-PersistedLogs::LogReadStatus MakeRecallStatusHistogram(
- PersistedLogs::LogReadStatus status) {
- UMA_HISTOGRAM_ENUMERATION("PrefService.PersistentLogRecallProtobufs",
- status, PersistedLogs::END_RECALL_STATUS);
- return status;
-}
-
// Reads the value at |index| from |list_value| as a string and Base64-decodes
// it into |result|. Returns true on success.
bool ReadBase64String(const base::ListValue& list_value,
@@ -58,7 +52,8 @@ std::string DecodeFromBase64(const std::string& to_convert) {
} // namespace
-void PersistedLogs::LogInfo::Init(const std::string& log_data,
+void PersistedLogs::LogInfo::Init(PersistedLogsMetrics* metrics,
+ const std::string& log_data,
const std::string& log_timestamp) {
DCHECK(!log_data.empty());
@@ -67,21 +62,21 @@ void PersistedLogs::LogInfo::Init(const std::string& log_data,
return;
}
- UMA_HISTOGRAM_PERCENTAGE(
- "UMA.ProtoCompressionRatio",
- static_cast<int>(100 * compressed_log_data.size() / log_data.size()));
+ metrics->RecordCompressionRatio(compressed_log_data.size(), log_data.size());
hash = base::SHA1HashString(log_data);
timestamp = log_timestamp;
}
-PersistedLogs::PersistedLogs(PrefService* local_state,
+PersistedLogs::PersistedLogs(std::unique_ptr<PersistedLogsMetrics> metrics,
+ PrefService* local_state,
const char* pref_name,
const char* outdated_pref_name,
size_t min_log_count,
size_t min_log_bytes,
size_t max_log_size)
- : local_state_(local_state),
+ : metrics_(std::move(metrics)),
+ local_state_(local_state),
pref_name_(pref_name),
outdated_pref_name_(outdated_pref_name),
min_log_count_(min_log_count),
@@ -117,7 +112,9 @@ PersistedLogs::LogReadStatus PersistedLogs::DeserializeLogs() {
void PersistedLogs::StoreLog(const std::string& log_data) {
list_.push_back(LogInfo());
- list_.back().Init(log_data, base::Int64ToString(base::Time::Now().ToTimeT()));
+ list_.back().Init(metrics_.get(),
+ log_data,
+ base::Int64ToString(base::Time::Now().ToTimeT()));
}
void PersistedLogs::StageLog() {
@@ -139,7 +136,7 @@ void PersistedLogs::DiscardStagedLog() {
PersistedLogs::LogReadStatus PersistedLogs::ReadLogsFromPrefList(
const base::ListValue& list_value) {
if (list_value.empty())
- return MakeRecallStatusHistogram(LIST_EMPTY);
+ return metrics_->RecordLogReadStatus(LIST_EMPTY);
const size_t log_count = list_value.GetSize();
@@ -152,7 +149,7 @@ PersistedLogs::LogReadStatus PersistedLogs::ReadLogsFromPrefList(
!dict->GetString(kLogDataKey, &list_[i].compressed_log_data) ||
!dict->GetString(kLogHashKey, &list_[i].hash)) {
list_.clear();
- return MakeRecallStatusHistogram(LOG_STRING_CORRUPTION);
+ return metrics_->RecordLogReadStatus(LOG_STRING_CORRUPTION);
}
list_[i].compressed_log_data =
@@ -165,7 +162,7 @@ PersistedLogs::LogReadStatus PersistedLogs::ReadLogsFromPrefList(
dict->GetString(kLogTimestampKey, &list_[i].timestamp);
}
- return MakeRecallStatusHistogram(RECALL_SUCCESS);
+ return metrics_->RecordLogReadStatus(RECALL_SUCCESS);
}
void PersistedLogs::WriteLogsToPrefList(base::ListValue* list_value) const {
@@ -194,8 +191,7 @@ void PersistedLogs::WriteLogsToPrefList(base::ListValue* list_value) const {
for (size_t i = start; i < list_.size(); ++i) {
size_t log_size = list_[i].compressed_log_data.length();
if (log_size > max_log_size_) {
- UMA_HISTOGRAM_COUNTS("UMA.Large Accumulated Log Not Persisted",
- static_cast<int>(log_size));
+ metrics_->RecordDroppedLogSize(log_size);
dropped_logs_num++;
continue;
}
@@ -208,13 +204,13 @@ void PersistedLogs::WriteLogsToPrefList(base::ListValue* list_value) const {
list_value->Append(std::move(dict_value));
}
if (dropped_logs_num > 0)
- UMA_HISTOGRAM_COUNTS("UMA.UnsentLogs.Dropped", dropped_logs_num);
+ metrics_->RecordDroppedLogsNum(dropped_logs_num);
}
PersistedLogs::LogReadStatus PersistedLogs::ReadLogsFromOldFormatPrefList(
const base::ListValue& list_value) {
if (list_value.empty())
- return MakeRecallStatusHistogram(LIST_EMPTY);
+ return metrics_->RecordLogReadStatus(LIST_EMPTY);
// For each log, there's two entries in the list (the data and the hash).
DCHECK_EQ(0U, list_value.GetSize() % 2);
@@ -229,11 +225,11 @@ PersistedLogs::LogReadStatus PersistedLogs::ReadLogsFromOldFormatPrefList(
if (!ReadBase64String(list_value, i * 2, &list_[i].compressed_log_data) ||
!ReadBase64String(list_value, i * 2 + 1, &list_[i].hash)) {
list_.clear();
- return MakeRecallStatusHistogram(LOG_STRING_CORRUPTION);
+ return metrics_->RecordLogReadStatus(LOG_STRING_CORRUPTION);
}
}
- return MakeRecallStatusHistogram(RECALL_SUCCESS);
+ return metrics_->RecordLogReadStatus(RECALL_SUCCESS);
}
} // namespace metrics

Powered by Google App Engine
This is Rietveld 408576698