8 #include "src/base/platform/platform.h" 9 #include "src/compilation-statistics.h" 14 void CompilationStatistics::RecordPhaseStats(
const char* phase_kind_name,
15 const char* phase_name,
16 const BasicStats& stats) {
17 base::MutexGuard guard(&record_mutex_);
19 std::string phase_name_str(phase_name);
20 auto it = phase_map_.find(phase_name_str);
21 if (it == phase_map_.end()) {
22 PhaseStats phase_stats(phase_map_.size(), phase_kind_name);
23 it = phase_map_.insert(std::make_pair(phase_name_str, phase_stats)).first;
25 it->second.Accumulate(stats);
29 void CompilationStatistics::RecordPhaseKindStats(
const char* phase_kind_name,
30 const BasicStats& stats) {
31 base::MutexGuard guard(&record_mutex_);
33 std::string phase_kind_name_str(phase_kind_name);
34 auto it = phase_kind_map_.find(phase_kind_name_str);
35 if (it == phase_kind_map_.end()) {
36 PhaseKindStats phase_kind_stats(phase_kind_map_.size());
37 it = phase_kind_map_.insert(std::make_pair(phase_kind_name_str,
38 phase_kind_stats)).first;
40 it->second.Accumulate(stats);
44 void CompilationStatistics::RecordTotalStats(
size_t source_size,
45 const BasicStats& stats) {
46 base::MutexGuard guard(&record_mutex_);
48 source_size += source_size;
49 total_stats_.Accumulate(stats);
53 void CompilationStatistics::BasicStats::Accumulate(
const BasicStats& stats) {
54 delta_ += stats.delta_;
55 total_allocated_bytes_ += stats.total_allocated_bytes_;
56 if (stats.absolute_max_allocated_bytes_ > absolute_max_allocated_bytes_) {
57 absolute_max_allocated_bytes_ = stats.absolute_max_allocated_bytes_;
58 max_allocated_bytes_ = stats.max_allocated_bytes_;
59 function_name_ = stats.function_name_;
63 static void WriteLine(std::ostream& os,
bool machine_format,
const char* name,
64 const CompilationStatistics::BasicStats& stats,
65 const CompilationStatistics::BasicStats& total_stats) {
66 const size_t kBufferSize = 128;
67 char buffer[kBufferSize];
69 double ms = stats.delta_.InMillisecondsF();
70 double percent = stats.delta_.PercentOf(total_stats.delta_);
72 static_cast<double>(stats.total_allocated_bytes_ * 100) /
73 static_cast<double>(total_stats.total_allocated_bytes_);
75 base::OS::SNPrintF(buffer, kBufferSize,
76 "\"%s_time\"=%.3f\n\"%s_space\"=%" PRIuS, name, ms, name,
77 stats.total_allocated_bytes_);
80 base::OS::SNPrintF(buffer, kBufferSize,
"%28s %10.3f (%5.1f%%) %10" PRIuS
81 " (%5.1f%%) %10" PRIuS
" %10" PRIuS,
82 name, ms, percent, stats.total_allocated_bytes_,
83 size_percent, stats.max_allocated_bytes_,
84 stats.absolute_max_allocated_bytes_);
87 if (stats.function_name_.size() > 0) {
88 os <<
" " << stats.function_name_.c_str();
95 static void WriteFullLine(std::ostream& os) {
96 os <<
"--------------------------------------------------------" 97 "--------------------------------------------------------\n";
101 static void WriteHeader(std::ostream& os) {
103 os <<
" Turbofan phase Time (ms) " 104 <<
" Space (bytes) Function\n" 106 <<
" Total Max. Abs. max.\n";
111 static void WritePhaseKindBreak(std::ostream& os) {
112 os <<
" ---------------------------" 113 "--------------------------------------------------------\n";
116 std::ostream& operator<<(std::ostream& os,
const AsPrintableStatistics& ps) {
119 const CompilationStatistics& s = ps.s;
121 typedef std::vector<CompilationStatistics::PhaseKindMap::const_iterator>
123 SortedPhaseKinds sorted_phase_kinds(s.phase_kind_map_.size());
124 for (
auto it = s.phase_kind_map_.begin(); it != s.phase_kind_map_.end();
126 sorted_phase_kinds[it->second.insert_order_] = it;
129 typedef std::vector<CompilationStatistics::PhaseMap::const_iterator>
131 SortedPhases sorted_phases(s.phase_map_.size());
132 for (
auto it = s.phase_map_.begin(); it != s.phase_map_.end(); ++it) {
133 sorted_phases[it->second.insert_order_] = it;
136 if (!ps.machine_output) WriteHeader(os);
137 for (
const auto& phase_kind_it : sorted_phase_kinds) {
138 const auto& phase_kind_name = phase_kind_it->first;
139 if (!ps.machine_output) {
140 for (
const auto& phase_it : sorted_phases) {
141 const auto& phase_stats = phase_it->second;
142 if (phase_stats.phase_kind_name_ != phase_kind_name)
continue;
143 const auto& phase_name = phase_it->first;
144 WriteLine(os, ps.machine_output, phase_name.c_str(), phase_stats,
147 WritePhaseKindBreak(os);
149 const auto& phase_kind_stats = phase_kind_it->second;
150 WriteLine(os, ps.machine_output, phase_kind_name.c_str(), phase_kind_stats,
155 if (!ps.machine_output) WriteFullLine(os);
156 WriteLine(os, ps.machine_output,
"totals", s.total_stats_, s.total_stats_);