LCOV - code coverage report
Current view: top level - src/compiler - zone-stats.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 53 53 100.0 %
Date: 2019-01-20 Functions: 15 15 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 <algorithm>
       6             : 
       7             : #include "src/compiler/zone-stats.h"
       8             : 
       9             : namespace v8 {
      10             : namespace internal {
      11             : namespace compiler {
      12             : 
      13          23 : ZoneStats::StatsScope::StatsScope(ZoneStats* zone_stats)
      14             :     : zone_stats_(zone_stats),
      15          23 :       total_allocated_bytes_at_start_(zone_stats->GetTotalAllocatedBytes()),
      16          46 :       max_allocated_bytes_(0) {
      17          23 :   zone_stats_->stats_.push_back(this);
      18          99 :   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          60 :         initial_values_.insert(std::make_pair(zone, size));
      22             :     USE(res);
      23             :     DCHECK(res.second);
      24             :   }
      25          23 : }
      26             : 
      27          23 : ZoneStats::StatsScope::~StatsScope() {
      28             :   DCHECK_EQ(zone_stats_->stats_.back(), this);
      29          23 :   zone_stats_->stats_.pop_back();
      30          23 : }
      31             : 
      32         846 : size_t ZoneStats::StatsScope::GetMaxAllocatedBytes() {
      33        1692 :   return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes());
      34             : }
      35             : 
      36        1753 : size_t ZoneStats::StatsScope::GetCurrentAllocatedBytes() {
      37             :   size_t total = 0;
      38        8770 :   for (Zone* zone : zone_stats_->zones_) {
      39        3511 :     total += static_cast<size_t>(zone->allocation_size());
      40             :     // Adjust for initial values.
      41             :     InitialValues::iterator it = initial_values_.find(zone);
      42        3511 :     if (it != initial_values_.end()) {
      43         935 :       total -= it->second;
      44             :     }
      45             :   }
      46        1753 :   return total;
      47             : }
      48             : 
      49         846 : size_t ZoneStats::StatsScope::GetTotalAllocatedBytes() {
      50         846 :   return zone_stats_->GetTotalAllocatedBytes() -
      51         846 :          total_allocated_bytes_at_start_;
      52             : }
      53             : 
      54          61 : void ZoneStats::StatsScope::ZoneReturned(Zone* zone) {
      55          61 :   size_t current_total = GetCurrentAllocatedBytes();
      56             :   // Update max.
      57         122 :   max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
      58             :   // Drop zone from initial value map.
      59             :   InitialValues::iterator it = initial_values_.find(zone);
      60          61 :   if (it != initial_values_.end()) {
      61             :     initial_values_.erase(it);
      62             :   }
      63          61 : }
      64             : 
      65     2912135 : ZoneStats::ZoneStats(AccountingAllocator* allocator)
      66     2912135 :     : max_allocated_bytes_(0), total_deleted_bytes_(0), allocator_(allocator) {}
      67             : 
      68     2912453 : ZoneStats::~ZoneStats() {
      69             :   DCHECK(zones_.empty());
      70             :   DCHECK(stats_.empty());
      71     2912518 : }
      72             : 
      73         429 : size_t ZoneStats::GetMaxAllocatedBytes() const {
      74         858 :   return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes());
      75             : }
      76             : 
      77         429 : size_t ZoneStats::GetCurrentAllocatedBytes() const {
      78             :   size_t total = 0;
      79   485935619 :   for (Zone* zone : zones_) {
      80   322141549 :     total += static_cast<size_t>(zone->allocation_size());
      81             :   }
      82         429 :   return total;
      83             : }
      84             : 
      85        1298 : size_t ZoneStats::GetTotalAllocatedBytes() const {
      86        2596 :   return total_deleted_bytes_ + GetCurrentAllocatedBytes();
      87             : }
      88             : 
      89    81892733 : Zone* ZoneStats::NewEmptyZone(const char* zone_name) {
      90    81892733 :   Zone* zone = new Zone(allocator_, zone_name);
      91    81898987 :   zones_.push_back(zone);
      92    81895628 :   return zone;
      93             : }
      94             : 
      95    81894879 : void ZoneStats::ReturnZone(Zone* zone) {
      96    81894879 :   size_t current_total = GetCurrentAllocatedBytes();
      97             :   // Update max.
      98   163789758 :   max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
      99             :   // Update stats.
     100   163789819 :   for (StatsScope* stat_scope : stats_) {
     101          61 :     stat_scope->ZoneReturned(zone);
     102             :   }
     103             :   // Remove from used.
     104    81893849 :   Zones::iterator it = std::find(zones_.begin(), zones_.end(), zone);
     105             :   DCHECK(it != zones_.end());
     106    81893849 :   zones_.erase(it);
     107   163786260 :   total_deleted_bytes_ += static_cast<size_t>(zone->allocation_size());
     108    81893130 :   delete zone;
     109    81904164 : }
     110             : 
     111             : }  // namespace compiler
     112             : }  // namespace internal
     113      183867 : }  // namespace v8

Generated by: LCOV version 1.10