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

Unified Diff: base/prefs/json_pref_store.cc

Issue 391893002: Track size of files serialized by the JsonPrefStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win64 compile: static_cast size_t to int... Created 6 years, 5 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: base/prefs/json_pref_store.cc
diff --git a/base/prefs/json_pref_store.cc b/base/prefs/json_pref_store.cc
index 9180984d0e8b9008b288ff846f3eafdd72c24f63..fd95b73115bcd1f8f122cad7ab8b00b9f97d95c6 100644
--- a/base/prefs/json_pref_store.cc
+++ b/base/prefs/json_pref_store.cc
@@ -9,12 +9,15 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/file_util.h"
+#include "base/files/file_path.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/json_string_value_serializer.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop_proxy.h"
+#include "base/metrics/histogram.h"
#include "base/prefs/pref_filter.h"
#include "base/sequenced_task_runner.h"
+#include "base/strings/string_util.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/values.h"
@@ -388,7 +391,27 @@ bool JsonPrefStore::SerializeData(std::string* output) {
JSONStringValueSerializer serializer(output);
serializer.set_pretty_print(true);
- return serializer.Serialize(*prefs_);
+ 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;
}
void JsonPrefStore::FinalizeFileRead(bool initialization_successful,
« 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