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 #ifndef COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_ | 5 #ifndef COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_ |
6 #define COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_ | 6 #define COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 // - AllocHook | 42 // - AllocHook |
43 // - FreeHook | 43 // - FreeHook |
44 // - AddObserver | 44 // - AddObserver |
45 // - RemoveObserver | 45 // - RemoveObserver |
46 // | 46 // |
47 // All other functions must always be called from the same thread. This is | 47 // All other functions must always be called from the same thread. This is |
48 // enforced with a DCHECK. | 48 // enforced with a DCHECK. |
49 class LeakDetector { | 49 class LeakDetector { |
50 public: | 50 public: |
51 // Contains a report of a detected memory leak. | 51 // Contains a report of a detected memory leak. |
52 // TODO(sque): This is becoming a copy of LeakDetectorImpl::LeakReport. Need | |
53 // to merge the two. | |
Simon Que
2016/04/11 20:31:25
I wonder if LeakDetector should just create a prot
Ilya Sherman
2016/04/13 00:07:12
Yeah, that seems pretty reasonable.
Simon Que
2016/04/13 22:41:31
Done.
| |
52 struct LeakReport { | 54 struct LeakReport { |
55 // This is a copy of LeakDetectorImpl::LeakReport::AllocationBreakdown. The | |
56 // only difference is that it uses a plain std::vector instead of an | |
57 // InternalVector (custom std::vector). See the definition of that struct | |
58 // for more information. | |
59 struct AllocationBreakdown { | |
60 AllocationBreakdown(); | |
61 ~AllocationBreakdown(); | |
62 | |
63 std::vector<uint32_t> counts_by_size; | |
64 uint32_t count_for_call_stack; | |
65 }; | |
66 | |
53 LeakReport(); | 67 LeakReport(); |
54 ~LeakReport(); | 68 ~LeakReport(); |
55 | 69 |
56 size_t alloc_size_bytes; | 70 size_t alloc_size_bytes; |
57 | 71 |
58 // Unlike the CallStack struct, which consists of addresses, this call stack | 72 // Unlike the CallStack struct, which consists of addresses, this call stack |
59 // will contain offsets in the executable binary. | 73 // will contain offsets in the executable binary. |
60 std::vector<uintptr_t> call_stack; | 74 std::vector<uintptr_t> call_stack; |
75 | |
76 // Historical records of allocation data. | |
77 std::vector<AllocationBreakdown> alloc_breakdown_history; | |
Ilya Sherman
2016/04/13 00:07:12
Optional nit: Mebbe s/alloc/allocation, given the
Simon Que
2016/04/13 22:41:31
The corresponding field in the protobuf is "alloc_
| |
61 }; | 78 }; |
62 | 79 |
63 // Interface for receiving leak reports. | 80 // Interface for receiving leak reports. |
64 class Observer { | 81 class Observer { |
65 public: | 82 public: |
66 virtual ~Observer() {} | 83 virtual ~Observer() {} |
67 | 84 |
68 // Called by leak detector to report a leak. | 85 // Called by leak detector to report a leak. |
69 virtual void OnLeakFound(const LeakReport& report) = 0; | 86 virtual void OnLeakFound(const LeakReport& report) = 0; |
70 }; | 87 }; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 // corresponds to the allowable range of |sampling_rate| passed in during | 181 // corresponds to the allowable range of |sampling_rate| passed in during |
165 // initialization: [0.0f, 1.0f] -> [0, UINT64_MAX]. | 182 // initialization: [0.0f, 1.0f] -> [0, UINT64_MAX]. |
166 uint64_t sampling_factor_; | 183 uint64_t sampling_factor_; |
167 | 184 |
168 DISALLOW_COPY_AND_ASSIGN(LeakDetector); | 185 DISALLOW_COPY_AND_ASSIGN(LeakDetector); |
169 }; | 186 }; |
170 | 187 |
171 } // namespace metrics | 188 } // namespace metrics |
172 | 189 |
173 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_ | 190 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_ |
OLD | NEW |