| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/metrics/leak_detector/leak_detector_impl.h" | 5 #include "components/metrics/leak_detector/leak_detector_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 detector_->RecordAlloc(ptr, size, stack.depth, | 177 detector_->RecordAlloc(ptr, size, stack.depth, |
| 178 reinterpret_cast<const void* const*>(stack.stack)); | 178 reinterpret_cast<const void* const*>(stack.stack)); |
| 179 | 179 |
| 180 EXPECT_TRUE(alloced_ptrs_.find(ptr) == alloced_ptrs_.end()); | 180 EXPECT_TRUE(alloced_ptrs_.find(ptr) == alloced_ptrs_.end()); |
| 181 alloced_ptrs_.insert(ptr); | 181 alloced_ptrs_.insert(ptr); |
| 182 | 182 |
| 183 ++total_num_allocs_; | 183 ++total_num_allocs_; |
| 184 total_alloced_size_ += size; | 184 total_alloced_size_ += size; |
| 185 if (total_alloced_size_ >= next_analysis_total_alloced_size_) { | 185 if (total_alloced_size_ >= next_analysis_total_alloced_size_) { |
| 186 InternalVector<InternalLeakReport> reports; | 186 InternalVector<InternalLeakReport> reports; |
| 187 detector_->TestForLeaks(&reports, 1024); | 187 detector_->TestForLeaks(&reports); |
| 188 for (const InternalLeakReport& report : reports) { | 188 for (const InternalLeakReport& report : reports) { |
| 189 auto iter = stored_reports_.find(report); | 189 auto iter = stored_reports_.find(report); |
| 190 if (iter == stored_reports_.end()) { | 190 if (iter == stored_reports_.end()) { |
| 191 stored_reports_.insert(report); | 191 stored_reports_.insert(report); |
| 192 } else { | 192 } else { |
| 193 // InternalLeakReports are uniquely identified by |alloc_size_bytes_| | 193 // InternalLeakReports are uniquely identified by |alloc_size_bytes_| |
| 194 // and |call_stack_|. See InternalLeakReport::operator<(). | 194 // and |call_stack_|. See InternalLeakReport::operator<(). |
| 195 // If a report with the same size and call stack already exists, | 195 // If a report with the same size and call stack already exists, |
| 196 // overwrite it with the new report, which has a newer history. | 196 // overwrite it with the new report, which has a newer history. |
| 197 stored_reports_.erase(iter); | 197 stored_reports_.erase(iter); |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 | 742 |
| 743 EXPECT_GT(counts_by_size[size_1_index], counts_by_size[size_0_index] * 10); | 743 EXPECT_GT(counts_by_size[size_1_index], counts_by_size[size_0_index] * 10); |
| 744 EXPECT_GT(counts_by_size[size_2_index], counts_by_size[size_0_index] * 10); | 744 EXPECT_GT(counts_by_size[size_2_index], counts_by_size[size_0_index] * 10); |
| 745 | 745 |
| 746 // |report1| and |report2| do not necessarily have the same allocation history | 746 // |report1| and |report2| do not necessarily have the same allocation history |
| 747 // due to the different rates at which they were generated. | 747 // due to the different rates at which they were generated. |
| 748 } | 748 } |
| 749 | 749 |
| 750 } // namespace leak_detector | 750 } // namespace leak_detector |
| 751 } // namespace metrics | 751 } // namespace metrics |
| OLD | NEW |