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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 time = base::TimeDelta(); | 277 time = base::TimeDelta(); |
278 } | 278 } |
279 | 279 |
280 void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) { | 280 void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) { |
281 value->BeginArray(name); | 281 value->BeginArray(name); |
282 value->AppendLongInteger(count); | 282 value->AppendLongInteger(count); |
283 value->AppendLongInteger(time.InMicroseconds()); | 283 value->AppendLongInteger(time.InMicroseconds()); |
284 value->EndArray(); | 284 value->EndArray(); |
285 } | 285 } |
286 | 286 |
287 void RuntimeCallCounter::Add(RuntimeCallCounter* other) { | |
288 count += other->count; | |
289 time += other->time; | |
290 } | |
291 | |
287 // static | 292 // static |
288 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, | 293 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, |
289 CounterId counter_id) { | 294 CounterId counter_id) { |
290 RuntimeCallCounter* counter = &(stats->*counter_id); | 295 RuntimeCallCounter* counter = &(stats->*counter_id); |
296 DCHECK(counter->name != NULL); | |
291 timer->Start(counter, stats->current_timer_.Value()); | 297 timer->Start(counter, stats->current_timer_.Value()); |
292 stats->current_timer_.SetValue(timer); | 298 stats->current_timer_.SetValue(timer); |
293 } | 299 } |
294 | 300 |
295 // static | 301 // static |
296 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { | 302 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { |
297 if (stats->current_timer_.Value() == timer) { | 303 if (stats->current_timer_.Value() == timer) { |
298 stats->current_timer_.SetValue(timer->Stop()); | 304 stats->current_timer_.SetValue(timer->Stop()); |
299 } else { | 305 } else { |
300 // Must be a Threading cctest. Walk the chain of Timers to find the | 306 // Must be a Threading cctest. Walk the chain of Timers to find the |
301 // buried one that's leaving. We don't care about keeping nested timings | 307 // buried one that's leaving. We don't care about keeping nested timings |
302 // accurate, just avoid crashing by keeping the chain intact. | 308 // accurate, just avoid crashing by keeping the chain intact. |
303 RuntimeCallTimer* next = stats->current_timer_.Value(); | 309 RuntimeCallTimer* next = stats->current_timer_.Value(); |
304 while (next->parent() != timer) next = next->parent(); | 310 while (next->parent() != timer) next = next->parent(); |
305 next->parent_.SetValue(timer->Stop()); | 311 next->parent_.SetValue(timer->Stop()); |
306 } | 312 } |
307 } | 313 } |
308 | 314 |
309 // static | 315 void RuntimeCallStats::Add(RuntimeCallStats* other) { |
316 RuntimeCallCounter* current = &(this->First); | |
317 RuntimeCallCounter* other_counter = &(other->First); | |
318 while (current < &(this->Last)) { | |
319 current = reinterpret_cast<RuntimeCallCounter*>( | |
320 reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter)); | |
321 other_counter = reinterpret_cast<RuntimeCallCounter*>( | |
322 reinterpret_cast<intptr_t>(other_counter) + sizeof(RuntimeCallCounter)); | |
323 current->Add(other_counter); | |
324 } | |
325 } | |
326 | |
310 void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats, | 327 void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats, |
311 CounterId counter_id) { | 328 CounterId counter_id) { |
312 RuntimeCallTimer* timer = stats->current_timer_.Value(); | 329 RuntimeCallTimer* timer = stats->current_timer_.Value(); |
313 // When RCS are enabled dynamically there might be no current timer set up. | 330 // When RCS are enabled dynamically there might be no current timer set up. |
314 if (timer == nullptr) return; | 331 if (timer == nullptr) return; |
315 timer->counter_ = &(stats->*counter_id); | 332 timer->counter_ = &(stats->*counter_id); |
316 } | 333 } |
317 | 334 |
318 void RuntimeCallStats::Print(std::ostream& os) { | 335 void RuntimeCallStats::Print(std::ostream& os) { |
319 RuntimeCallStatEntries entries; | 336 RuntimeCallStatEntries entries; |
320 if (current_timer_.Value() != nullptr) { | 337 if (current_timer_.Value() != nullptr) { |
321 current_timer_.Value()->Elapsed(); | 338 current_timer_.Value()->Elapsed(); |
322 } | 339 } |
323 | 340 RuntimeCallCounter* current = &(this->First); |
324 #define PRINT_COUNTER(name) entries.Add(&this->name); | 341 while (current < &(this->Last)) { |
325 FOR_EACH_MANUAL_COUNTER(PRINT_COUNTER) | 342 current = reinterpret_cast<RuntimeCallCounter*>( |
326 #undef PRINT_COUNTER | 343 reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter)); |
327 | 344 entries.Add(current); |
328 #define PRINT_COUNTER(name, nargs, ressize) entries.Add(&this->Runtime_##name); | 345 } |
329 FOR_EACH_INTRINSIC(PRINT_COUNTER) | |
330 #undef PRINT_COUNTER | |
331 | |
332 #define PRINT_COUNTER(name) entries.Add(&this->Builtin_##name); | |
333 BUILTIN_LIST_C(PRINT_COUNTER) | |
334 #undef PRINT_COUNTER | |
335 | |
336 #define PRINT_COUNTER(name) entries.Add(&this->API_##name); | |
337 FOR_EACH_API_COUNTER(PRINT_COUNTER) | |
338 #undef PRINT_COUNTER | |
339 | |
340 #define PRINT_COUNTER(name) entries.Add(&this->Handler_##name); | |
341 FOR_EACH_HANDLER_COUNTER(PRINT_COUNTER) | |
342 #undef PRINT_COUNTER | |
343 | |
344 entries.Print(os); | 346 entries.Print(os); |
345 } | 347 } |
346 | 348 |
347 void RuntimeCallStats::Reset() { | 349 void RuntimeCallStats::Reset() { |
348 if (V8_LIKELY(FLAG_runtime_stats == 0)) return; | 350 if (V8_LIKELY(FLAG_runtime_stats == 0)) return; |
349 | 351 |
350 #define RESET_COUNTER(name) this->name.Reset(); | 352 RuntimeCallCounter* current = &(this->First); |
351 FOR_EACH_MANUAL_COUNTER(RESET_COUNTER) | 353 while (current < &(this->Last)) { |
fmeawad
2016/11/10 15:51:00
Is there a performance impact from adding a check
Camillo Bruni
2016/11/14 09:38:56
I think this doesn't really matter speed-wise, we
| |
352 #undef RESET_COUNTER | 354 current = reinterpret_cast<RuntimeCallCounter*>( |
353 | 355 reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter)); |
354 #define RESET_COUNTER(name, nargs, result_size) this->Runtime_##name.Reset(); | 356 current->Reset(); |
355 FOR_EACH_INTRINSIC(RESET_COUNTER) | 357 } |
356 #undef RESET_COUNTER | |
357 | |
358 #define RESET_COUNTER(name) this->Builtin_##name.Reset(); | |
359 BUILTIN_LIST_C(RESET_COUNTER) | |
360 #undef RESET_COUNTER | |
361 | |
362 #define RESET_COUNTER(name) this->API_##name.Reset(); | |
363 FOR_EACH_API_COUNTER(RESET_COUNTER) | |
364 #undef RESET_COUNTER | |
365 | |
366 #define RESET_COUNTER(name) this->Handler_##name.Reset(); | |
367 FOR_EACH_HANDLER_COUNTER(RESET_COUNTER) | |
368 #undef RESET_COUNTER | |
369 | 358 |
370 in_use_ = true; | 359 in_use_ = true; |
371 } | 360 } |
372 | 361 |
373 void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) { | 362 void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) { |
374 if (current_timer_.Value() != nullptr) { | 363 if (current_timer_.Value() != nullptr) { |
375 current_timer_.Value()->Elapsed(); | 364 current_timer_.Value()->Elapsed(); |
376 } | 365 } |
377 #define DUMP_COUNTER(name) \ | 366 RuntimeCallCounter* current = &(this->First); |
378 if (this->name.count > 0) this->name.Dump(value); | 367 while (current < &(this->Last)) { |
379 FOR_EACH_MANUAL_COUNTER(DUMP_COUNTER) | 368 current = reinterpret_cast<RuntimeCallCounter*>( |
380 #undef DUMP_COUNTER | 369 reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter)); |
381 | 370 if (current->count > 0) current->Dump(value); |
382 #define DUMP_COUNTER(name, nargs, result_size) \ | 371 } |
383 if (this->Runtime_##name.count > 0) this->Runtime_##name.Dump(value); | |
384 FOR_EACH_INTRINSIC(DUMP_COUNTER) | |
385 #undef DUMP_COUNTER | |
386 | |
387 #define DUMP_COUNTER(name) \ | |
388 if (this->Builtin_##name.count > 0) this->Builtin_##name.Dump(value); | |
389 BUILTIN_LIST_C(DUMP_COUNTER) | |
390 #undef DUMP_COUNTER | |
391 | |
392 #define DUMP_COUNTER(name) \ | |
393 if (this->API_##name.count > 0) this->API_##name.Dump(value); | |
394 FOR_EACH_API_COUNTER(DUMP_COUNTER) | |
395 #undef DUMP_COUNTER | |
396 | |
397 #define DUMP_COUNTER(name) \ | |
398 if (this->Handler_##name.count > 0) this->Handler_##name.Dump(value); | |
399 FOR_EACH_HANDLER_COUNTER(DUMP_COUNTER) | |
400 #undef DUMP_COUNTER | |
401 | 372 |
402 in_use_ = false; | 373 in_use_ = false; |
403 } | 374 } |
404 | 375 |
405 } // namespace internal | 376 } // namespace internal |
406 } // namespace v8 | 377 } // namespace v8 |
OLD | NEW |