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

Unified Diff: chrome/profiling/stack.h

Issue 2943733002: Add out-of-process memory logging stream parsing. (Closed)
Patch Set: Remove version 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 side-by-side diff with in-line comments
Download patch
Index: chrome/profiling/stack.h
diff --git a/chrome/profiling/stack.h b/chrome/profiling/stack.h
new file mode 100644
index 0000000000000000000000000000000000000000..98ed7691b1697806ee56b8e4d082d4943fde16f2
--- /dev/null
+++ b/chrome/profiling/stack.h
@@ -0,0 +1,65 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_PROFILING_STACK_H_
+#define CHROME_PROFILING_STACK_H_
+
+#include <functional>
+#include <vector>
+
+#include "base/macros.h"
+#include "chrome/profiling/address.h"
+
+namespace profiling {
+
+// Holds a move-only stack backtrace and a precomputed hash.
+//
+// This is immutable since we assume it can be read from multiple threads
+// without locking.
+//
+// This class has a ref_count member which is used by the allocation tracker
+// to track references to the stack. The reference counting is managed
+// externally. Tracking live objects with a global atom list in a threadsafe
+// manner is much more difficult if this class derives from RefCount.
+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.
+ public:
+ 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
+ ~Stack();
+
+ bool operator==(const Stack& other) const;
+ bool operator!=(const Stack& other) const;
+
+ const std::vector<Address>& addrs() const;
+
+ 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.
+
+ private:
+ friend class StackStorage; // Only StackStorage can do ref counting.
+
+ // The reference counting is not threadsafe. it's assumed the StackStorage is
+ // the only class accessing this, and it's done inside a lock.
+ void AddRef() const { ref_count_++; }
+ bool Release() const { // Returns whether the result is non-zero.
+ return !!(--ref_count_);
+ }
+
+ std::vector<Address> addrs_;
+ size_t hash_;
+ mutable int ref_count_ = 0;
+};
+
+} // namespace profiling
+
+namespace std {
+
+template <>
+struct hash<profiling::Stack> {
+ using argument_type = profiling::Stack;
+ using result_type = size_t;
+ result_type operator()(const argument_type& s) const { return s.hash(); }
+};
+
+} // namespace std
+
+#endif // CHROME_PROFILING_STACK_H_

Powered by Google App Engine
This is Rietveld 408576698