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

Unified Diff: chrome/profiling/allocation_tracker.cc

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/allocation_tracker.cc
diff --git a/chrome/profiling/allocation_tracker.cc b/chrome/profiling/allocation_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..958a01b9768cc08aa292a7d566bf338322ba716a
--- /dev/null
+++ b/chrome/profiling/allocation_tracker.cc
@@ -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.
+
+#include "chrome/profiling/allocation_tracker.h"
+
+#include "base/callback.h"
+#include "chrome/profiling/profiling_globals.h"
+#include "chrome/profiling/stack_storage.h"
+
+namespace profiling {
+
+AllocationTracker::Alloc::Alloc(size_t sz, StackStorage::Key key)
+ : size(sz), stack_key(key) {}
+
+AllocationTracker::AllocationTracker(CompleteCallback complete_cb)
+ : complete_callback_(std::move(complete_cb)),
+ stack_storage_(ProfilingGlobals::Get()->GetStackStorage()) {}
+
+AllocationTracker::~AllocationTracker() {
+ std::vector<StackStorage::Key> to_free;
+ to_free.reserve(live_allocs_.size());
+ for (const auto& cur : live_allocs_)
+ to_free.push_back(cur.second.stack_key);
+ stack_storage_->Free(to_free);
+}
+
+void AllocationTracker::OnHeader(const StreamHeader& header) {}
+
+void AllocationTracker::OnAlloc(const AllocPacket& alloc_packet,
+ Stack&& stack) {
awong 2017/06/19 20:00:13 r-value reference? Why not by copy?
brettw 2017/06/19 23:29:45 I assume you mean by value. I didn't want to have
+ StackStorage::Key stack_key = stack_storage_->Insert(std::move(stack));
+
+ live_allocs_.emplace(Address(alloc_packet.address),
+ Alloc(alloc_packet.size, stack_key));
+}
+
+void AllocationTracker::OnFree(const FreePacket& free_packet) {
+ auto found = live_allocs_.find(Address(free_packet.address));
+ if (found != live_allocs_.end()) {
+ stack_storage_->Free(found->second.stack_key);
+ live_allocs_.erase(found);
+ }
+}
+
+void AllocationTracker::OnComplete() {
+ std::move(complete_callback_).Run();
+ // Danger: object may be deleted now.
+}
+
+} // namespace profiling

Powered by Google App Engine
This is Rietveld 408576698