Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_STACK_H_ | |
| 6 #define CHROME_PROFILING_STACK_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. | |
| 17 // | |
| 18 // This is immutable since we assume it can be read from multiple threads | |
| 19 // without locking. | |
| 20 // | |
| 21 // This class has a ref_count member which is used by the allocation tracker | |
| 22 // to track references to the stack. The reference counting is managed | |
| 23 // externally. Tracking live objects with a global atom list in a threadsafe | |
| 24 // manner is much more difficult if this class derives from RefCount. | |
| 25 class Stack { | |
|
awong
2017/06/19 21:51:27
nit: rename Backtrace.
Stack looks like a data st
brettw
2017/06/19 23:29:46
Done.
| |
| 26 public: | |
| 27 explicit Stack(std::vector<Address>&& a); | |
|
awong
2017/06/19 21:51:27
If this is move-only, don't you need a DisallowCop
brettw
2017/06/19 23:29:46
It's not move-only, but I guess I can make it like
| |
| 28 ~Stack(); | |
| 29 | |
| 30 bool operator==(const Stack& other) const; | |
| 31 bool operator!=(const Stack& other) const; | |
| 32 | |
| 33 const std::vector<Address>& addrs() const; | |
| 34 | |
| 35 size_t hash() const { return hash_; } | |
|
awong
2017/06/19 21:51:27
Is this actually a "hash()" as in an unstable valu
brettw
2017/06/19 23:29:46
Changed to fingerprint.
| |
| 36 | |
| 37 private: | |
| 38 friend class StackStorage; // Only StackStorage can do ref counting. | |
| 39 | |
| 40 // The reference counting is not threadsafe. it's assumed the StackStorage is | |
| 41 // the only class accessing this, and it's done inside a lock. | |
| 42 void AddRef() const { ref_count_++; } | |
| 43 bool Release() const { // Returns whether the result is non-zero. | |
| 44 return !!(--ref_count_); | |
| 45 } | |
| 46 | |
| 47 std::vector<Address> addrs_; | |
| 48 size_t hash_; | |
| 49 mutable int ref_count_ = 0; | |
| 50 }; | |
| 51 | |
| 52 } // namespace profiling | |
| 53 | |
| 54 namespace std { | |
| 55 | |
| 56 template <> | |
| 57 struct hash<profiling::Stack> { | |
| 58 using argument_type = profiling::Stack; | |
| 59 using result_type = size_t; | |
| 60 result_type operator()(const argument_type& s) const { return s.hash(); } | |
| 61 }; | |
| 62 | |
| 63 } // namespace std | |
| 64 | |
| 65 #endif // CHROME_PROFILING_STACK_H_ | |
| OLD | NEW |