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

Side by Side 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: histograms back in JsonPrefStore impl Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/prefs/json_pref_store.h" 5 #include "base/prefs/json_pref_store.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 base::Move(path, bad); 84 base::Move(path, bad);
85 return bad_existed ? PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT 85 return bad_existed ? PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT
86 : PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE; 86 : PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE;
87 } 87 }
88 } else if (!value->IsType(base::Value::TYPE_DICTIONARY)) { 88 } else if (!value->IsType(base::Value::TYPE_DICTIONARY)) {
89 return PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE; 89 return PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE;
90 } 90 }
91 return PersistentPrefStore::PREF_READ_ERROR_NONE; 91 return PersistentPrefStore::PREF_READ_ERROR_NONE;
92 } 92 }
93 93
94 // Records a sample for |size| in the Settings.JsonDataReadSizeKilobytes
95 // histogram suffixed with the base name of the JSON file under |path|.
96 void RecordJsonDataSizeHistogram(const base::FilePath& path, size_t size) {
97 std::string spaceless_basename;
98 base::ReplaceChars(path.BaseName().MaybeAsASCII(), " ", "_",
99 &spaceless_basename);
100
101 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
102 // macro adapted to allow for a dynamically suffixed histogram name.
103 // Note: The factory creates and owns the histogram.
104 base::HistogramBase* histogram = base::Histogram::FactoryGet(
105 "Settings.JsonDataReadSizeKilobytes." + spaceless_basename, 1, 10000, 50,
106 base::HistogramBase::kUmaTargetedHistogramFlag);
107 histogram->Add(static_cast<int>(size) / 1024);
108 }
109
94 scoped_ptr<JsonPrefStore::ReadResult> ReadPrefsFromDisk( 110 scoped_ptr<JsonPrefStore::ReadResult> ReadPrefsFromDisk(
95 const base::FilePath& path, 111 const base::FilePath& path,
96 const base::FilePath& alternate_path) { 112 const base::FilePath& alternate_path) {
97 if (!base::PathExists(path) && !alternate_path.empty() && 113 if (!base::PathExists(path) && !alternate_path.empty() &&
98 base::PathExists(alternate_path)) { 114 base::PathExists(alternate_path)) {
99 base::Move(alternate_path, path); 115 base::Move(alternate_path, path);
100 } 116 }
101 117
102 int error_code; 118 int error_code;
103 std::string error_msg; 119 std::string error_msg;
104 scoped_ptr<JsonPrefStore::ReadResult> read_result( 120 scoped_ptr<JsonPrefStore::ReadResult> read_result(
105 new JsonPrefStore::ReadResult); 121 new JsonPrefStore::ReadResult);
106 JSONFileValueSerializer serializer(path); 122 JSONFileValueSerializer serializer(path);
107 read_result->value.reset(serializer.Deserialize(&error_code, &error_msg)); 123 read_result->value.reset(serializer.Deserialize(&error_code, &error_msg));
108 read_result->error = 124 read_result->error =
109 HandleReadErrors(read_result->value.get(), path, error_code, error_msg); 125 HandleReadErrors(read_result->value.get(), path, error_code, error_msg);
110 read_result->no_dir = !base::PathExists(path.DirName()); 126 read_result->no_dir = !base::PathExists(path.DirName());
127
128 RecordJsonDataSizeHistogram(path, serializer.get_last_read_size());
129
111 return read_result.Pass(); 130 return read_result.Pass();
112 } 131 }
113 132
114 } // namespace 133 } // namespace
115 134
116 // static 135 // static
117 scoped_refptr<base::SequencedTaskRunner> JsonPrefStore::GetTaskRunnerForFile( 136 scoped_refptr<base::SequencedTaskRunner> JsonPrefStore::GetTaskRunnerForFile(
118 const base::FilePath& filename, 137 const base::FilePath& filename,
119 base::SequencedWorkerPool* worker_pool) { 138 base::SequencedWorkerPool* worker_pool) {
120 std::string token("json_pref_store-"); 139 std::string token("json_pref_store-");
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 391 }
373 392
374 bool JsonPrefStore::SerializeData(std::string* output) { 393 bool JsonPrefStore::SerializeData(std::string* output) {
375 DCHECK(CalledOnValidThread()); 394 DCHECK(CalledOnValidThread());
376 395
377 if (pref_filter_) 396 if (pref_filter_)
378 pref_filter_->FilterSerializeData(prefs_.get()); 397 pref_filter_->FilterSerializeData(prefs_.get());
379 398
380 JSONStringValueSerializer serializer(output); 399 JSONStringValueSerializer serializer(output);
381 serializer.set_pretty_print(true); 400 serializer.set_pretty_print(true);
382 bool result = serializer.Serialize(*prefs_); 401 return serializer.Serialize(*prefs_);
383
384 if (result) {
385 std::string spaceless_basename;
386 base::ReplaceChars(path_.BaseName().MaybeAsASCII(), " ", "_",
387 &spaceless_basename);
388
389 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_10000
390 // macro adapted to allow for a dynamically suffixed histogram name.
391 // Note: The factory creates and owns the histogram.
392 base::HistogramBase* histogram =
393 base::LinearHistogram::FactoryGet(
394 "Settings.JsonDataSizeKilobytes." + spaceless_basename,
395 1,
396 10000,
397 50,
398 base::HistogramBase::kUmaTargetedHistogramFlag);
399 histogram->Add(static_cast<int>(output->size()) / 1024);
400 }
401
402 return result;
403 } 402 }
404 403
405 void JsonPrefStore::FinalizeFileRead(bool initialization_successful, 404 void JsonPrefStore::FinalizeFileRead(bool initialization_successful,
406 scoped_ptr<base::DictionaryValue> prefs, 405 scoped_ptr<base::DictionaryValue> prefs,
407 bool schedule_write) { 406 bool schedule_write) {
408 DCHECK(CalledOnValidThread()); 407 DCHECK(CalledOnValidThread());
409 408
410 filtering_in_progress_ = false; 409 filtering_in_progress_ = false;
411 410
412 if (!initialization_successful) { 411 if (!initialization_successful) {
(...skipping 12 matching lines...) Expand all
425 424
426 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE) 425 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE)
427 error_delegate_->OnError(read_error_); 426 error_delegate_->OnError(read_error_);
428 427
429 FOR_EACH_OBSERVER(PrefStore::Observer, 428 FOR_EACH_OBSERVER(PrefStore::Observer,
430 observers_, 429 observers_,
431 OnInitializationCompleted(true)); 430 OnInitializationCompleted(true));
432 431
433 return; 432 return;
434 } 433 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698