| 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/backtrace_storage.h" | 
|  | 9 #include "chrome/profiling/profiling_globals.h" | 
|  | 10 | 
|  | 11 namespace profiling { | 
|  | 12 | 
|  | 13 AllocationTracker::Alloc::Alloc(size_t sz, BacktraceStorage::Key key) | 
|  | 14     : size(sz), backtrace_key(key) {} | 
|  | 15 | 
|  | 16 AllocationTracker::AllocationTracker(CompleteCallback complete_cb) | 
|  | 17     : complete_callback_(std::move(complete_cb)), | 
|  | 18       backtrace_storage_(ProfilingGlobals::Get()->GetBacktraceStorage()) {} | 
|  | 19 | 
|  | 20 AllocationTracker::~AllocationTracker() { | 
|  | 21   std::vector<BacktraceStorage::Key> to_free; | 
|  | 22   to_free.reserve(live_allocs_.size()); | 
|  | 23   for (const auto& cur : live_allocs_) | 
|  | 24     to_free.push_back(cur.second.backtrace_key); | 
|  | 25   backtrace_storage_->Free(to_free); | 
|  | 26 } | 
|  | 27 | 
|  | 28 void AllocationTracker::OnHeader(const StreamHeader& header) {} | 
|  | 29 | 
|  | 30 void AllocationTracker::OnAlloc(const AllocPacket& alloc_packet, | 
|  | 31                                 std::vector<Address>&& bt) { | 
|  | 32   BacktraceStorage::Key backtrace_key = | 
|  | 33       backtrace_storage_->Insert(std::move(bt)); | 
|  | 34   live_allocs_.emplace(Address(alloc_packet.address), | 
|  | 35                        Alloc(alloc_packet.size, backtrace_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     backtrace_storage_->Free(found->second.backtrace_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 | 
|---|