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..34868e8a666f5a7856c2e74b10e0121b55db8712 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); |
|
Simon Que
2016/10/11 01:11:05
The parentheses are not necessary. [] and . have h
mwlodar
2016/10/11 07:13:23
Done.
|
| ++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,41 @@ 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& call_stack_count_info = call_stack_and_info.second; |
|
Simon Que
2016/10/11 01:11:05
Nit: Easier to just call this "count_info". Also i
mwlodar
2016/10/11 07:13:23
Done.
|
| + |
| + // If the |previous_count| is 0 then we need to initialize info. |
|
Simon Que
2016/10/11 01:11:05
Where is each CallStackCountInfo initialized? They
mwlodar
2016/10/11 07:13:23
I have defined a constructor for CallStackCountInf
|
| + if (call_stack_count_info.previous_count == 0 || |
| + call_stack_count_info.count < call_stack_count_info.previous_count) { |
| + call_stack_count_info.last_drop_timestamp = timestamp; |
| + call_stack_count_info.last_drop_count = call_stack_count_info.count; |
| + } |
| + call_stack_count_info.previous_count = call_stack_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& call_stack_count_info = call_stack_count_info_iter->second; |
| + *timestamp_delta = timestamp - call_stack_count_info.last_drop_timestamp; |
| + *count_delta = call_stack_count_info.count - |
| + call_stack_count_info.last_drop_count; |
| + } else { |
| + LOG(WARNING) << "Accessing information about a call stack that has not " << |
| + "been recorded"; |
| + *timestamp_delta = timestamp; |
| + *count_delta = 0; |
| } |
| } |