| 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 | |
| 127 return proto; | 124 return proto; |
| 128 } | 125 } |
| 129 | 126 |
| 130 // The only instance of LeakDetector that should be used. | 127 // The only instance of LeakDetector that should be used. |
| 131 base::LazyInstance<LeakDetector>::Leaky g_instance = LAZY_INSTANCE_INITIALIZER; | 128 base::LazyInstance<LeakDetector>::Leaky g_instance = LAZY_INSTANCE_INITIALIZER; |
| 132 | 129 |
| 133 // Thread-specific data to be used by hook functions. | 130 // Thread-specific data to be used by hook functions. |
| 134 base::LazyInstance<base::ThreadLocalPointer<void>>::Leaky g_hook_data_tls = | 131 base::LazyInstance<base::ThreadLocalPointer<void>>::Leaky g_hook_data_tls = |
| 135 LAZY_INSTANCE_INITIALIZER; | 132 LAZY_INSTANCE_INITIALIZER; |
| 136 | 133 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 } | 265 } |
| 269 | 266 |
| 270 // Check for leaks after |analysis_interval_bytes_| bytes have been | 267 // Check for leaks after |analysis_interval_bytes_| bytes have been |
| 271 // allocated since the last time that was done. | 268 // allocated since the last time that was done. |
| 272 if (total_alloc_size > | 269 if (total_alloc_size > |
| 273 detector->last_analysis_alloc_size_ + analysis_interval_bytes) { | 270 detector->last_analysis_alloc_size_ + analysis_interval_bytes) { |
| 274 // Try to maintain regular intervals of size |analysis_interval_bytes_|. | 271 // Try to maintain regular intervals of size |analysis_interval_bytes_|. |
| 275 detector->last_analysis_alloc_size_ = | 272 detector->last_analysis_alloc_size_ = |
| 276 total_alloc_size - total_alloc_size % analysis_interval_bytes; | 273 total_alloc_size - total_alloc_size % analysis_interval_bytes; |
| 277 | 274 |
| 278 // Collect new leak reports. Use current |total_alloc_size| as | |
| 279 // a timestamp, then transform change in timestamp into the | |
| 280 // number of intervals passed. | |
| 281 InternalVector<InternalLeakReport> leak_reports; | 275 InternalVector<InternalLeakReport> leak_reports; |
| 282 detector->impl_->TestForLeaks(&leak_reports, total_alloc_size); | 276 detector->impl_->TestForLeaks(&leak_reports); |
| 283 for (auto &report : leak_reports) | |
| 284 report.set_num_rising_intervals( | |
| 285 report.num_rising_intervals() / analysis_interval_bytes); | |
| 286 | 277 |
| 287 // Pass leak reports to observers. | 278 // Pass leak reports to observers. |
| 288 std::vector<MemoryLeakReportProto> leak_report_protos; | 279 std::vector<MemoryLeakReportProto> leak_report_protos; |
| 289 leak_report_protos.reserve(leak_reports.size()); | 280 leak_report_protos.reserve(leak_reports.size()); |
| 290 std::transform(leak_reports.begin(), leak_reports.end(), | 281 std::transform(leak_reports.begin(), leak_reports.end(), |
| 291 std::back_inserter(leak_report_protos), | 282 std::back_inserter(leak_report_protos), |
| 292 &ConvertLeakReportToProto); | 283 &ConvertLeakReportToProto); |
| 293 detector->NotifyObservers(leak_report_protos); | 284 detector->NotifyObservers(leak_report_protos); |
| 294 } | 285 } |
| 295 } | 286 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 return; | 336 return; |
| 346 } | 337 } |
| 347 | 338 |
| 348 { | 339 { |
| 349 base::AutoLock lock(observers_lock_); | 340 base::AutoLock lock(observers_lock_); |
| 350 FOR_EACH_OBSERVER(Observer, observers_, OnLeaksFound(reports)); | 341 FOR_EACH_OBSERVER(Observer, observers_, OnLeaksFound(reports)); |
| 351 } | 342 } |
| 352 } | 343 } |
| 353 | 344 |
| 354 } // namespace metrics | 345 } // namespace metrics |
| OLD | NEW |