Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/metrics/leak_detector/call_stack_table.h" | |
| 6 | |
| 7 #include "components/metrics/leak_detector/call_stack_manager.h" | |
| 8 | |
| 9 namespace metrics { | |
| 10 namespace leak_detector { | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 using ValueType = LeakDetectorValueType; | |
| 15 | |
| 16 // Get the top |kRankedListSize| entries. | |
|
jar (doing other things)
2015/11/14 02:58:36
I don't understand this comment. Perhaps the comm
Simon Que
2015/11/17 00:28:48
Done.
| |
| 17 const int kRankedListSize = 16; | |
| 18 | |
| 19 // Initial number of hash table buckets. | |
|
jar (doing other things)
2015/11/14 02:58:36
nit: your choice... but the name of the variable s
Simon Que
2015/11/17 00:28:48
Done.
| |
| 20 const int kInitialHashTableSize = 1999; | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 size_t CallStackTable::StoredHash::operator() ( | |
| 25 const CallStack* call_stack) const { | |
| 26 // The call stack object should already have a hash computed when it was | |
| 27 // created. | |
| 28 // | |
| 29 // This is NOT the actual hash computation function for a new call stack. | |
| 30 return call_stack->hash; | |
| 31 } | |
| 32 | |
| 33 CallStackTable::CallStackTable(int call_stack_suspicion_threshold) | |
| 34 : num_allocs_(0), | |
| 35 num_frees_(0), | |
| 36 entry_map_(kInitialHashTableSize), | |
| 37 leak_analyzer_(kRankedListSize, call_stack_suspicion_threshold) { | |
| 38 } | |
| 39 | |
| 40 CallStackTable::~CallStackTable() {} | |
| 41 | |
| 42 void CallStackTable::Add(const CallStack* call_stack) { | |
| 43 auto iter = entry_map_.find(call_stack); | |
| 44 Entry* entry = nullptr; | |
| 45 if (iter == entry_map_.end()) { | |
| 46 entry = &entry_map_[call_stack]; | |
|
jar (doing other things)
2015/11/14 02:58:36
Would it have been enough to just do this operator
Simon Que
2015/11/17 00:28:48
Done.
| |
| 47 } else { | |
| 48 entry = &iter->second; | |
| 49 } | |
| 50 | |
| 51 ++entry->net_num_allocs; | |
| 52 ++num_allocs_; | |
| 53 } | |
| 54 | |
| 55 void CallStackTable::Remove(const CallStack* call_stack) { | |
| 56 auto iter = entry_map_.find(call_stack); | |
| 57 if (iter == entry_map_.end()) | |
| 58 return; | |
| 59 Entry* entry = &iter->second; | |
| 60 --entry->net_num_allocs; | |
| 61 ++num_frees_; | |
| 62 | |
| 63 // Delete zero-alloc entries to free up space. | |
| 64 if (entry->net_num_allocs == 0) | |
| 65 entry_map_.erase(iter); | |
| 66 } | |
| 67 | |
| 68 void CallStackTable::TestForLeaks() { | |
| 69 // Add all entries to the ranked list. | |
| 70 RankedList ranked_list(kRankedListSize); | |
| 71 | |
| 72 for (const auto& entry_pair : entry_map_) { | |
| 73 const Entry& entry = entry_pair.second; | |
| 74 if (entry.net_num_allocs > 0) { | |
|
jar (doing other things)
2015/11/14 02:58:36
Given line 65, which seems to discard any entries
Simon Que
2015/11/17 00:28:48
Done.
| |
| 75 LeakDetectorValueType call_stack_value(entry_pair.first); | |
| 76 ranked_list.Add(call_stack_value, entry.net_num_allocs); | |
| 77 } | |
| 78 } | |
| 79 leak_analyzer_.AddSample(ranked_list.Pass()); | |
| 80 } | |
| 81 | |
| 82 } // namespace leak_detector | |
| 83 } // namespace metrics | |
| OLD | NEW |