Chromium Code Reviews| Index: components/metrics/leak_detector/call_stack_table.cc |
| diff --git a/components/metrics/leak_detector/call_stack_table.cc b/components/metrics/leak_detector/call_stack_table.cc |
| index 8f9540bc0d4b35f6f619c350fd8c13ba2fc1514f..40ce275dd7a1026af5738a0f82d9e9597e87dac8 100644 |
| --- a/components/metrics/leak_detector/call_stack_table.cc |
| +++ b/components/metrics/leak_detector/call_stack_table.cc |
| @@ -42,7 +42,7 @@ CallStackTable::CallStackTable(int call_stack_suspicion_threshold) |
| CallStackTable::~CallStackTable() {} |
| void CallStackTable::Add(const CallStack* call_stack) { |
| - ++entry_map_[call_stack]; |
| + ++entry_map_[call_stack].count; |
| ++num_allocs_; |
| } |
| @@ -50,7 +50,7 @@ void CallStackTable::Remove(const CallStack* call_stack) { |
| auto iter = entry_map_.find(call_stack); |
| if (iter == entry_map_.end()) |
| return; |
| - uint32_t& count_for_call_stack = iter->second; |
| + uint32_t& count_for_call_stack = iter->second.count; |
| --count_for_call_stack; |
| ++num_frees_; |
| @@ -67,9 +67,40 @@ void CallStackTable::TestForLeaks() { |
| } |
| void CallStackTable::GetTopCallStacks(RankedSet* top_entries) const { |
| - for (const auto& call_stack_and_count : entry_map_) { |
| - top_entries->AddCallStack(call_stack_and_count.first, |
| - call_stack_and_count.second); |
| + for (const auto& call_stack_count_info : entry_map_) { |
| + top_entries->AddCallStack(call_stack_count_info.first, |
| + call_stack_count_info.second.count); |
| + } |
| +} |
| + |
| +void CallStackTable::UpdateLastDropInfo(size_t timestamp) { |
| + for (auto& call_stack_and_info : entry_map_) { |
| + auto& count_info = call_stack_and_info.second; |
| + |
| + // If the |previous_count| is 0 then we need to initialize info. |
| + if (count_info.previous_count == 0 || |
| + count_info.count < count_info.previous_count) { |
| + count_info.last_drop_timestamp = timestamp; |
| + count_info.last_drop_count = count_info.count; |
| + } |
| + count_info.previous_count = count_info.count; |
| + } |
| +} |
| + |
| +void CallStackTable::GetLastUptrendInfo( |
| + const CallStack* call_stack, size_t timestamp, size_t* timestamp_delta, |
| + uint32_t* count_delta) const { |
| + const auto& call_stack_count_info_iter = entry_map_.find(call_stack); |
| + |
| + if (call_stack_count_info_iter != entry_map_.end()) { |
| + const auto& count_info = call_stack_count_info_iter->second; |
| + *timestamp_delta = timestamp - count_info.last_drop_timestamp; |
| + *count_delta = count_info.count - count_info.last_drop_count; |
| + } else { |
| + LOG(WARNING) << "Accessing information about a call stack that has not " << |
| + "been recorded"; |
|
Simon Que
2016/10/11 08:14:04
The LOG(WARNING) is unnecessary since this case sh
mwlodar
2016/10/11 20:24:03
Done.
|
| + *timestamp_delta = timestamp; |
| + *count_delta = 0; |
| } |
| } |