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> | |
8 | |
9 #include "src/base/platform/platform.h" | 7 #include "src/base/platform/platform.h" |
10 #include "src/isolate.h" | 8 #include "src/isolate.h" |
11 #include "src/log-inl.h" | 9 #include "src/log-inl.h" |
12 | 10 |
13 namespace v8 { | 11 namespace v8 { |
14 namespace internal { | 12 namespace internal { |
15 | 13 |
16 StatsTable::StatsTable() | 14 StatsTable::StatsTable() |
17 : lookup_function_(NULL), | 15 : lookup_function_(NULL), |
18 create_histogram_function_(NULL), | 16 create_histogram_function_(NULL), |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 186 |
189 #define HP(name, caption) name##_.Reset(); | 187 #define HP(name, caption) name##_.Reset(); |
190 HISTOGRAM_PERCENTAGE_LIST(HP) | 188 HISTOGRAM_PERCENTAGE_LIST(HP) |
191 #undef HP | 189 #undef HP |
192 | 190 |
193 #define HM(name, caption) name##_.Reset(); | 191 #define HM(name, caption) name##_.Reset(); |
194 HISTOGRAM_LEGACY_MEMORY_LIST(HM) | 192 HISTOGRAM_LEGACY_MEMORY_LIST(HM) |
195 #undef HM | 193 #undef HM |
196 } | 194 } |
197 | 195 |
198 class RuntimeCallStatEntries { | |
199 public: | |
200 void Print(std::ostream& os) { | |
201 if (total_call_count > 0) { | |
202 std::sort(entries.rbegin(), entries.rend()); | |
203 os << std::setw(50) << "Runtime Function/C++ Builtin" << std::setw(10) | |
204 << "Time" << std::setw(18) << "Count" << std::endl | |
205 << std::string(86, '=') << std::endl; | |
206 for (Entry& entry : entries) { | |
207 entry.SetTotal(total_time, total_call_count); | |
208 entry.Print(os); | |
209 } | |
210 os << std::string(86, '-') << std::endl; | |
211 Entry("Total", total_time, total_call_count).Print(os); | |
212 } | |
213 } | |
214 | |
215 void Add(const char* name, base::TimeDelta time, uint32_t count) { | |
216 entries.push_back(Entry(name, time, count)); | |
217 total_time += time; | |
218 total_call_count += count; | |
219 } | |
220 | |
221 private: | |
222 class Entry { | |
223 public: | |
224 Entry(const char* name, base::TimeDelta time, uint64_t count) | |
225 : name_(name), | |
226 time_(time.InMilliseconds()), | |
227 count_(count), | |
228 time_percent_(100), | |
229 count_percent_(100) {} | |
230 | |
231 bool operator<(const Entry& other) const { | |
232 if (time_ < other.time_) return true; | |
233 if (time_ > other.time_) return false; | |
234 return count_ < other.count_; | |
235 } | |
236 | |
237 void Print(std::ostream& os) { | |
238 os.precision(2); | |
239 os << std::fixed; | |
240 os << std::setw(50) << name_; | |
241 os << std::setw(8) << time_ << "ms "; | |
242 os << std::setw(6) << time_percent_ << "%"; | |
243 os << std::setw(10) << count_ << " "; | |
244 os << std::setw(6) << count_percent_ << "%"; | |
245 os << std::endl; | |
246 } | |
247 | |
248 void SetTotal(base::TimeDelta total_time, uint64_t total_count) { | |
249 time_percent_ = 100.0 * time_ / total_time.InMilliseconds(); | |
250 count_percent_ = 100.0 * count_ / total_count; | |
251 } | |
252 | |
253 private: | |
254 const char* name_; | |
255 int64_t time_; | |
256 uint64_t count_; | |
257 double time_percent_; | |
258 double count_percent_; | |
259 }; | |
260 | |
261 uint64_t total_call_count = 0; | |
262 base::TimeDelta total_time; | |
263 std::vector<Entry> entries; | |
264 }; | |
265 | |
266 void RuntimeCallStats::Print(std::ostream& os) { | |
267 RuntimeCallStatEntries entries; | |
268 | |
269 #define PRINT_COUNTER(name, nargs, ressize) \ | |
270 if (this->Count_Runtime_##name > 0) { \ | |
271 entries.Add(#name, this->Time_Runtime_##name, this->Count_Runtime_##name); \ | |
272 } | |
273 FOR_EACH_INTRINSIC(PRINT_COUNTER) | |
274 #undef PRINT_COUNTER | |
275 #define PRINT_COUNTER(name, type) \ | |
276 if (this->Count_Builtin_##name > 0) { \ | |
277 entries.Add(#name, this->Time_Builtin_##name, this->Count_Builtin_##name); \ | |
278 } | |
279 BUILTIN_LIST_C(PRINT_COUNTER) | |
280 #undef PRINT_COUNTER | |
281 entries.Print(os); | |
282 } | |
283 | |
284 void RuntimeCallStats::Reset() { | |
285 #define RESET_COUNTER(name, nargs, ressize) \ | |
286 Count_Runtime_##name = 0; \ | |
287 Time_Runtime_##name = base::TimeDelta(); | |
288 FOR_EACH_INTRINSIC(RESET_COUNTER) | |
289 #undef RESET_COUNTER | |
290 #define RESET_COUNTER(name, type) \ | |
291 Count_Builtin_##name = 0; \ | |
292 Time_Builtin_##name = base::TimeDelta(); | |
293 BUILTIN_LIST_C(RESET_COUNTER) | |
294 #undef RESET_COUNTER | |
295 } | |
296 | |
297 } // namespace internal | 196 } // namespace internal |
298 } // namespace v8 | 197 } // namespace v8 |
OLD | NEW |