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_COMPILATION_STATISTICS_H_ 6 #define V8_COMPILATION_STATISTICS_H_ 7 8 #include <map> 9 #include <string> 10 11 #include "src/allocation.h" 12 #include "src/base/platform/time.h" 13 14 namespace v8 { 15 namespace internal { 16 17 class CompilationInfo; 18 19 class CompilationStatistics final : public Malloced { 20 public: CompilationStatistics()21 CompilationStatistics() {} 22 23 class BasicStats { 24 public: BasicStats()25 BasicStats() 26 : total_allocated_bytes_(0), 27 max_allocated_bytes_(0), 28 absolute_max_allocated_bytes_(0) {} 29 30 void Accumulate(const BasicStats& stats); 31 32 base::TimeDelta delta_; 33 size_t total_allocated_bytes_; 34 size_t max_allocated_bytes_; 35 size_t absolute_max_allocated_bytes_; 36 std::string function_name_; 37 }; 38 39 void RecordPhaseStats(const char* phase_kind_name, const char* phase_name, 40 const BasicStats& stats); 41 42 void RecordPhaseKindStats(const char* phase_kind_name, 43 const BasicStats& stats); 44 45 void RecordTotalStats(size_t source_size, const BasicStats& stats); 46 47 private: 48 class TotalStats : public BasicStats { 49 public: TotalStats()50 TotalStats() : source_size_(0) {} 51 uint64_t source_size_; 52 }; 53 54 class OrderedStats : public BasicStats { 55 public: OrderedStats(size_t insert_order)56 explicit OrderedStats(size_t insert_order) : insert_order_(insert_order) {} 57 size_t insert_order_; 58 }; 59 60 class PhaseStats : public OrderedStats { 61 public: PhaseStats(size_t insert_order,const char * phase_kind_name)62 PhaseStats(size_t insert_order, const char* phase_kind_name) 63 : OrderedStats(insert_order), phase_kind_name_(phase_kind_name) {} 64 std::string phase_kind_name_; 65 }; 66 67 friend std::ostream& operator<<(std::ostream& os, 68 const CompilationStatistics& s); 69 70 typedef OrderedStats PhaseKindStats; 71 typedef std::map<std::string, PhaseKindStats> PhaseKindMap; 72 typedef std::map<std::string, PhaseStats> PhaseMap; 73 74 TotalStats total_stats_; 75 PhaseKindMap phase_kind_map_; 76 PhaseMap phase_map_; 77 78 DISALLOW_COPY_AND_ASSIGN(CompilationStatistics); 79 }; 80 81 std::ostream& operator<<(std::ostream& os, const CompilationStatistics& s); 82 83 } // namespace internal 84 } // namespace v8 85 86 #endif 87