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

Unified Diff: net/sdch/sdch_owner.cc

Issue 1051353003: SDCH: add TimeWeightedMemoryUse (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Record more exact creation time Created 5 years, 9 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 | « net/sdch/sdch_owner.h ('k') | net/sdch/sdch_owner_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/sdch/sdch_owner.cc
diff --git a/net/sdch/sdch_owner.cc b/net/sdch/sdch_owner.cc
index 9d985816a9e0350e3930b7c17e7f4f0fdbb85630..09d06ec7b2550ae8334cb49270b6f5f204f12d40 100644
--- a/net/sdch/sdch_owner.cc
+++ b/net/sdch/sdch_owner.cc
@@ -20,43 +20,6 @@ namespace net {
namespace {
-enum DictionaryFate {
- // A Get-Dictionary header wasn't acted on.
- DICTIONARY_FATE_GET_IGNORED = 1,
-
- // A fetch was attempted, but failed.
- // TODO(rdsmith): Actually record this case.
- DICTIONARY_FATE_FETCH_FAILED = 2,
-
- // A successful fetch was dropped on the floor, no space.
- DICTIONARY_FATE_FETCH_IGNORED_NO_SPACE = 3,
-
- // A successful fetch was refused by the SdchManager.
- DICTIONARY_FATE_FETCH_MANAGER_REFUSED = 4,
-
- // A dictionary was successfully added based on
- // a Get-Dictionary header in a response.
- DICTIONARY_FATE_ADD_RESPONSE_TRIGGERED = 5,
-
- // A dictionary was evicted by an incoming dict.
- DICTIONARY_FATE_EVICT_FOR_DICT = 6,
-
- // A dictionary was evicted by memory pressure.
- DICTIONARY_FATE_EVICT_FOR_MEMORY = 7,
-
- // A dictionary was evicted on destruction.
- DICTIONARY_FATE_EVICT_FOR_DESTRUCTION = 8,
-
- // A dictionary was successfully added based on
- // persistence from a previous browser revision.
- DICTIONARY_FATE_ADD_PERSISTENCE_TRIGGERED = 9,
-
- // A dictionary was unloaded on destruction, but is still present on disk.
- DICTIONARY_FATE_UNLOAD_FOR_DESTRUCTION = 10,
-
- DICTIONARY_FATE_MAX = 11
-};
-
enum PersistenceFailureReason {
// File didn't exist; is being created.
PERSISTENCE_FAILURE_REASON_NO_FILE = 1,
@@ -77,25 +40,11 @@ const int kFreshnessLifetimeHours = 24;
// Dictionaries that have never been used only stay fresh for one hour.
const int kNeverUsedFreshnessLifetimeHours = 1;
-void RecordDictionaryFate(enum DictionaryFate fate) {
- UMA_HISTOGRAM_ENUMERATION("Sdch3.DictionaryFate", fate, DICTIONARY_FATE_MAX);
-}
-
void RecordPersistenceFailure(PersistenceFailureReason failure_reason) {
UMA_HISTOGRAM_ENUMERATION("Sdch3.PersistenceFailureReason", failure_reason,
PERSISTENCE_FAILURE_REASON_MAX);
}
-void RecordDictionaryEvictionOrUnload(int use_count, DictionaryFate fate) {
- DCHECK(fate == DICTIONARY_FATE_EVICT_FOR_DICT ||
- fate == DICTIONARY_FATE_EVICT_FOR_MEMORY ||
- fate == DICTIONARY_FATE_EVICT_FOR_DESTRUCTION ||
- fate == DICTIONARY_FATE_UNLOAD_FOR_DESTRUCTION);
-
- UMA_HISTOGRAM_COUNTS_100("Sdch3.DictionaryUseCount", use_count);
- RecordDictionaryFate(fate);
-}
-
// Schema specifications and access routines.
// The persistent prefs store is conceptually shared with any other network
@@ -266,6 +215,28 @@ const size_t SdchOwner::kMaxTotalDictionarySize = 20 * 1000 * 1000;
// amount of space available in storage.
const size_t SdchOwner::kMinSpaceForDictionaryFetch = 50 * 1000;
+void SdchOwner::RecordDictionaryFate(enum DictionaryFate fate) {
+ UMA_HISTOGRAM_ENUMERATION("Sdch3.DictionaryFate", fate, DICTIONARY_FATE_MAX);
+}
+
+void SdchOwner::RecordDictionaryEvictionOrUnload(const std::string& server_hash,
+ size_t size,
+ int use_count,
+ DictionaryFate fate) {
+ DCHECK(fate == DICTIONARY_FATE_EVICT_FOR_DICT ||
+ fate == DICTIONARY_FATE_EVICT_FOR_MEMORY ||
+ fate == DICTIONARY_FATE_EVICT_FOR_DESTRUCTION ||
+ fate == DICTIONARY_FATE_UNLOAD_FOR_DESTRUCTION);
+
+ UMA_HISTOGRAM_COUNTS_100("Sdch3.DictionaryUseCount", use_count);
+ RecordDictionaryFate(fate);
+
+ DCHECK(load_times_.count(server_hash) == 1);
+ base::Time now = clock_->Now();
+ base::TimeDelta dict_lifetime = now - load_times_[server_hash];
+ consumed_byte_seconds_.push_back(size * dict_lifetime.InMilliseconds());
+}
+
SdchOwner::SdchOwner(SdchManager* sdch_manager, URLRequestContext* context)
: manager_(sdch_manager->GetWeakPtr()),
fetcher_(new SdchDictionaryFetcher(context)),
@@ -285,7 +256,8 @@ SdchOwner::SdchOwner(SdchManager* sdch_manager, URLRequestContext* context)
base::Unretained(this))),
in_memory_pref_store_(new ValueMapPrefStore()),
external_pref_store_(nullptr),
- pref_store_(in_memory_pref_store_.get()) {
+ pref_store_(in_memory_pref_store_.get()),
+ creation_time_(clock_->Now()) {
#if defined(OS_CHROMEOS)
// For debugging http://crbug.com/454198; remove when resolved.
CHECK(clock_.get());
@@ -309,7 +281,8 @@ SdchOwner::~SdchOwner() {
DictionaryFate fate = IsPersistingDictionaries() ?
DICTIONARY_FATE_UNLOAD_FOR_DESTRUCTION :
DICTIONARY_FATE_EVICT_FOR_DESTRUCTION;
- RecordDictionaryEvictionOrUnload(new_uses, fate);
+ RecordDictionaryEvictionOrUnload(it.server_hash(), it.size(), new_uses,
+ fate);
}
manager_->RemoveObserver(this);
@@ -318,6 +291,13 @@ SdchOwner::~SdchOwner() {
if (external_pref_store_)
external_pref_store_->RemoveObserver(this);
+ int64 process_lifetime =
+ (clock_->Now() - creation_time_).InMilliseconds();
+ for (auto& val : consumed_byte_seconds_) {
Ilya Sherman 2015/04/03 20:42:17 nit: "const auto&"?
+ UMA_HISTOGRAM_COUNTS("Sdch3.TimeWeightedMemoryUse",
+ val / process_lifetime);
Ilya Sherman 2015/04/03 20:42:17 Optional: Maybe use UMA_HISTOGRAM_MEMORY_KB here?
+ }
+
#if defined(OS_CHROMEOS)
destroyed_ = 0xdeadbeef;
#endif
@@ -450,7 +430,9 @@ void SdchOwner::OnDictionaryFetched(base::Time last_used,
int new_uses = stale_it->use_count -
use_counts_at_load_[stale_it->server_hash];
- RecordDictionaryEvictionOrUnload(new_uses,
+ RecordDictionaryEvictionOrUnload(stale_it->server_hash,
+ stale_it->dictionary_size,
+ new_uses,
DICTIONARY_FATE_EVICT_FOR_DICT);
++stale_it;
@@ -487,6 +469,7 @@ void SdchOwner::OnDictionaryFetched(base::Time last_used,
dictionary_description->SetInteger(kDictionarySizeKey,
dictionary_text.size());
pref_dictionary_map->Set(server_hash, dictionary_description.Pass());
+ load_times_[server_hash] = clock_->Now();
}
void SdchOwner::OnDictionaryUsed(SdchManager* manager,
@@ -719,7 +702,9 @@ void SdchOwner::OnMemoryPressure(
for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd();
it.Advance()) {
int new_uses = it.use_count() - use_counts_at_load_[it.server_hash()];
- RecordDictionaryEvictionOrUnload(new_uses,
+ RecordDictionaryEvictionOrUnload(it.server_hash(),
+ it.size(),
+ new_uses,
DICTIONARY_FATE_EVICT_FOR_MEMORY);
}
« no previous file with comments | « net/sdch/sdch_owner.h ('k') | net/sdch/sdch_owner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698