OLD | NEW |
(Empty) | |
| 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 #include <iostream> // NOLINT(readability/streams) |
| 6 #include <vector> |
| 7 |
| 8 #include "src/base/platform/platform.h" |
| 9 #include "src/compilation-statistics.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 |
| 14 void CompilationStatistics::RecordPhaseStats(const char* phase_kind_name, |
| 15 const char* phase_name, |
| 16 const BasicStats& stats) { |
| 17 std::string phase_name_str(phase_name); |
| 18 auto it = phase_map_.find(phase_name_str); |
| 19 if (it == phase_map_.end()) { |
| 20 PhaseStats phase_stats(phase_map_.size(), phase_kind_name); |
| 21 it = phase_map_.insert(std::make_pair(phase_name_str, phase_stats)).first; |
| 22 } |
| 23 it->second.Accumulate(stats); |
| 24 } |
| 25 |
| 26 |
| 27 void CompilationStatistics::RecordPhaseKindStats(const char* phase_kind_name, |
| 28 const BasicStats& stats) { |
| 29 std::string phase_kind_name_str(phase_kind_name); |
| 30 auto it = phase_kind_map_.find(phase_kind_name_str); |
| 31 if (it == phase_kind_map_.end()) { |
| 32 PhaseKindStats phase_kind_stats(phase_kind_map_.size()); |
| 33 it = phase_kind_map_.insert(std::make_pair(phase_kind_name_str, |
| 34 phase_kind_stats)).first; |
| 35 } |
| 36 it->second.Accumulate(stats); |
| 37 } |
| 38 |
| 39 |
| 40 void CompilationStatistics::RecordTotalStats(size_t source_size, |
| 41 const BasicStats& stats) { |
| 42 source_size += source_size; |
| 43 total_stats_.Accumulate(stats); |
| 44 } |
| 45 |
| 46 |
| 47 void CompilationStatistics::BasicStats::Accumulate(const BasicStats& stats) { |
| 48 delta_ += stats.delta_; |
| 49 total_allocated_bytes_ += stats.total_allocated_bytes_; |
| 50 if (stats.max_allocated_bytes_ > max_allocated_bytes_) { |
| 51 max_allocated_bytes_ = stats.max_allocated_bytes_; |
| 52 function_name_ = stats.function_name_; |
| 53 } |
| 54 } |
| 55 |
| 56 |
| 57 static void WriteLine(std::ostream& os, const char* name, |
| 58 const CompilationStatistics::BasicStats& stats, |
| 59 const CompilationStatistics::BasicStats& total_stats) { |
| 60 const size_t kBufferSize = 128; |
| 61 char buffer[kBufferSize]; |
| 62 |
| 63 double ms = stats.delta_.InMillisecondsF(); |
| 64 double percent = stats.delta_.PercentOf(total_stats.delta_); |
| 65 double size_percent = |
| 66 static_cast<double>(stats.total_allocated_bytes_ * 100) / |
| 67 static_cast<double>(total_stats.total_allocated_bytes_); |
| 68 base::OS::SNPrintF(buffer, kBufferSize, |
| 69 "%28s %10.3f ms / %5.1f %% %10u total / %5.1f %% %10u max", |
| 70 name, ms, percent, stats.total_allocated_bytes_, |
| 71 size_percent, stats.max_allocated_bytes_); |
| 72 |
| 73 os << buffer; |
| 74 if (stats.function_name_.size() > 0) { |
| 75 os << " : " << stats.function_name_.c_str(); |
| 76 } |
| 77 os << std::endl; |
| 78 } |
| 79 |
| 80 |
| 81 static void WriteFullLine(std::ostream& os) { |
| 82 os << "-----------------------------------------------" |
| 83 "-----------------------------------------------\n"; |
| 84 } |
| 85 |
| 86 |
| 87 static void WriteHeader(std::ostream& os) { |
| 88 WriteFullLine(os); |
| 89 os << " Turbofan timing results:\n"; |
| 90 WriteFullLine(os); |
| 91 } |
| 92 |
| 93 |
| 94 static void WritePhaseKindBreak(std::ostream& os) { |
| 95 os << " ------------------" |
| 96 "-----------------------------------------------\n"; |
| 97 } |
| 98 |
| 99 |
| 100 std::ostream& operator<<(std::ostream& os, const CompilationStatistics& s) { |
| 101 // phase_kind_map_ and phase_map_ don't get mutated, so store a bunch of |
| 102 // pointers into them. |
| 103 |
| 104 typedef std::vector<CompilationStatistics::PhaseKindMap::const_iterator> |
| 105 SortedPhaseKinds; |
| 106 SortedPhaseKinds sorted_phase_kinds(s.phase_kind_map_.size()); |
| 107 for (auto it = s.phase_kind_map_.begin(); it != s.phase_kind_map_.end(); |
| 108 ++it) { |
| 109 sorted_phase_kinds[it->second.insert_order_] = it; |
| 110 } |
| 111 |
| 112 typedef std::vector<CompilationStatistics::PhaseMap::const_iterator> |
| 113 SortedPhases; |
| 114 SortedPhases sorted_phases(s.phase_map_.size()); |
| 115 for (auto it = s.phase_map_.begin(); it != s.phase_map_.end(); ++it) { |
| 116 sorted_phases[it->second.insert_order_] = it; |
| 117 } |
| 118 |
| 119 WriteHeader(os); |
| 120 for (auto phase_kind_it : sorted_phase_kinds) { |
| 121 const auto& phase_kind_name = phase_kind_it->first; |
| 122 for (auto phase_it : sorted_phases) { |
| 123 const auto& phase_stats = phase_it->second; |
| 124 if (phase_stats.phase_kind_name_ != phase_kind_name) continue; |
| 125 const auto& phase_name = phase_it->first; |
| 126 WriteLine(os, phase_name.c_str(), phase_stats, s.total_stats_); |
| 127 } |
| 128 WritePhaseKindBreak(os); |
| 129 const auto& phase_kind_stats = phase_kind_it->second; |
| 130 WriteLine(os, phase_kind_name.c_str(), phase_kind_stats, s.total_stats_); |
| 131 os << std::endl; |
| 132 } |
| 133 WriteFullLine(os); |
| 134 WriteLine(os, "totals", s.total_stats_, s.total_stats_); |
| 135 |
| 136 return os; |
| 137 } |
| 138 |
| 139 } // namespace internal |
| 140 } // namespace v8 |
OLD | NEW |