LCOV - code coverage report
Current view: top level - src/compiler - zone-stats.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 52 52 100.0 %
Date: 2017-04-26 Functions: 13 13 100.0 %

          Line data    Source code
       1             : // Copyright 2014 the V8 project 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 "src/compiler/zone-stats.h"
       6             : 
       7             : namespace v8 {
       8             : namespace internal {
       9             : namespace compiler {
      10             : 
      11          23 : ZoneStats::StatsScope::StatsScope(ZoneStats* zone_stats)
      12             :     : zone_stats_(zone_stats),
      13             :       total_allocated_bytes_at_start_(zone_stats->GetTotalAllocatedBytes()),
      14          46 :       max_allocated_bytes_(0) {
      15          23 :   zone_stats_->stats_.push_back(this);
      16          99 :   for (Zone* zone : zone_stats_->zones_) {
      17          30 :     size_t size = static_cast<size_t>(zone->allocation_size());
      18             :     std::pair<InitialValues::iterator, bool> res =
      19          60 :         initial_values_.insert(std::make_pair(zone, size));
      20             :     USE(res);
      21             :     DCHECK(res.second);
      22             :   }
      23          23 : }
      24             : 
      25          23 : ZoneStats::StatsScope::~StatsScope() {
      26             :   DCHECK_EQ(zone_stats_->stats_.back(), this);
      27          23 :   zone_stats_->stats_.pop_back();
      28          23 : }
      29             : 
      30         846 : size_t ZoneStats::StatsScope::GetMaxAllocatedBytes() {
      31        1692 :   return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes());
      32             : }
      33             : 
      34        1753 : size_t ZoneStats::StatsScope::GetCurrentAllocatedBytes() {
      35             :   size_t total = 0;
      36        8770 :   for (Zone* zone : zone_stats_->zones_) {
      37        3511 :     total += static_cast<size_t>(zone->allocation_size());
      38             :     // Adjust for initial values.
      39             :     InitialValues::iterator it = initial_values_.find(zone);
      40        3511 :     if (it != initial_values_.end()) {
      41         935 :       total -= it->second;
      42             :     }
      43             :   }
      44        1753 :   return total;
      45             : }
      46             : 
      47         846 : size_t ZoneStats::StatsScope::GetTotalAllocatedBytes() {
      48        1692 :   return zone_stats_->GetTotalAllocatedBytes() -
      49         846 :          total_allocated_bytes_at_start_;
      50             : }
      51             : 
      52          61 : void ZoneStats::StatsScope::ZoneReturned(Zone* zone) {
      53          61 :   size_t current_total = GetCurrentAllocatedBytes();
      54             :   // Update max.
      55         122 :   max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
      56             :   // Drop zone from initial value map.
      57             :   InitialValues::iterator it = initial_values_.find(zone);
      58          61 :   if (it != initial_values_.end()) {
      59             :     initial_values_.erase(it);
      60             :   }
      61          61 : }
      62             : 
      63      943837 : ZoneStats::ZoneStats(AccountingAllocator* allocator)
      64      943837 :     : max_allocated_bytes_(0), total_deleted_bytes_(0), allocator_(allocator) {}
      65             : 
      66      943846 : ZoneStats::~ZoneStats() {
      67             :   DCHECK(zones_.empty());
      68             :   DCHECK(stats_.empty());
      69      943848 : }
      70             : 
      71         429 : size_t ZoneStats::GetMaxAllocatedBytes() {
      72         858 :   return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes());
      73             : }
      74             : 
      75         429 : size_t ZoneStats::GetCurrentAllocatedBytes() {
      76             :   size_t total = 0;
      77   198866938 :   for (Zone* zone : zones_) {
      78    85674140 :     total += static_cast<size_t>(zone->allocation_size());
      79             :   }
      80         429 :   return total;
      81             : }
      82             : 
      83         429 : size_t ZoneStats::GetTotalAllocatedBytes() {
      84        2596 :   return total_deleted_bytes_ + GetCurrentAllocatedBytes();
      85             : }
      86             : 
      87    27517192 : Zone* ZoneStats::NewEmptyZone(const char* zone_name) {
      88    27517192 :   Zone* zone = new Zone(allocator_, zone_name);
      89    27518159 :   zones_.push_back(zone);
      90    27517227 :   return zone;
      91             : }
      92             : 
      93    27516923 : void ZoneStats::ReturnZone(Zone* zone) {
      94    27516923 :   size_t current_total = GetCurrentAllocatedBytes();
      95             :   // Update max.
      96    55033846 :   max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
      97             :   // Update stats.
      98    55033907 :   for (StatsScope* stat_scope : stats_) {
      99    27516856 :     stat_scope->ZoneReturned(zone);
     100             :   }
     101             :   // Remove from used.
     102    27516820 :   Zones::iterator it = std::find(zones_.begin(), zones_.end(), zone);
     103             :   DCHECK(it != zones_.end());
     104    27516820 :   zones_.erase(it);
     105    55033590 :   total_deleted_bytes_ += static_cast<size_t>(zone->allocation_size());
     106    27516795 :   delete zone;
     107    27519205 : }
     108             : 
     109             : }  // namespace compiler
     110             : }  // namespace internal
     111             : }  // namespace v8

Generated by: LCOV version 1.10