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

Unified Diff: chrome/profiling/stack_storage.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_storage.h
diff --git a/chrome/profiling/stack_storage.h b/chrome/profiling/stack_storage.h
new file mode 100644
index 0000000000000000000000000000000000000000..6f00a652f6eafdf00ab632e2d490243dbdaf4821
--- /dev/null
+++ b/chrome/profiling/stack_storage.h
@@ -0,0 +1,51 @@
+// 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_STORAGE_H_
+#define CHROME_PROFILING_STACK_STORAGE_H_
+
+#include <unordered_set>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/synchronization/lock.h"
+#include "chrome/profiling/stack.h"
+
+namespace profiling {
+
+// This class is threadsafe.
+class StackStorage {
+ public:
+ using Container = std::unordered_set<Stack>;
+ using Key = Container::iterator;
+
+ StackStorage();
+ ~StackStorage();
+
+ // Adds the give stack to the storage and returns a key to it. If a matching
Boris Vidolov 2017/06/17 03:13:15 nit: "given"
+ // stack already exists, a key to the existing one will be returned.
+ //
+ // The returned key will have a reference count associated with it, call
+ // Free when the key is no longer needed.
+ Key Insert(Stack&& stack);
+
+ // Frees one reference to a stack.
+ void Free(const Key& key);
+ void Free(const std::vector<Key>& keys);
+
+ // Returns the stack associated with the given key. Assumes the caller holds
+ // a key to it that will keep the stack in scope.
+ const Stack& GetStackForKey(const Key& key) const;
+
+ private:
+ mutable base::Lock lock_;
+
+ // List of live stacks for de-duping. Protected by the lock_.
+ Container stacks_;
+};
+
+} // namespace profiling
+
+#endif // CHROME_PROFILING_STACK_STORAGE_H_

Powered by Google App Engine
This is Rietveld 408576698