Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| OLD | NEW |