| 1 | // -*- C++ -*-cxx . . $ `<file>/vendor/Heap-Layers/heaps/debug/statsheap.h`/ |
| 2 | |
| 3 | #ifndef HL_STATS_H |
| 4 | #define HL_STATS_Hcxx . . $ `vendor/Heap-Layers/heaps/debug/statsheap.h:4:9`! |
| 5 | |
| 6 | #include <map> |
| 7 | #include <cassert> |
| 8 | |
| 9 | namespace HLcxx . . $ HL/ { |
| 10 | |
| 11 | template <class SuperHeap> |
| 12 | class InUseHeapcxx . . $ HL/InUseHeap# : public SuperHeap { |
| 13 | private: |
| 14 | typedef stdcxx . . $ std/::mapcxx . . $ std/map#<void *, int> mapTypecxx . . $ HL/InUseHeap#mapType#; |
| 15 | public: |
| 16 | InUseHeapcxx . . $ HL/InUseHeap#`InUseHeap<SuperHeap>`(49f6e7a06ebc5aa8).() |
| 17 | : inUsecxx . . $ HL/InUseHeap#inUse. (0), |
| 18 | maxInUsecxx . . $ HL/InUseHeap#maxInUse. (0) |
| 19 | {} |
| 20 | void * malloccxx . . $ HL/InUseHeap#malloc(bfcfa4d6b7f7ef64). (size_t sz) { |
| 21 | void * ptr = SuperHeap::malloc (sz); |
| 22 | if (ptr != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 23 | inUsecxx . . $ HL/InUseHeap#inUse. += sz; |
| 24 | if (maxInUsecxx . . $ HL/InUseHeap#maxInUse. < inUsecxx . . $ HL/InUseHeap#inUse.) { |
| 25 | maxInUsecxx . . $ HL/InUseHeap#maxInUse. = inUsecxx . . $ HL/InUseHeap#inUse.; |
| 26 | } |
| 27 | allocatedObjectscxx . . $ HL/InUseHeap#allocatedObjects..insertcxx . . $ std/map#insert(92111883a3599ede). (stdcxx . . $ std/pair#pair(14d64bafa7379ebc).::paircxx . . $ std/pair#<void *, int>(ptr, sz)); |
| 28 | } |
| 29 | return ptr; |
| 30 | } |
| 31 | |
| 32 | void freecxx . . $ HL/InUseHeap#free(5d22bdacc48458e8). (void * ptr) { |
| 33 | mapTypecxx . . $ HL/InUseHeap#mapType#::iteratorcxx . . $ std/map#iterator# icxx . . $ std/_Rb_tree_iterator#_Rb_tree_iterator(49f6e7a06ebc5aa8).; |
| 34 | i =cxx . . $ std/_Rb_tree_iterator#`operator=`(3e2de9beff978712). allocatedObjectscxx . . $ HL/InUseHeap#allocatedObjects..findcxx . . $ std/map#find(36f8d56706583706). (ptr); |
| 35 | if (i ==cxx . . $ std/`operator==`(84f83906d8995b82). allocatedObjectscxx . . $ HL/InUseHeap#allocatedObjects..endcxx . . $ std/map#end(fbe2f8c57595edf).()) { |
| 36 | // oops -- called free on object i didn't allocate. |
| 37 | assertcxx . . $ `/usr/include/assert.h:50:10`! (0); |
| 38 | } |
| 39 | inUsecxx . . $ HL/InUseHeap#inUse. -= (*cxx . . $ std/_Rb_tree_iterator#`operator*`(c93303b41ac66b6d).i).secondcxx . . $ std/pair#second.; |
| 40 | allocatedObjectscxx . . $ HL/InUseHeap#allocatedObjects..erasecxx . . $ std/map#erase(9238c2f1608b9ba6). (i); |
| 41 | SuperHeap::free (ptr); |
| 42 | } |
| 43 | |
| 44 | int getInUsecxx . . $ HL/InUseHeap#getInUse(455f465bc33b4cdf). () const { |
| 45 | return inUsecxx . . $ HL/InUseHeap#inUse.; |
| 46 | } |
| 47 | |
| 48 | int getMaxInUsecxx . . $ HL/InUseHeap#getMaxInUse(455f465bc33b4cdf). () const { |
| 49 | return maxInUsecxx . . $ HL/InUseHeap#maxInUse.; |
| 50 | } |
| 51 | |
| 52 | private: |
| 53 | int inUsecxx . . $ HL/InUseHeap#inUse.; |
| 54 | int maxInUsecxx . . $ HL/InUseHeap#maxInUse.; |
| 55 | mapTypecxx . . $ HL/InUseHeap#mapType# allocatedObjectscxx . . $ HL/InUseHeap#allocatedObjects.; |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | template <class SuperHeap> |
| 60 | class AllocatedHeapcxx . . $ HL/AllocatedHeap# : public SuperHeap { |
| 61 | public: |
| 62 | AllocatedHeapcxx . . $ HL/AllocatedHeap#`AllocatedHeap<SuperHeap>`(49f6e7a06ebc5aa8). () |
| 63 | : allocatedcxx . . $ HL/AllocatedHeap#allocated. (0), |
| 64 | maxAllocatedcxx . . $ HL/AllocatedHeap#maxAllocated. (0) |
| 65 | {} |
| 66 | void * malloccxx . . $ HL/AllocatedHeap#malloc(bfcfa4d6b7f7ef64). (size_t sz) { |
| 67 | void * ptr = SuperHeap::malloc (sz); |
| 68 | if (ptr != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 69 | allocatedcxx . . $ HL/AllocatedHeap#allocated. += SuperHeap::getSize(ptr); |
| 70 | if (maxAllocatedcxx . . $ HL/AllocatedHeap#maxAllocated. < allocatedcxx . . $ HL/AllocatedHeap#allocated.) { |
| 71 | maxAllocatedcxx . . $ HL/AllocatedHeap#maxAllocated. = allocatedcxx . . $ HL/AllocatedHeap#allocated.; |
| 72 | } |
| 73 | } |
| 74 | return ptr; |
| 75 | } |
| 76 | |
| 77 | void freecxx . . $ HL/AllocatedHeap#free(5d22bdacc48458e8). (void * ptr) { |
| 78 | allocatedcxx . . $ HL/AllocatedHeap#allocated. -= SuperHeap::getSize(ptr); |
| 79 | SuperHeap::free (ptr); |
| 80 | } |
| 81 | |
| 82 | int getAllocatedcxx . . $ HL/AllocatedHeap#getAllocated(455f465bc33b4cdf). () const { |
| 83 | return allocatedcxx . . $ HL/AllocatedHeap#allocated.; |
| 84 | } |
| 85 | int getMaxAllocatedcxx . . $ HL/AllocatedHeap#getMaxAllocated(455f465bc33b4cdf). () const { |
| 86 | return maxAllocatedcxx . . $ HL/AllocatedHeap#maxAllocated.; |
| 87 | } |
| 88 | |
| 89 | private: |
| 90 | int allocatedcxx . . $ HL/AllocatedHeap#allocated.; |
| 91 | int maxAllocatedcxx . . $ HL/AllocatedHeap#maxAllocated.; |
| 92 | }; |
| 93 | |
| 94 | |
| 95 | template <class SuperHeap> |
| 96 | class StatsHeapcxx . . $ HL/StatsHeap# : public SuperHeap { |
| 97 | public: |
| 98 | ~cxx . . $ HL/StatsHeap#`~StatsHeap<SuperHeap>`(49f6e7a06ebc5aa8).StatsHeap () { |
| 99 | printf ("In use = %d, allocated = %d\n", SuperHeap::getInUse(), SuperHeap::getAllocated()); |
| 100 | printf ("Max in use = %d, max allocated = %d\n", SuperHeap::getMaxInUse(), SuperHeap::getMaxAllocated()); |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | } |
| 105 | |
| 106 | #endif |