Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.h" | 5 #include "components/metrics/leak_detector/leak_detector.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 } | 114 } |
| 115 | 115 |
| 116 for (const auto& entry : report.alloc_breakdown_history()) { | 116 for (const auto& entry : report.alloc_breakdown_history()) { |
| 117 auto* proto_entry = proto.add_alloc_breakdown_history(); | 117 auto* proto_entry = proto.add_alloc_breakdown_history(); |
| 118 for (const uint32_t count : entry.counts_by_size) { | 118 for (const uint32_t count : entry.counts_by_size) { |
| 119 proto_entry->add_counts_by_size(count); | 119 proto_entry->add_counts_by_size(count); |
| 120 } | 120 } |
| 121 proto_entry->set_count_for_call_stack(entry.count_for_call_stack); | 121 proto_entry->set_count_for_call_stack(entry.count_for_call_stack); |
| 122 } | 122 } |
| 123 | 123 |
| 124 proto.set_num_rising_intervals(report.num_rising_intervals()); | |
| 125 proto.set_num_allocs_increase(report.num_allocs_increase()); | |
| 126 | |
| 124 return proto; | 127 return proto; |
| 125 } | 128 } |
| 126 | 129 |
| 127 // The only instance of LeakDetector that should be used. | 130 // The only instance of LeakDetector that should be used. |
| 128 base::LazyInstance<LeakDetector>::Leaky g_instance = LAZY_INSTANCE_INITIALIZER; | 131 base::LazyInstance<LeakDetector>::Leaky g_instance = LAZY_INSTANCE_INITIALIZER; |
| 129 | 132 |
| 130 // Thread-specific data to be used by hook functions. | 133 // Thread-specific data to be used by hook functions. |
| 131 base::LazyInstance<base::ThreadLocalPointer<void>>::Leaky g_hook_data_tls = | 134 base::LazyInstance<base::ThreadLocalPointer<void>>::Leaky g_hook_data_tls = |
| 132 LAZY_INSTANCE_INITIALIZER; | 135 LAZY_INSTANCE_INITIALIZER; |
| 133 | 136 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 | 269 |
| 267 // Check for leaks after |analysis_interval_bytes_| bytes have been | 270 // Check for leaks after |analysis_interval_bytes_| bytes have been |
| 268 // allocated since the last time that was done. | 271 // allocated since the last time that was done. |
| 269 if (total_alloc_size > | 272 if (total_alloc_size > |
| 270 detector->last_analysis_alloc_size_ + analysis_interval_bytes) { | 273 detector->last_analysis_alloc_size_ + analysis_interval_bytes) { |
| 271 // Try to maintain regular intervals of size |analysis_interval_bytes_|. | 274 // Try to maintain regular intervals of size |analysis_interval_bytes_|. |
| 272 detector->last_analysis_alloc_size_ = | 275 detector->last_analysis_alloc_size_ = |
| 273 total_alloc_size - total_alloc_size % analysis_interval_bytes; | 276 total_alloc_size - total_alloc_size % analysis_interval_bytes; |
| 274 | 277 |
| 275 InternalVector<InternalLeakReport> leak_reports; | 278 InternalVector<InternalLeakReport> leak_reports; |
| 276 detector->impl_->TestForLeaks(&leak_reports); | 279 detector->impl_->TestForLeaks(&leak_reports, total_alloc_size); |
| 280 for(auto &report : leak_reports) | |
|
Simon Que
2016/10/11 01:11:06
Nit: space after "for"
Nit: "auto& report"
mwlodar
2016/10/11 07:13:24
Done.
| |
| 281 report.normalize_num_rising_intervals(analysis_interval_bytes); | |
|
Simon Que
2016/10/11 01:11:06
Do the division here. See my comments in that func
mwlodar
2016/10/11 07:13:24
Done.
| |
| 277 | 282 |
| 278 // Pass leak reports to observers. | 283 // Pass leak reports to observers. |
| 279 std::vector<MemoryLeakReportProto> leak_report_protos; | 284 std::vector<MemoryLeakReportProto> leak_report_protos; |
| 280 leak_report_protos.reserve(leak_reports.size()); | 285 leak_report_protos.reserve(leak_reports.size()); |
| 281 std::transform(leak_reports.begin(), leak_reports.end(), | 286 std::transform(leak_reports.begin(), leak_reports.end(), |
| 282 std::back_inserter(leak_report_protos), | 287 std::back_inserter(leak_report_protos), |
| 283 &ConvertLeakReportToProto); | 288 &ConvertLeakReportToProto); |
| 284 detector->NotifyObservers(leak_report_protos); | 289 detector->NotifyObservers(leak_report_protos); |
| 285 } | 290 } |
| 286 } | 291 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 return; | 341 return; |
| 337 } | 342 } |
| 338 | 343 |
| 339 { | 344 { |
| 340 base::AutoLock lock(observers_lock_); | 345 base::AutoLock lock(observers_lock_); |
| 341 FOR_EACH_OBSERVER(Observer, observers_, OnLeaksFound(reports)); | 346 FOR_EACH_OBSERVER(Observer, observers_, OnLeaksFound(reports)); |
| 342 } | 347 } |
| 343 } | 348 } |
| 344 | 349 |
| 345 } // namespace metrics | 350 } // namespace metrics |
| OLD | NEW |