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

Side by Side Diff: chrome/profiling/backtrace.h

Issue 2943733002: Add out-of-process memory logging stream parsing. (Closed)
Patch Set: Add TODO Created 3 years, 6 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
« no previous file with comments | « chrome/profiling/allocation_tracker.cc ('k') | chrome/profiling/backtrace.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 CHROME_PROFILING_BACKTRACE_H_
6 #define CHROME_PROFILING_BACKTRACE_H_
7
8 #include <functional>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "chrome/profiling/address.h"
13
14 namespace profiling {
15
16 // Holds a move-only stack backtrace and a precomputed hash. This backtrace
17 // uses addresses in the instrumented process. This is in contrast to
18 // base::StackTrace which is for getting and working with stack traces in the
19 // current process.
20 //
21 // This is immutable since we assume it can be read from multiple threads
22 // without locking.
23 //
24 // This class has a ref_count member which is used by the allocation tracker
25 // to track references to the stack. The reference counting is managed
26 // externally. Tracking live objects with a global atom list in a threadsafe
27 // manner is much more difficult if this class derives from RefCount.
28 class Backtrace {
29 public:
30 // Move-only class. Backtraces should be managed by BacktraceStorage and
31 // we shouldn't be copying vectors around.
32 explicit Backtrace(std::vector<Address>&& a);
33 Backtrace(Backtrace&& other) noexcept;
34 ~Backtrace();
35
36 Backtrace& operator=(Backtrace&& other);
37
38 bool operator==(const Backtrace& other) const;
39 bool operator!=(const Backtrace& other) const;
40
41 const std::vector<Address>& addrs() const;
42
43 size_t fingerprint() const { return fingerprint_; }
44
45 private:
46 friend class BacktraceStorage; // Only BacktraceStorage can do ref counting.
47
48 // The reference counting is not threadsafe. it's assumed the
49 // BacktraceStorage is the only class accessing this, and it's done inside a
50 // lock.
51 void AddRef() const { ref_count_++; }
52 bool Release() const { // Returns whether the result is non-zero.
53 return !!(--ref_count_);
54 }
55
56 std::vector<Address> addrs_;
57 size_t fingerprint_;
58 mutable int ref_count_ = 0;
59
60 DISALLOW_COPY_AND_ASSIGN(Backtrace);
61 };
62
63 } // namespace profiling
64
65 namespace std {
66
67 template <>
68 struct hash<profiling::Backtrace> {
69 using argument_type = profiling::Backtrace;
70 using result_type = size_t;
71 result_type operator()(const argument_type& s) const {
72 return s.fingerprint();
73 }
74 };
75
76 } // namespace std
77
78 #endif // CHROME_PROFILING_BACKTRACE_H_
OLDNEW
« no previous file with comments | « chrome/profiling/allocation_tracker.cc ('k') | chrome/profiling/backtrace.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698