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

Unified Diff: chrome/profiling/allocation_tracker.cc

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/profiling/allocation_tracker.h ('k') | chrome/profiling/backtrace.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..89c3b4b0b18797e2efb73e210e6aa73c3348bc9d
--- /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/backtrace_storage.h"
+#include "chrome/profiling/profiling_globals.h"
+
+namespace profiling {
+
+AllocationTracker::Alloc::Alloc(size_t sz, BacktraceStorage::Key key)
+ : size(sz), backtrace_key(key) {}
+
+AllocationTracker::AllocationTracker(CompleteCallback complete_cb)
+ : complete_callback_(std::move(complete_cb)),
+ backtrace_storage_(ProfilingGlobals::Get()->GetBacktraceStorage()) {}
+
+AllocationTracker::~AllocationTracker() {
+ std::vector<BacktraceStorage::Key> to_free;
+ to_free.reserve(live_allocs_.size());
+ for (const auto& cur : live_allocs_)
+ to_free.push_back(cur.second.backtrace_key);
+ backtrace_storage_->Free(to_free);
+}
+
+void AllocationTracker::OnHeader(const StreamHeader& header) {}
+
+void AllocationTracker::OnAlloc(const AllocPacket& alloc_packet,
+ std::vector<Address>&& bt) {
+ BacktraceStorage::Key backtrace_key =
+ backtrace_storage_->Insert(std::move(bt));
+ live_allocs_.emplace(Address(alloc_packet.address),
+ Alloc(alloc_packet.size, backtrace_key));
+}
+
+void AllocationTracker::OnFree(const FreePacket& free_packet) {
+ auto found = live_allocs_.find(Address(free_packet.address));
+ if (found != live_allocs_.end()) {
+ backtrace_storage_->Free(found->second.backtrace_key);
+ live_allocs_.erase(found);
+ }
+}
+
+void AllocationTracker::OnComplete() {
+ std::move(complete_callback_).Run();
+ // Danger: object may be deleted now.
+}
+
+} // namespace profiling
« no previous file with comments | « chrome/profiling/allocation_tracker.h ('k') | chrome/profiling/backtrace.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698