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#ifndef V8_COMPILER_PIPELINE_STATISTICS_H_ 6#define V8_COMPILER_PIPELINE_STATISTICS_H_ 7 8#include <string> 9 10#include "src/base/platform/elapsed-timer.h" 11#include "src/base/smart-pointers.h" 12#include "src/compilation-statistics.h" 13#include "src/compiler/zone-pool.h" 14 15namespace v8 { 16namespace internal { 17namespace compiler { 18 19class PhaseScope; 20 21class PipelineStatistics : public Malloced { 22 public: 23 PipelineStatistics(CompilationInfo* info, ZonePool* zone_pool); 24 ~PipelineStatistics(); 25 26 void BeginPhaseKind(const char* phase_kind_name); 27 void EndPhaseKind(); 28 29 private: 30 size_t OuterZoneSize() { 31 return static_cast<size_t>(outer_zone_->allocation_size()); 32 } 33 34 class CommonStats { 35 public: 36 CommonStats() : outer_zone_initial_size_(0) {} 37 38 void Begin(PipelineStatistics* pipeline_stats); 39 void End(PipelineStatistics* pipeline_stats, 40 CompilationStatistics::BasicStats* diff); 41 42 base::SmartPointer<ZonePool::StatsScope> scope_; 43 base::ElapsedTimer timer_; 44 size_t outer_zone_initial_size_; 45 size_t allocated_bytes_at_start_; 46 }; 47 48 bool InPhaseKind() { return !phase_kind_stats_.scope_.is_empty(); } 49 50 friend class PhaseScope; 51 bool InPhase() { return !phase_stats_.scope_.is_empty(); } 52 void BeginPhase(const char* name); 53 void EndPhase(); 54 55 Isolate* isolate_; 56 Zone* outer_zone_; 57 ZonePool* zone_pool_; 58 CompilationStatistics* compilation_stats_; 59 std::string function_name_; 60 61 // Stats for the entire compilation. 62 CommonStats total_stats_; 63 size_t source_size_; 64 65 // Stats for phase kind. 66 const char* phase_kind_name_; 67 CommonStats phase_kind_stats_; 68 69 // Stats for phase. 70 const char* phase_name_; 71 CommonStats phase_stats_; 72 73 DISALLOW_COPY_AND_ASSIGN(PipelineStatistics); 74}; 75 76 77class PhaseScope { 78 public: 79 PhaseScope(PipelineStatistics* pipeline_stats, const char* name) 80 : pipeline_stats_(pipeline_stats) { 81 if (pipeline_stats_ != nullptr) pipeline_stats_->BeginPhase(name); 82 } 83 ~PhaseScope() { 84 if (pipeline_stats_ != nullptr) pipeline_stats_->EndPhase(); 85 } 86 87 private: 88 PipelineStatistics* const pipeline_stats_; 89 90 DISALLOW_COPY_AND_ASSIGN(PhaseScope); 91}; 92 93} // namespace compiler 94} // namespace internal 95} // namespace v8 96 97#endif 98