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/compiler/zone-stats.h" 13 #include "src/diagnostics/compilation-statistics.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(OptimizedCompilationInfo* info, 24 CompilationStatistics* turbo_stats, ZoneStats* zone_stats); 25 ~PipelineStatistics(); 26 PipelineStatistics(const PipelineStatistics&) = delete; 27 PipelineStatistics& operator=(const PipelineStatistics&) = delete; 28 29 void BeginPhaseKind(const char* phase_kind_name); 30 void EndPhaseKind(); 31 32 private: OuterZoneSize()33 size_t OuterZoneSize() { 34 return static_cast<size_t>(outer_zone_->allocation_size()); 35 } 36 37 class CommonStats { 38 public: CommonStats()39 CommonStats() : outer_zone_initial_size_(0) {} 40 CommonStats(const CommonStats&) = delete; 41 CommonStats& operator=(const CommonStats&) = delete; 42 43 void Begin(PipelineStatistics* pipeline_stats); 44 void End(PipelineStatistics* pipeline_stats, 45 CompilationStatistics::BasicStats* diff); 46 47 std::unique_ptr<ZoneStats::StatsScope> scope_; 48 base::ElapsedTimer timer_; 49 size_t outer_zone_initial_size_; 50 size_t allocated_bytes_at_start_; 51 }; 52 InPhaseKind()53 bool InPhaseKind() { return !!phase_kind_stats_.scope_; } 54 55 friend class PhaseScope; InPhase()56 bool InPhase() { return !!phase_stats_.scope_; } 57 void BeginPhase(const char* name); 58 void EndPhase(); 59 60 Zone* outer_zone_; 61 ZoneStats* zone_stats_; 62 CompilationStatistics* compilation_stats_; 63 std::string function_name_; 64 65 // Stats for the entire compilation. 66 CommonStats total_stats_; 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 77 78 class PhaseScope { 79 public: PhaseScope(PipelineStatistics * pipeline_stats,const char * name)80 PhaseScope(PipelineStatistics* pipeline_stats, const char* name) 81 : pipeline_stats_(pipeline_stats) { 82 if (pipeline_stats_ != nullptr) pipeline_stats_->BeginPhase(name); 83 } ~PhaseScope()84 ~PhaseScope() { 85 if (pipeline_stats_ != nullptr) pipeline_stats_->EndPhase(); 86 } 87 PhaseScope(const PhaseScope&) = delete; 88 PhaseScope& operator=(const PhaseScope&) = delete; 89 90 private: 91 PipelineStatistics* const pipeline_stats_; 92 }; 93 94 } // namespace compiler 95 } // namespace internal 96 } // namespace v8 97 98 #endif // V8_COMPILER_PIPELINE_STATISTICS_H_ 99