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