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

Unified Diff: base/prefs/json_pref_store.cc

Issue 891663003: Log pref file size histogram on read rather than on write. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits / format / only log on successful read Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/json/json_file_value_serializer.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/prefs/json_pref_store.cc
diff --git a/base/prefs/json_pref_store.cc b/base/prefs/json_pref_store.cc
index e35ed295d699b68ffe50d707d1864b8dcc046125..c52a95c9cc2b7b675059cbd6d91574a465633eba 100644
--- a/base/prefs/json_pref_store.cc
+++ b/base/prefs/json_pref_store.cc
@@ -91,6 +91,22 @@ PersistentPrefStore::PrefReadError HandleReadErrors(
return PersistentPrefStore::PREF_READ_ERROR_NONE;
}
+// Records a sample for |size| in the Settings.JsonDataReadSizeKilobytes
+// histogram suffixed with the base name of the JSON file under |path|.
+void RecordJsonDataSizeHistogram(const base::FilePath& path, size_t size) {
+ std::string spaceless_basename;
+ base::ReplaceChars(path.BaseName().MaybeAsASCII(), " ", "_",
+ &spaceless_basename);
+
+ // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
+ // macro adapted to allow for a dynamically suffixed histogram name.
+ // Note: The factory creates and owns the histogram.
+ base::HistogramBase* histogram = base::Histogram::FactoryGet(
+ "Settings.JsonDataReadSizeKilobytes." + spaceless_basename, 1, 10000, 50,
+ base::HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add(static_cast<int>(size) / 1024);
+}
+
scoped_ptr<JsonPrefStore::ReadResult> ReadPrefsFromDisk(
const base::FilePath& path,
const base::FilePath& alternate_path) {
@@ -108,6 +124,10 @@ scoped_ptr<JsonPrefStore::ReadResult> ReadPrefsFromDisk(
read_result->error =
HandleReadErrors(read_result->value.get(), path, error_code, error_msg);
read_result->no_dir = !base::PathExists(path.DirName());
+
+ if (read_result->error == PersistentPrefStore::PREF_READ_ERROR_NONE)
+ RecordJsonDataSizeHistogram(path, serializer.get_last_read_size());
+
return read_result.Pass();
}
@@ -379,27 +399,7 @@ bool JsonPrefStore::SerializeData(std::string* output) {
JSONStringValueSerializer serializer(output);
serializer.set_pretty_print(true);
- bool result = serializer.Serialize(*prefs_);
-
- if (result) {
- std::string spaceless_basename;
- base::ReplaceChars(path_.BaseName().MaybeAsASCII(), " ", "_",
- &spaceless_basename);
-
- // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_10000
- // macro adapted to allow for a dynamically suffixed histogram name.
- // Note: The factory creates and owns the histogram.
- base::HistogramBase* histogram =
- base::LinearHistogram::FactoryGet(
- "Settings.JsonDataSizeKilobytes." + spaceless_basename,
- 1,
- 10000,
- 50,
- base::HistogramBase::kUmaTargetedHistogramFlag);
- histogram->Add(static_cast<int>(output->size()) / 1024);
- }
-
- return result;
+ return serializer.Serialize(*prefs_);
}
void JsonPrefStore::FinalizeFileRead(bool initialization_successful,
« no previous file with comments | « base/json/json_file_value_serializer.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698