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 class CompilationStatistics; 19 20 struct AsPrintableStatistics { 21 const CompilationStatistics& s; 22 const bool machine_output; 23 }; 24 25 class CompilationStatistics final : public Malloced { 26 public: CompilationStatistics()27 CompilationStatistics() {} 28 29 class BasicStats { 30 public: BasicStats()31 BasicStats() 32 : total_allocated_bytes_(0), 33 max_allocated_bytes_(0), 34 absolute_max_allocated_bytes_(0) {} 35 36 void Accumulate(const BasicStats& stats); 37 38 base::TimeDelta delta_; 39 size_t total_allocated_bytes_; 40 size_t max_allocated_bytes_; 41 size_t absolute_max_allocated_bytes_; 42 std::string function_name_; 43 }; 44 45 void RecordPhaseStats(const char* phase_kind_name, const char* phase_name, 46 const BasicStats& stats); 47 48 void RecordPhaseKindStats(const char* phase_kind_name, 49 const BasicStats& stats); 50 51 void RecordTotalStats(size_t source_size, const BasicStats& stats); 52 53 private: 54 class TotalStats : public BasicStats { 55 public: TotalStats()56 TotalStats() : source_size_(0) {} 57 uint64_t source_size_; 58 }; 59 60 class OrderedStats : public BasicStats { 61 public: OrderedStats(size_t insert_order)62 explicit OrderedStats(size_t insert_order) : insert_order_(insert_order) {} 63 size_t insert_order_; 64 }; 65 66 class PhaseStats : public OrderedStats { 67 public: PhaseStats(size_t insert_order,const char * phase_kind_name)68 PhaseStats(size_t insert_order, const char* phase_kind_name) 69 : OrderedStats(insert_order), phase_kind_name_(phase_kind_name) {} 70 std::string phase_kind_name_; 71 }; 72 73 friend std::ostream& operator<<(std::ostream& os, 74 const AsPrintableStatistics& s); 75 76 typedef OrderedStats PhaseKindStats; 77 typedef std::map<std::string, PhaseKindStats> PhaseKindMap; 78 typedef std::map<std::string, PhaseStats> PhaseMap; 79 80 TotalStats total_stats_; 81 PhaseKindMap phase_kind_map_; 82 PhaseMap phase_map_; 83 base::Mutex record_mutex_; 84 85 DISALLOW_COPY_AND_ASSIGN(CompilationStatistics); 86 }; 87 88 std::ostream& operator<<(std::ostream& os, const AsPrintableStatistics& s); 89 90 } // namespace internal 91 } // namespace v8 92 93 #endif 94