| 67 | string Name() override { return "ev_allocator"; } |
| 68 | |
| 69 | void* AllocateRaw(size_t alignment, size_t num_bytes) override { |
| 70 | num_bytes = AlignedSize(num_bytes); |
| 71 | |
| 72 | if (num_bytes > kChunkSize) { |
| 73 | LOG(FATAL) << "Allocation of " << num_bytes << " exceeds " |
| 74 | << kChunkSize << " in EVAllocator."; |
| 75 | } |
| 76 | |
| 77 | if (num_bytes > LargeAllocationWarningBytes() && |
| 78 | single_allocation_warning_count_ < kMaxSingleAllocationWarnings) { |
| 79 | ++single_allocation_warning_count_; |
| 80 | LOG(WARNING) << "Allocation of " << num_bytes << " exceeds " |
| 81 | << 100 * kLargeAllocationWarningThreshold |
| 82 | << "% of system memory."; |
| 83 | } |
| 84 | |
| 85 | void* p = impl_.Allocate(num_bytes); |
| 86 | if (ev_allocator_collect_stats) { |
| 87 | const std::size_t alloc_size = impl_.AllocatedSize(p); |
| 88 | mutex_lock l(mu_); |
| 89 | ++stats_.num_allocs; |
| 90 | stats_.bytes_in_use += alloc_size; |
| 91 | stats_.peak_bytes_in_use = |
| 92 | std::max<int64>(stats_.peak_bytes_in_use, stats_.bytes_in_use); |
| 93 | stats_.largest_alloc_size = |
| 94 | std::max<int64>(stats_.largest_alloc_size, alloc_size); |
| 95 | |
| 96 | if (stats_.bytes_in_use > TotalAllocationWarningBytes() && |
| 97 | total_allocation_warning_count_ < kMaxTotalAllocationWarnings) { |
| 98 | ++total_allocation_warning_count_; |
| 99 | LOG(WARNING) << "Total allocated memory " << stats_.bytes_in_use |
| 100 | << "exceeds " << 100 * kTotalAllocationWarningThreshold |
| 101 | << "% of system memory"; |
| 102 | } |
| 103 | } |
| 104 | return p; |
| 105 | } |
| 106 | |
| 107 | size_t BatchAllocateRaw(size_t num, size_t alignment, |
| 108 | size_t num_bytes, void** ret) override { |
no test coverage detected