Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 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 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 10 | #include "src/base/platform/elapsed-timer.h" |
| 11 | #include "src/base/smart-pointers.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 12 | #include "src/compilation-statistics.h" |
| 13 | #include "src/compiler/zone-pool.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, ZonePool* zone_pool); |
| 24 | ~PipelineStatistics(); |
| 25 | |
| 26 | void BeginPhaseKind(const char* phase_kind_name); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 27 | void EndPhaseKind(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 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 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 42 | base::SmartPointer<ZonePool::StatsScope> scope_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 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(); } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 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 | |
| 77 | class PhaseScope { |
| 78 | public: |
| 79 | PhaseScope(PipelineStatistics* pipeline_stats, const char* name) |
| 80 | : pipeline_stats_(pipeline_stats) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 81 | if (pipeline_stats_ != nullptr) pipeline_stats_->BeginPhase(name); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 82 | } |
| 83 | ~PhaseScope() { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 84 | if (pipeline_stats_ != nullptr) pipeline_stats_->EndPhase(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 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 |