brettw | bd8214bf | 2017-06-20 03:47:03 | [diff] [blame] | 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 | #ifndef CHROME_PROFILING_ALLOCATION_TRACKER_H_ |
| 6 | #define CHROME_PROFILING_ALLOCATION_TRACKER_H_ |
| 7 | |
| 8 | #include <map> |
| 9 | |
| 10 | #include "base/callback.h" |
| 11 | #include "base/macros.h" |
| 12 | #include "chrome/profiling/backtrace_storage.h" |
| 13 | #include "chrome/profiling/memlog_receiver.h" |
| 14 | |
| 15 | namespace profiling { |
| 16 | |
| 17 | // Tracks live allocations in one process. This is an analogue to memory-infra |
| 18 | // allocation register and needs to be merged/deduped. |
| 19 | class AllocationTracker : public MemlogReceiver { |
| 20 | public: |
| 21 | using CompleteCallback = base::OnceClosure; |
| 22 | |
| 23 | explicit AllocationTracker(CompleteCallback complete_cb); |
| 24 | ~AllocationTracker() override; |
| 25 | |
| 26 | void OnHeader(const StreamHeader& header) override; |
| 27 | void OnAlloc(const AllocPacket& alloc_packet, |
| 28 | std::vector<Address>&& bt) override; |
| 29 | void OnFree(const FreePacket& free_packet) override; |
| 30 | void OnComplete() override; |
| 31 | |
| 32 | private: |
| 33 | CompleteCallback complete_callback_; |
| 34 | |
| 35 | struct Alloc { |
| 36 | Alloc(size_t sz, BacktraceStorage::Key key); |
Albert J. Wong | 6fa7481 | 2017-06-27 21:16:12 | [diff] [blame] | 37 | Alloc(const Alloc& other); |
| 38 | ~Alloc(); |
brettw | bd8214bf | 2017-06-20 03:47:03 | [diff] [blame] | 39 | |
| 40 | size_t size; |
| 41 | BacktraceStorage::Key backtrace_key; |
| 42 | }; |
| 43 | |
| 44 | // Cached pointer to the global singleton. |
| 45 | BacktraceStorage* backtrace_storage_; |
| 46 | |
| 47 | std::map<Address, Alloc> live_allocs_; |
| 48 | |
| 49 | DISALLOW_COPY_AND_ASSIGN(AllocationTracker); |
| 50 | }; |
| 51 | |
| 52 | } // namespace profiling |
| 53 | |
| 54 | #endif // CHROME_PROFILING_ALLOCATION_TRACKER_H_ |