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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 #include "chrome/profiling/allocation_tracker.h"
6
7 #include "base/callback.h"
8 #include "chrome/profiling/profiling_globals.h"
9 #include "chrome/profiling/stack_storage.h"
10
11 namespace profiling {
12
13 AllocationTracker::Alloc::Alloc(size_t sz, StackStorage::Key key)
14 : size(sz), stack_key(key) {}
15
16 AllocationTracker::AllocationTracker(CompleteCallback complete_cb)
17 : complete_callback_(std::move(complete_cb)),
18 stack_storage_(ProfilingGlobals::Get()->GetStackStorage()) {}
19
20 AllocationTracker::~AllocationTracker() {
21 std::vector<StackStorage::Key> to_free;
22 to_free.reserve(live_allocs_.size());
23 for (const auto& cur : live_allocs_)
24 to_free.push_back(cur.second.stack_key);
25 stack_storage_->Free(to_free);
26 }
27
28 void AllocationTracker::OnHeader(const StreamHeader& header) {}
29
30 void AllocationTracker::OnAlloc(const AllocPacket& alloc_packet,
31 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
32 StackStorage::Key stack_key = stack_storage_->Insert(std::move(stack));
33
34 live_allocs_.emplace(Address(alloc_packet.address),
35 Alloc(alloc_packet.size, stack_key));
36 }
37
38 void AllocationTracker::OnFree(const FreePacket& free_packet) {
39 auto found = live_allocs_.find(Address(free_packet.address));
40 if (found != live_allocs_.end()) {
41 stack_storage_->Free(found->second.stack_key);
42 live_allocs_.erase(found);
43 }
44 }
45
46 void AllocationTracker::OnComplete() {
47 std::move(complete_callback_).Run();
48 // Danger: object may be deleted now.
49 }
50
51 } // namespace profiling
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698