OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/counters.h" | 5 #include "src/counters.h" |
6 | 6 |
7 #include <iomanip> | 7 #include <iomanip> |
8 | 8 |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 #define HM(name, caption) name##_.Reset(); | 193 #define HM(name, caption) name##_.Reset(); |
194 HISTOGRAM_LEGACY_MEMORY_LIST(HM) | 194 HISTOGRAM_LEGACY_MEMORY_LIST(HM) |
195 #undef HM | 195 #undef HM |
196 } | 196 } |
197 | 197 |
198 class RuntimeCallStatEntries { | 198 class RuntimeCallStatEntries { |
199 public: | 199 public: |
200 void Print(std::ostream& os) { | 200 void Print(std::ostream& os) { |
201 if (total_call_count == 0) return; | 201 if (total_call_count == 0) return; |
202 std::sort(entries.rbegin(), entries.rend()); | 202 std::sort(entries.rbegin(), entries.rend()); |
203 os << std::setw(50) << "Runtime Function/C++ Builtin" << std::setw(10) | 203 os << std::setw(50) << "Runtime Function/C++ Builtin" << std::setw(12) |
204 << "Time" << std::setw(18) << "Count" << std::endl | 204 << "Time" << std::setw(18) << "Count" << std::endl |
205 << std::string(86, '=') << std::endl; | 205 << std::string(88, '=') << std::endl; |
206 for (Entry& entry : entries) { | 206 for (Entry& entry : entries) { |
207 entry.SetTotal(total_time, total_call_count); | 207 entry.SetTotal(total_time, total_call_count); |
208 entry.Print(os); | 208 entry.Print(os); |
209 } | 209 } |
210 os << std::string(86, '-') << std::endl; | 210 os << std::string(88, '-') << std::endl; |
211 Entry("Total", total_time, total_call_count).Print(os); | 211 Entry("Total", total_time, total_call_count).Print(os); |
212 } | 212 } |
213 | 213 |
214 void Add(RuntimeCallCounter* counter) { | 214 void Add(RuntimeCallCounter* counter) { |
215 if (counter->count == 0) return; | 215 if (counter->count == 0) return; |
216 entries.push_back(Entry(counter->name, counter->time, counter->count)); | 216 entries.push_back(Entry(counter->name, counter->time, counter->count)); |
217 total_time += counter->time; | 217 total_time += counter->time; |
218 total_call_count += counter->count; | 218 total_call_count += counter->count; |
219 } | 219 } |
220 | 220 |
221 private: | 221 private: |
222 class Entry { | 222 class Entry { |
223 public: | 223 public: |
224 Entry(const char* name, base::TimeDelta time, uint64_t count) | 224 Entry(const char* name, base::TimeDelta time, uint64_t count) |
225 : name_(name), | 225 : name_(name), |
226 time_(time.InMilliseconds()), | 226 time_(time.InMicroseconds()), |
227 count_(count), | 227 count_(count), |
228 time_percent_(100), | 228 time_percent_(100), |
229 count_percent_(100) {} | 229 count_percent_(100) {} |
230 | 230 |
231 bool operator<(const Entry& other) const { | 231 bool operator<(const Entry& other) const { |
232 if (time_ < other.time_) return true; | 232 if (time_ < other.time_) return true; |
233 if (time_ > other.time_) return false; | 233 if (time_ > other.time_) return false; |
234 return count_ < other.count_; | 234 return count_ < other.count_; |
235 } | 235 } |
236 | 236 |
237 void Print(std::ostream& os) { | 237 void Print(std::ostream& os) { |
238 os.precision(2); | 238 os.precision(2); |
239 os << std::fixed; | 239 os << std::fixed << std::setprecision(2); |
240 os << std::setw(50) << name_; | 240 os << std::setw(50) << name_; |
241 os << std::setw(8) << time_ << "ms "; | 241 os << std::setw(10) << static_cast<double>(time_) / 1000 << "ms "; |
242 os << std::setw(6) << time_percent_ << "%"; | 242 os << std::setw(6) << time_percent_ << "%"; |
243 os << std::setw(10) << count_ << " "; | 243 os << std::setw(10) << count_ << " "; |
244 os << std::setw(6) << count_percent_ << "%"; | 244 os << std::setw(6) << count_percent_ << "%"; |
245 os << std::endl; | 245 os << std::endl; |
246 } | 246 } |
247 | 247 |
248 void SetTotal(base::TimeDelta total_time, uint64_t total_count) { | 248 void SetTotal(base::TimeDelta total_time, uint64_t total_count) { |
249 if (total_time.InMilliseconds() == 0) { | 249 if (total_time.InMicroseconds() == 0) { |
250 time_percent_ = 0; | 250 time_percent_ = 0; |
251 } else { | 251 } else { |
252 time_percent_ = 100.0 * time_ / total_time.InMilliseconds(); | 252 time_percent_ = 100.0 * time_ / total_time.InMicroseconds(); |
253 } | 253 } |
254 count_percent_ = 100.0 * count_ / total_count; | 254 count_percent_ = 100.0 * count_ / total_count; |
255 } | 255 } |
256 | 256 |
257 private: | 257 private: |
258 const char* name_; | 258 const char* name_; |
259 int64_t time_; | 259 int64_t time_; |
260 uint64_t count_; | 260 uint64_t count_; |
261 double time_percent_; | 261 double time_percent_; |
262 double count_percent_; | 262 double count_percent_; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 FOR_EACH_API_COUNTER(RESET_COUNTER) | 341 FOR_EACH_API_COUNTER(RESET_COUNTER) |
342 #undef RESET_COUNTER | 342 #undef RESET_COUNTER |
343 | 343 |
344 #define RESET_COUNTER(name) this->Handler_##name.Reset(); | 344 #define RESET_COUNTER(name) this->Handler_##name.Reset(); |
345 FOR_EACH_HANDLER_COUNTER(RESET_COUNTER) | 345 FOR_EACH_HANDLER_COUNTER(RESET_COUNTER) |
346 #undef RESET_COUNTER | 346 #undef RESET_COUNTER |
347 } | 347 } |
348 | 348 |
349 } // namespace internal | 349 } // namespace internal |
350 } // namespace v8 | 350 } // namespace v8 |
OLD | NEW |