7 #include "src/compiler/zone-stats.h" 13 ZoneStats::StatsScope::StatsScope(ZoneStats* zone_stats)
14 : zone_stats_(zone_stats),
15 total_allocated_bytes_at_start_(zone_stats->GetTotalAllocatedBytes()),
16 max_allocated_bytes_(0) {
17 zone_stats_->stats_.push_back(
this);
18 for (Zone* zone : zone_stats_->zones_) {
19 size_t size =
static_cast<size_t>(zone->allocation_size());
20 std::pair<InitialValues::iterator, bool> res =
21 initial_values_.insert(std::make_pair(zone, size));
27 ZoneStats::StatsScope::~StatsScope() {
28 DCHECK_EQ(zone_stats_->stats_.back(),
this);
29 zone_stats_->stats_.pop_back();
32 size_t ZoneStats::StatsScope::GetMaxAllocatedBytes() {
33 return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes());
36 size_t ZoneStats::StatsScope::GetCurrentAllocatedBytes() {
38 for (Zone* zone : zone_stats_->zones_) {
39 total +=
static_cast<size_t>(zone->allocation_size());
41 InitialValues::iterator it = initial_values_.find(zone);
42 if (it != initial_values_.end()) {
49 size_t ZoneStats::StatsScope::GetTotalAllocatedBytes() {
50 return zone_stats_->GetTotalAllocatedBytes() -
51 total_allocated_bytes_at_start_;
54 void ZoneStats::StatsScope::ZoneReturned(Zone* zone) {
55 size_t current_total = GetCurrentAllocatedBytes();
57 max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
59 InitialValues::iterator it = initial_values_.find(zone);
60 if (it != initial_values_.end()) {
61 initial_values_.erase(it);
65 ZoneStats::ZoneStats(AccountingAllocator* allocator)
66 : max_allocated_bytes_(0), total_deleted_bytes_(0), allocator_(allocator) {}
68 ZoneStats::~ZoneStats() {
69 DCHECK(zones_.empty());
70 DCHECK(stats_.empty());
73 size_t ZoneStats::GetMaxAllocatedBytes()
const {
74 return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes());
77 size_t ZoneStats::GetCurrentAllocatedBytes()
const {
79 for (Zone* zone : zones_) {
80 total +=
static_cast<size_t>(zone->allocation_size());
85 size_t ZoneStats::GetTotalAllocatedBytes()
const {
86 return total_deleted_bytes_ + GetCurrentAllocatedBytes();
89 Zone* ZoneStats::NewEmptyZone(
const char* zone_name) {
90 Zone* zone =
new Zone(allocator_, zone_name);
91 zones_.push_back(zone);
95 void ZoneStats::ReturnZone(Zone* zone) {
96 size_t current_total = GetCurrentAllocatedBytes();
98 max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
100 for (StatsScope* stat_scope : stats_) {
101 stat_scope->ZoneReturned(zone);
104 Zones::iterator it = std::find(zones_.begin(), zones_.end(), zone);
105 DCHECK(it != zones_.end());
107 total_deleted_bytes_ +=
static_cast<size_t>(zone->allocation_size());