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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 entry.Print(os); | 209 entry.Print(os); |
210 } | 210 } |
211 os << std::string(88, '-') << std::endl; | 211 os << std::string(88, '-') << std::endl; |
212 Entry("Total", total_time, total_call_count).Print(os); | 212 Entry("Total", total_time, total_call_count).Print(os); |
213 } | 213 } |
214 | 214 |
215 // By default, the compiler will usually inline this, which results in a large | 215 // By default, the compiler will usually inline this, which results in a large |
216 // binary size increase: std::vector::push_back expands to a large amount of | 216 // binary size increase: std::vector::push_back expands to a large amount of |
217 // instructions, and this function is invoked repeatedly by macros. | 217 // instructions, and this function is invoked repeatedly by macros. |
218 V8_NOINLINE void Add(RuntimeCallCounter* counter) { | 218 V8_NOINLINE void Add(RuntimeCallCounter* counter) { |
219 if (counter->count == 0) return; | 219 if (counter->count() == 0) return; |
220 entries.push_back(Entry(counter->name, counter->time, counter->count)); | 220 entries.push_back( |
221 total_time += counter->time; | 221 Entry(counter->name(), counter->time(), counter->count())); |
222 total_call_count += counter->count; | 222 total_time += counter->time(); |
223 total_call_count += counter->count(); | |
223 } | 224 } |
224 | 225 |
225 private: | 226 private: |
226 class Entry { | 227 class Entry { |
227 public: | 228 public: |
228 Entry(const char* name, base::TimeDelta time, uint64_t count) | 229 Entry(const char* name, base::TimeDelta time, uint64_t count) |
229 : name_(name), | 230 : name_(name), |
230 time_(time.InMicroseconds()), | 231 time_(time.InMicroseconds()), |
231 count_(count), | 232 count_(count), |
232 time_percent_(100), | 233 time_percent_(100), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 double time_percent_; | 267 double time_percent_; |
267 double count_percent_; | 268 double count_percent_; |
268 }; | 269 }; |
269 | 270 |
270 uint64_t total_call_count = 0; | 271 uint64_t total_call_count = 0; |
271 base::TimeDelta total_time; | 272 base::TimeDelta total_time; |
272 std::vector<Entry> entries; | 273 std::vector<Entry> entries; |
273 }; | 274 }; |
274 | 275 |
275 void RuntimeCallCounter::Reset() { | 276 void RuntimeCallCounter::Reset() { |
276 count = 0; | 277 count_ = 0; |
277 time = base::TimeDelta(); | 278 time_ = base::TimeDelta(); |
278 } | 279 } |
279 | 280 |
280 void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) { | 281 void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) { |
281 value->BeginArray(name); | 282 value->BeginArray(name_); |
282 value->AppendLongInteger(count); | 283 value->AppendLongInteger(count_); |
283 value->AppendLongInteger(time.InMicroseconds()); | 284 value->AppendLongInteger(time_.InMicroseconds()); |
284 value->EndArray(); | 285 value->EndArray(); |
285 } | 286 } |
286 | 287 |
287 void RuntimeCallCounter::Add(RuntimeCallCounter* other) { | 288 void RuntimeCallCounter::Add(RuntimeCallCounter* other) { |
288 count += other->count; | 289 count_ += other->count(); |
289 time += other->time; | 290 time_ += other->time(); |
291 } | |
292 | |
293 void RuntimeCallTimer::Snapshot() { | |
294 base::TimeTicks now = base::TimeTicks::Now(); | |
295 RuntimeCallTimer* timer = this; | |
296 base::TimeDelta delta = base::TimeDelta(); | |
Igor Sheludko
2016/11/22 22:53:59
Nit: you can drop = base::TimeDelta().
| |
297 while (timer != nullptr) { | |
298 // Iteration 1: delta = 0, AddSubtime will have no effect | |
299 // Iteration n+1: Subtract the subtimer's time from the current timer. | |
300 timer->SubtractSubtime(delta); | |
301 delta = timer->Restart(now); | |
lpy
2016/11/22 22:25:44
I think there's a problem here. In order to mainta
Igor Sheludko
2016/11/22 22:53:59
We request "now" value only once and then use it t
| |
302 // Add the timer's own time. | |
303 timer->AddAndSubmitResults(delta); | |
304 timer = timer->parent(); | |
305 } | |
290 } | 306 } |
291 | 307 |
292 // static | 308 // static |
293 const RuntimeCallStats::CounterId RuntimeCallStats::counters[] = { | 309 const RuntimeCallStats::CounterId RuntimeCallStats::counters[] = { |
294 #define CALL_RUNTIME_COUNTER(name) &RuntimeCallStats::name, | 310 #define CALL_RUNTIME_COUNTER(name) &RuntimeCallStats::name, |
295 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) // | 311 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) // |
296 #undef CALL_RUNTIME_COUNTER | 312 #undef CALL_RUNTIME_COUNTER |
297 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ | 313 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ |
298 &RuntimeCallStats::Runtime_##name, // | 314 &RuntimeCallStats::Runtime_##name, // |
299 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) // | 315 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) // |
300 #undef CALL_RUNTIME_COUNTER | 316 #undef CALL_RUNTIME_COUNTER |
301 #define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::Builtin_##name, | 317 #define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::Builtin_##name, |
302 BUILTIN_LIST_C(CALL_BUILTIN_COUNTER) // | 318 BUILTIN_LIST_C(CALL_BUILTIN_COUNTER) // |
303 #undef CALL_BUILTIN_COUNTER | 319 #undef CALL_BUILTIN_COUNTER |
304 #define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::API_##name, | 320 #define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::API_##name, |
305 FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER) // | 321 FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER) // |
306 #undef CALL_BUILTIN_COUNTER | 322 #undef CALL_BUILTIN_COUNTER |
307 #define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::Handler_##name, | 323 #define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::Handler_##name, |
308 FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER) | 324 FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER) |
309 #undef CALL_BUILTIN_COUNTER | 325 #undef CALL_BUILTIN_COUNTER |
310 }; | 326 }; |
311 | 327 |
312 // static | 328 // static |
313 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, | 329 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, |
314 CounterId counter_id) { | 330 CounterId counter_id) { |
315 RuntimeCallCounter* counter = &(stats->*counter_id); | 331 RuntimeCallCounter* counter = &(stats->*counter_id); |
316 DCHECK(counter->name != nullptr); | 332 DCHECK(counter->name() != nullptr); |
317 timer->Start(counter, stats->current_timer_.Value()); | 333 timer->Start(counter, stats->current_timer_.Value()); |
318 stats->current_timer_.SetValue(timer); | 334 stats->current_timer_.SetValue(timer); |
319 } | 335 } |
320 | 336 |
321 // static | 337 // static |
322 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { | 338 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { |
323 if (stats->current_timer_.Value() == timer) { | 339 if (stats->current_timer_.Value() == timer) { |
324 stats->current_timer_.SetValue(timer->Stop()); | 340 stats->current_timer_.SetValue(timer->Stop()); |
325 } else { | 341 } else { |
326 // Must be a Threading cctest. Walk the chain of Timers to find the | 342 // Must be a Threading cctest. Walk the chain of Timers to find the |
(...skipping 20 matching lines...) Expand all Loading... | |
347 CounterId counter_id) { | 363 CounterId counter_id) { |
348 RuntimeCallTimer* timer = stats->current_timer_.Value(); | 364 RuntimeCallTimer* timer = stats->current_timer_.Value(); |
349 // When RCS are enabled dynamically there might be no current timer set up. | 365 // When RCS are enabled dynamically there might be no current timer set up. |
350 if (timer == nullptr) return; | 366 if (timer == nullptr) return; |
351 timer->counter_ = &(stats->*counter_id); | 367 timer->counter_ = &(stats->*counter_id); |
352 } | 368 } |
353 | 369 |
354 void RuntimeCallStats::Print(std::ostream& os) { | 370 void RuntimeCallStats::Print(std::ostream& os) { |
355 RuntimeCallStatEntries entries; | 371 RuntimeCallStatEntries entries; |
356 if (current_timer_.Value() != nullptr) { | 372 if (current_timer_.Value() != nullptr) { |
357 current_timer_.Value()->Elapsed(); | 373 current_timer_.Value()->Snapshot(); |
358 } | 374 } |
359 for (const RuntimeCallStats::CounterId counter_id : | 375 for (const RuntimeCallStats::CounterId counter_id : |
360 RuntimeCallStats::counters) { | 376 RuntimeCallStats::counters) { |
361 RuntimeCallCounter* counter = &(this->*counter_id); | 377 RuntimeCallCounter* counter = &(this->*counter_id); |
362 entries.Add(counter); | 378 entries.Add(counter); |
363 } | 379 } |
364 entries.Print(os); | 380 entries.Print(os); |
365 } | 381 } |
366 | 382 |
367 void RuntimeCallStats::Reset() { | 383 void RuntimeCallStats::Reset() { |
(...skipping 13 matching lines...) Expand all Loading... | |
381 counter->Reset(); | 397 counter->Reset(); |
382 } | 398 } |
383 | 399 |
384 in_use_ = true; | 400 in_use_ = true; |
385 } | 401 } |
386 | 402 |
387 void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) { | 403 void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) { |
388 for (const RuntimeCallStats::CounterId counter_id : | 404 for (const RuntimeCallStats::CounterId counter_id : |
389 RuntimeCallStats::counters) { | 405 RuntimeCallStats::counters) { |
390 RuntimeCallCounter* counter = &(this->*counter_id); | 406 RuntimeCallCounter* counter = &(this->*counter_id); |
391 if (counter->count > 0) counter->Dump(value); | 407 if (counter->count() > 0) counter->Dump(value); |
392 } | 408 } |
393 | 409 |
394 in_use_ = false; | 410 in_use_ = false; |
395 } | 411 } |
396 | 412 |
397 } // namespace internal | 413 } // namespace internal |
398 } // namespace v8 | 414 } // namespace v8 |
OLD | NEW |