Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: components/metrics/leak_detector/call_stack_table.h

Issue 2403223002: Leak reports collect information about the last uptrend (Closed)
Patch Set: Added a test case Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef COMPONENTS_METRICS_LEAK_DETECTOR_CALL_STACK_TABLE_H_ 5 #ifndef COMPONENTS_METRICS_LEAK_DETECTOR_CALL_STACK_TABLE_H_
6 #define COMPONENTS_METRICS_LEAK_DETECTOR_CALL_STACK_TABLE_H_ 6 #define COMPONENTS_METRICS_LEAK_DETECTOR_CALL_STACK_TABLE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 30 matching lines...) Expand all
41 void Remove(const CallStack* call_stack); 41 void Remove(const CallStack* call_stack);
42 42
43 // Check for leak patterns in the allocation data. 43 // Check for leak patterns in the allocation data.
44 void TestForLeaks(); 44 void TestForLeaks();
45 45
46 // Get the top N entries in the CallStackTable, ranked by net number of 46 // Get the top N entries in the CallStackTable, ranked by net number of
47 // allocations. N is given by |top_entries->max_size()|, so |*top_entries| 47 // allocations. N is given by |top_entries->max_size()|, so |*top_entries|
48 // must already be initialized with that number. 48 // must already be initialized with that number.
49 void GetTopCallStacks(RankedSet* top_entries) const; 49 void GetTopCallStacks(RankedSet* top_entries) const;
50 50
51 // Updates information about the last seen drop in the number of allocations
52 // and sets the |previous_count| for every stored call stack, both inside
53 // |entry_map_|. It should be called in the analysis phase, before the
54 // reports are generated, with |timestamp| describing current point in the
55 // timeline.
56 void UpdateLastDropInfo(size_t timestamp);
57
58 // Retrieves the change in timestamp and allocation count since the last
59 // observed drop in the number for allocations for the given call stack
60 // (or since the oldest kept record for the call stacks if there were no
61 // drops)
62 void GetLastUptrendInfo(
63 const CallStack* call_stack, size_t timestamp, size_t *timestamp_delta,
64 uint32_t *count_delta) const;
65
51 const LeakAnalyzer& leak_analyzer() const { return leak_analyzer_; } 66 const LeakAnalyzer& leak_analyzer() const { return leak_analyzer_; }
52 67
53 size_t size() const { return entry_map_.size(); } 68 size_t size() const { return entry_map_.size(); }
54 bool empty() const { return entry_map_.empty(); } 69 bool empty() const { return entry_map_.empty(); }
55 70
56 uint32_t num_allocs() const { return num_allocs_; } 71 uint32_t num_allocs() const { return num_allocs_; }
57 uint32_t num_frees() const { return num_frees_; } 72 uint32_t num_frees() const { return num_frees_; }
58 73
59 private: 74 private:
75 struct CallStackCountInfo {
76 uint32_t count, previous_count, last_drop_count;
77 size_t last_drop_timestamp;
78 CallStackCountInfo() : count(0), previous_count(0), last_drop_count(0),
79 last_drop_timestamp(0) {}
80 };
81
60 // Total number of allocs and frees in this table. 82 // Total number of allocs and frees in this table.
61 uint32_t num_allocs_; 83 uint32_t num_allocs_;
62 uint32_t num_frees_; 84 uint32_t num_frees_;
63 85
64 // Hash table containing entries. Uses CustomAllocator to avoid recursive 86 // Hash table containing entries. Uses CustomAllocator to avoid recursive
65 // malloc hook invocation when analyzing allocs and frees. 87 // malloc hook invocation when analyzing allocs and frees.
66 using TableEntryAllocator = 88 using TableEntryAllocator =
67 STLAllocator<std::pair<const CallStack* const, uint32_t>, 89 STLAllocator<std::pair<const CallStack* const, uint32_t>,
68 CustomAllocator>; 90 CustomAllocator>;
69 91
70 // Stores a mapping of each call stack to the number of recorded allocations 92 // Stores a mapping of each call stack to the number of recorded allocations
71 // made from that call site. 93 // made from that call site.
72 base::hash_map<const CallStack*, 94 base::hash_map<const CallStack*,
73 uint32_t, 95 CallStackCountInfo,
74 StoredHash, 96 StoredHash,
75 std::equal_to<const CallStack*>, 97 std::equal_to<const CallStack*>,
76 TableEntryAllocator> entry_map_; 98 TableEntryAllocator> entry_map_;
77 99
78 // For detecting leak patterns in incoming allocations. 100 // For detecting leak patterns in incoming allocations.
79 LeakAnalyzer leak_analyzer_; 101 LeakAnalyzer leak_analyzer_;
80 102
81 DISALLOW_COPY_AND_ASSIGN(CallStackTable); 103 DISALLOW_COPY_AND_ASSIGN(CallStackTable);
82 }; 104 };
83 105
84 } // namespace leak_detector 106 } // namespace leak_detector
85 } // namespace metrics 107 } // namespace metrics
86 108
87 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_CALL_STACK_TABLE_H_ 109 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_CALL_STACK_TABLE_H_
OLDNEW
« no previous file with comments | « no previous file | components/metrics/leak_detector/call_stack_table.cc » ('j') | components/metrics/proto/memory_leak_report.proto » ('J')

Powered by Google App Engine
This is Rietveld 408576698