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 |
11 #include "base/allocator/allocator_extension.h" | 11 #include "base/allocator/allocator_extension.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/numerics/safe_conversions.h" | 16 #include "base/numerics/safe_conversions.h" |
17 #include "base/threading/thread_local.h" | 17 #include "base/threading/thread_local.h" |
18 #include "components/metrics/leak_detector/custom_allocator.h" | 18 #include "components/metrics/leak_detector/custom_allocator.h" |
19 #include "components/metrics/leak_detector/leak_detector_impl.h" | 19 #include "components/metrics/leak_detector/leak_detector_impl.h" |
20 #include "components/metrics/proto/memory_leak_report.pb.h" | |
20 | 21 |
21 #if defined(OS_CHROMEOS) | 22 #if defined(OS_CHROMEOS) |
22 #include <link.h> // for dl_iterate_phdr | 23 #include <link.h> // for dl_iterate_phdr |
23 #else | 24 #else |
24 #error "Getting binary mapping info is not supported on this platform." | 25 #error "Getting binary mapping info is not supported on this platform." |
25 #endif // defined(OS_CHROMEOS) | 26 #endif // defined(OS_CHROMEOS) |
26 | 27 |
27 namespace metrics { | 28 namespace metrics { |
28 | 29 |
29 using InternalLeakReport = leak_detector::LeakDetectorImpl::LeakReport; | 30 using InternalLeakReport = leak_detector::LeakDetectorImpl::LeakReport; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 (hook_data.entered_hook ? 1 : 0) | (hook_data.alloc_size << 1); | 153 (hook_data.entered_hook ? 1 : 0) | (hook_data.alloc_size << 1); |
153 g_hook_data_tls.Get().Set(reinterpret_cast<void*>(ptr_value)); | 154 g_hook_data_tls.Get().Set(reinterpret_cast<void*>(ptr_value)); |
154 } | 155 } |
155 | 156 |
156 } // namespace | 157 } // namespace |
157 | 158 |
158 // static | 159 // static |
159 LeakDetector* LeakDetector::GetInstance() { | 160 LeakDetector* LeakDetector::GetInstance() { |
160 return g_instance.Pointer(); | 161 return g_instance.Pointer(); |
161 } | 162 } |
163 // static | |
jochen (gone - plz use gerrit)
2016/06/01 15:11:28
nit. empty line above this line
Simon Que
2016/06/02 17:55:17
Done.
| |
164 void LeakDetector::StaticInit() { | |
165 g_hook_data_tls.Get(); | |
Primiano Tucci (use gerrit)
2016/06/01 21:26:30
ignore_result(g_hook_data_tls.Pointer()); just to
Simon Que
2016/06/02 17:55:17
Done.
| |
166 } | |
162 | 167 |
163 void LeakDetector::Init(const MemoryLeakReportProto::Params& params, | 168 void LeakDetector::Init(const MemoryLeakReportProto::Params& params, |
164 scoped_refptr<base::TaskRunner> task_runner) { | 169 scoped_refptr<base::TaskRunner> task_runner) { |
165 DCHECK(thread_checker_.CalledOnValidThread()); | 170 DCHECK(thread_checker_.CalledOnValidThread()); |
166 DCHECK_GT(params.sampling_rate(), 0); | 171 DCHECK_GT(params.sampling_rate(), 0); |
167 | 172 |
168 sampling_factor_ = | 173 sampling_factor_ = |
169 base::saturated_cast<uint64_t>(params.sampling_rate() * UINT64_MAX); | 174 base::saturated_cast<uint64_t>(params.sampling_rate() * UINT64_MAX); |
170 | 175 |
171 analysis_interval_bytes_ = params.analysis_interval_bytes(); | 176 analysis_interval_bytes_ = params.analysis_interval_bytes(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 return; | 335 return; |
331 } | 336 } |
332 | 337 |
333 { | 338 { |
334 base::AutoLock lock(observers_lock_); | 339 base::AutoLock lock(observers_lock_); |
335 FOR_EACH_OBSERVER(Observer, observers_, OnLeaksFound(reports)); | 340 FOR_EACH_OBSERVER(Observer, observers_, OnLeaksFound(reports)); |
336 } | 341 } |
337 } | 342 } |
338 | 343 |
339 } // namespace metrics | 344 } // namespace metrics |
OLD | NEW |