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

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

Issue 986503002: components/metrics: Add runtime memory leak detector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Create CallStackManager out of LeakDetectorImpl Created 5 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_METRICS_LEAK_DETECTOR_CALL_STACK_MANAGER_H_
6 #define COMPONENTS_METRICS_LEAK_DETECTOR_CALL_STACK_MANAGER_H_
7
8 #include <gperftools/custom_allocator.h>
9 #include <stdint.h>
10
11 #include <unordered_set>
12
13 #include "base/macros.h"
14 #include "components/metrics/leak_detector/stl_allocator.h"
15
16 namespace leak_detector {
17
18 // Struct to represent a call stack.
19 struct CallStack {
20 uint32_t depth; // Depth of current call stack.
21 const void** stack; // Call stack as an array of addrs.
22
23 size_t hash; // Hash of call stack.
24 };
25
26 // Maintains and owns all unique call stack objects.
27 class CallStackManager {
28 public:
29 CallStackManager();
30 ~CallStackManager();
31
32 // Returns a CallStack object for a given call stack. Each unique call stack
33 // has its own CallStack object. If the given call stack has already been
34 // created by a previous call to this function, return a pointer to that same
35 // call stack object.
36 //
37 // Returns the call stacks as const pointers because no caller should take
38 // ownership of them and modify or delete them.
39 const CallStack* GetCallStack(int depth, const void* const stack[]);
40
41 size_t size() const {
42 return call_stacks_.size();
43 }
44
45 private:
46 // Allocator class for unique call stacks.
47 using CallStackPointerAllocator = STL_Allocator<CallStack*, CustomAllocator>;
48
49 // Used to compute hashes from call stack objects. Takes a pointer to a call
50 // stack object as an argument.
51 struct CallStackPointerHash {
52 size_t operator() (const CallStack* call_stack) const;
53 };
54
55 // Equality comparator for call stack objects. Takes pointers to call stack
56 // objects as arguments.
57 struct CallStackPointerEqual {
58 bool operator() (const CallStack* c1, const CallStack* c2) const;
59 };
60
61 // Holds all call stack objects.
62 std::unordered_set<CallStack*,
63 CallStackPointerHash,
64 CallStackPointerEqual,
65 CallStackPointerAllocator> call_stacks_;
66
67 DISALLOW_COPY_AND_ASSIGN(CallStackManager);
68 };
69
70 } // namespace leak_detector
71
72 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_CALL_STACK_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698