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 #ifndef V8_COUNTERS_H_ | 5 #ifndef V8_COUNTERS_H_ |
6 #define V8_COUNTERS_H_ | 6 #define V8_COUNTERS_H_ |
7 | 7 |
8 #include "include/v8.h" | 8 #include "include/v8.h" |
9 #include "src/allocation.h" | 9 #include "src/allocation.h" |
10 #include "src/base/platform/elapsed-timer.h" | 10 #include "src/base/platform/elapsed-timer.h" |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) + | 478 return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) + |
479 value * ((current_ms - last_ms_) / interval_ms); | 479 value * ((current_ms - last_ms_) / interval_ms); |
480 } | 480 } |
481 | 481 |
482 struct RuntimeCallCounter { | 482 struct RuntimeCallCounter { |
483 explicit RuntimeCallCounter(const char* name) : name(name) {} | 483 explicit RuntimeCallCounter(const char* name) : name(name) {} |
484 void Reset(); | 484 void Reset(); |
485 | 485 |
486 const char* name; | 486 const char* name; |
487 int64_t count = 0; | 487 int64_t count = 0; |
| 488 bool enabled = true; |
488 base::TimeDelta time; | 489 base::TimeDelta time; |
489 }; | 490 }; |
490 | 491 |
491 // RuntimeCallTimer is used to keep track of the stack of currently active | 492 // RuntimeCallTimer is used to keep track of the stack of currently active |
492 // timers used for properly measuring the own time of a RuntimeCallCounter. | 493 // timers used for properly measuring the own time of a RuntimeCallCounter. |
493 class RuntimeCallTimer { | 494 class RuntimeCallTimer { |
494 public: | 495 public: |
495 inline void Initialize(RuntimeCallCounter* counter, | 496 inline void Initialize(RuntimeCallCounter* counter, |
496 RuntimeCallTimer* parent) { | 497 RuntimeCallTimer* parent) { |
497 counter_ = counter; | 498 counter_ = counter; |
498 parent_ = parent; | 499 parent_ = parent; |
499 } | 500 } |
500 | 501 |
501 inline void Start() { | 502 inline void Start() { |
502 timer_.Start(); | 503 timer_.Start(); |
503 counter_->count++; | 504 counter_->count++; |
504 } | 505 } |
505 | 506 |
| 507 inline bool enabled() { return counter_ != NULL; } |
| 508 |
506 inline RuntimeCallTimer* Stop() { | 509 inline RuntimeCallTimer* Stop() { |
507 base::TimeDelta delta = timer_.Elapsed(); | 510 base::TimeDelta delta = timer_.Elapsed(); |
508 counter_->time += delta; | 511 counter_->time += delta; |
| 512 |
509 if (parent_ != NULL) { | 513 if (parent_ != NULL) { |
510 parent_->AdjustForSubTimer(delta); | 514 parent_->AdjustForSubTimer(delta); |
511 } | 515 } |
512 return parent_; | 516 return parent_; |
513 } | 517 } |
514 | 518 |
515 inline void AdjustForSubTimer(base::TimeDelta delta) { | 519 inline void AdjustForSubTimer(base::TimeDelta delta) { |
516 counter_->time -= delta; | 520 counter_->time -= delta; |
517 } | 521 } |
518 | 522 |
519 private: | 523 private: |
520 RuntimeCallCounter* counter_; | 524 RuntimeCallCounter* counter_; |
521 RuntimeCallTimer* parent_; | 525 RuntimeCallTimer* parent_; |
522 base::ElapsedTimer timer_; | 526 base::ElapsedTimer timer_; |
523 }; | 527 }; |
524 | 528 |
| 529 #define API_COUNTER(V) \ |
| 530 V(Array_New) \ |
| 531 V(BooleanObject_BooleanValue) \ |
| 532 V(BooleanObject_New) \ |
| 533 V(Context_New) \ |
| 534 V(Date_DateTimeConfigurationChangeNotification) \ |
| 535 V(Date_New) \ |
| 536 V(Date_NumberValue) \ |
| 537 V(Error) \ |
| 538 V(External_New) \ |
| 539 V(Function_New) \ |
| 540 V(FunctionTemplate_New) \ |
| 541 V(FunctionTemplate_NewWithFastHandler) \ |
| 542 V(Int32Value) \ |
| 543 V(IntegerValue) \ |
| 544 V(JSON_Parse) \ |
| 545 V(JSON_Stringify) \ |
| 546 V(Map_AsArray) \ |
| 547 V(Map_Clear) \ |
| 548 V(Map_Delete) \ |
| 549 V(Map_Get) \ |
| 550 V(Map_Has) \ |
| 551 V(Map_New) \ |
| 552 V(Map_Set) \ |
| 553 V(NumberObject_New) \ |
| 554 V(NumberObject_NumberValue) \ |
| 555 V(NumberValue) \ |
| 556 V(Object_New) \ |
| 557 V(ObjectTemplate_New) \ |
| 558 V(Persistent_New) \ |
| 559 V(Private_New) \ |
| 560 V(Promise_Catch) \ |
| 561 V(Promise_Chain) \ |
| 562 V(Promise_HasRejectHandler) \ |
| 563 V(Promise_Resolver_New) \ |
| 564 V(Promise_Resolver_Resolve) \ |
| 565 V(Promise_Then) \ |
| 566 V(Proxy_New) \ |
| 567 V(RangeError) \ |
| 568 V(ReferenceError) \ |
| 569 V(RegExp_New) \ |
| 570 V(Set_Add) \ |
| 571 V(Set_AsArray) \ |
| 572 V(Set_Clear) \ |
| 573 V(Set_Delete) \ |
| 574 V(Set_Has) \ |
| 575 V(Set_New) \ |
| 576 V(String_NewExternalOneByte) \ |
| 577 V(String_NewExternalTwoByte) \ |
| 578 V(String_NewFromOneByte) \ |
| 579 V(String_NewFromTwoByte) \ |
| 580 V(String_NewFromUtf8) \ |
| 581 V(StringObject_New) \ |
| 582 V(StringObject_StringValue) \ |
| 583 V(String_Write) \ |
| 584 V(String_WriteUtf8) \ |
| 585 V(Symbol_New) \ |
| 586 V(SymbolObject_New) \ |
| 587 V(SymbolObject_SymbolValue) \ |
| 588 V(SyntaxError) \ |
| 589 V(ToArrayIndex) \ |
| 590 V(ToDetailString) \ |
| 591 V(ToInt32) \ |
| 592 V(ToInteger) \ |
| 593 V(ToNumber) \ |
| 594 V(ToObject) \ |
| 595 V(ToString) \ |
| 596 V(ToUint32) \ |
| 597 V(TypeError) \ |
| 598 V(Uint32Value) \ |
| 599 V(UnboundScript_GetLineNumber) \ |
| 600 V(UnboundScript_GetName) \ |
| 601 V(UnboundScript_GetSourceMappingURL) \ |
| 602 V(UnboundScript_GetSourceURL) \ |
| 603 V(v8_ArrayBuffer_Cast) \ |
| 604 V(v8_ArrayBuffer_Neuter) \ |
| 605 V(v8_ArrayBuffer_New) \ |
| 606 V(v8_Array_CloneElementAt) \ |
| 607 V(v8_DataView_New) \ |
| 608 V(v8_Debug_Call) \ |
| 609 V(v8_Debug_GetMirror) \ |
| 610 V(v8_Float32Array_New) \ |
| 611 V(v8_Float64Array_New) \ |
| 612 V(v8_Function_Call) \ |
| 613 V(v8_Function_NewInstance) \ |
| 614 V(v8_FunctionTemplate_GetFunction) \ |
| 615 V(v8_Int16Array_New) \ |
| 616 V(v8_Int32Array_New) \ |
| 617 V(v8_Int8Array_New) \ |
| 618 V(v8_Message_GetEndColumn) \ |
| 619 V(v8_Message_GetLineNumber) \ |
| 620 V(v8_Message_GetSourceLine) \ |
| 621 V(v8_Message_GetStartColumn) \ |
| 622 V(v8_Object_CallAsConstructor) \ |
| 623 V(v8_Object_CallAsFunction) \ |
| 624 V(v8_Object_CreateDataProperty) \ |
| 625 V(v8_Object_DefineOwnProperty) \ |
| 626 V(v8_Object_Delete) \ |
| 627 V(v8_Object_DeleteProperty) \ |
| 628 V(v8_Object_ForceSet) \ |
| 629 V(v8_Object_Get) \ |
| 630 V(v8_Object_GetOwnPropertyDescriptor) \ |
| 631 V(v8_Object_GetOwnPropertyNames) \ |
| 632 V(v8_Object_GetPropertyAttributes) \ |
| 633 V(v8_Object_GetPropertyNames) \ |
| 634 V(v8_Object_GetRealNamedProperty) \ |
| 635 V(v8_Object_GetRealNamedPropertyAttributes) \ |
| 636 V(v8_Object_GetRealNamedPropertyAttributesInPrototypeChain) \ |
| 637 V(v8_Object_GetRealNamedPropertyInPrototypeChain) \ |
| 638 V(v8_Object_HasOwnProperty) \ |
| 639 V(v8_Object_HasRealIndexedProperty) \ |
| 640 V(v8_Object_HasRealNamedCallbackProperty) \ |
| 641 V(v8_Object_HasRealNamedProperty) \ |
| 642 V(v8_Object_ObjectProtoToString) \ |
| 643 V(v8_Object_Set) \ |
| 644 V(v8_Object_SetAccessor) \ |
| 645 V(v8_Object_SetIntegrityLevel) \ |
| 646 V(v8_Object_SetPrivate) \ |
| 647 V(v8_Object_SetPrototype) \ |
| 648 V(v8_ObjectTemplate_NewInstance) \ |
| 649 V(v8_ScriptCompiler_Compile) \ |
| 650 V(v8_ScriptCompiler_CompileFunctionInContext) \ |
| 651 V(v8_ScriptCompiler_CompileUnbound) \ |
| 652 V(v8_Script_Run) \ |
| 653 V(v8_SharedArrayBuffer_New) \ |
| 654 V(v8_String_Concat) \ |
| 655 V(v8_TryCatch_StackTrace) \ |
| 656 V(v8_Uint16Array_New) \ |
| 657 V(v8_Uint32Array_New) \ |
| 658 V(v8_Uint8Array_New) \ |
| 659 V(v8_Uint8ClampedArray_New) \ |
| 660 V(v8_UnboundScript_GetId) |
| 661 |
| 662 #define OTHER_COUNTER(V) \ |
| 663 V(AccessorGetterCallback) \ |
| 664 V(AccessorNameGetterCallback) \ |
| 665 V(AccessorNameSetterCallback) \ |
| 666 V(FunctionCallback) \ |
| 667 V(GC) \ |
| 668 V(GenericNamedPropertyDeleterCallback) \ |
| 669 V(GenericNamedPropertyQueryCallback) \ |
| 670 V(GenericNamedPropertySetterCallback) \ |
| 671 V(IndexedPropertyDeleterCallback) \ |
| 672 V(IndexedPropertyGetterCallback) \ |
| 673 V(IndexedPropertyQueryCallback) \ |
| 674 V(IndexedPropertySetterCallback) \ |
| 675 V(InvokeFunctionCallback) \ |
| 676 V(JS_Execution) \ |
| 677 V(RecompileConcurrent) \ |
| 678 V(RecompileSynchronous) \ |
| 679 V(DeoptimizeCode) \ |
| 680 V(OptimizeCode) \ |
| 681 V(CompileFullCode) \ |
| 682 V(CompileIgnition) \ |
| 683 V(CompileEval) \ |
| 684 V(Compile) \ |
| 685 V(CompileSerialize) \ |
| 686 V(CompileDeserialize) \ |
| 687 V(ParseLazy) \ |
| 688 V(Parse) \ |
| 689 V(CompileCode) \ |
| 690 V(PropertyCallback) \ |
| 691 V(UnexpectedStubMiss) |
| 692 |
525 struct RuntimeCallStats { | 693 struct RuntimeCallStats { |
526 // Dummy counter for the unexpected stub miss. | |
527 RuntimeCallCounter UnexpectedStubMiss = | |
528 RuntimeCallCounter("UnexpectedStubMiss"); | |
529 // Counter for runtime callbacks into JavaScript. | |
530 RuntimeCallCounter ExternalCallback = RuntimeCallCounter("ExternalCallback"); | |
531 RuntimeCallCounter GC = RuntimeCallCounter("GC"); | |
532 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ | 694 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ |
533 RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name); | 695 RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name); |
534 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) | 696 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) |
535 #undef CALL_RUNTIME_COUNTER | 697 #undef CALL_RUNTIME_COUNTER |
536 #define CALL_BUILTIN_COUNTER(name, type) \ | 698 #define CALL_BUILTIN_COUNTER(name, type) \ |
537 RuntimeCallCounter Builtin_##name = RuntimeCallCounter(#name); | 699 RuntimeCallCounter Builtin_##name = RuntimeCallCounter(#name); |
538 BUILTIN_LIST_C(CALL_BUILTIN_COUNTER) | 700 BUILTIN_LIST_C(CALL_BUILTIN_COUNTER) |
539 #undef CALL_BUILTIN_COUNTER | 701 #undef CALL_BUILTIN_COUNTER |
| 702 #define CALL_BUILTIN_COUNTER(name) \ |
| 703 RuntimeCallCounter API_##name = RuntimeCallCounter("API_" #name); |
| 704 API_COUNTER(CALL_BUILTIN_COUNTER) |
| 705 #undef CALL_BUILTIN_COUNTER |
| 706 #define CALL_BUILTIN_COUNTER(name) \ |
| 707 RuntimeCallCounter name = RuntimeCallCounter(#name); |
| 708 OTHER_COUNTER(CALL_BUILTIN_COUNTER) |
| 709 #undef CALL_BUILTIN_COUNTER |
540 | 710 |
541 // Counter to track recursive time events. | 711 // Counter to track recursive time events. |
542 RuntimeCallTimer* current_timer_ = NULL; | 712 RuntimeCallTimer* current_timer_ = NULL; |
543 | 713 |
544 // Starting measuring the time for a function. This will establish the | 714 // Starting measuring the time for a function. This will establish the |
545 // connection to the parent counter for properly calculating the own times. | 715 // connection to the parent counter for properly calculating the own times. |
546 void Enter(RuntimeCallCounter* counter); | 716 void Enter(RuntimeCallCounter* counter); |
547 void Enter(RuntimeCallTimer* timer); | 717 void Enter(RuntimeCallTimer* timer); |
548 // Leave a scope for a measured runtime function. This will properly add | 718 // Leave a scope for a measured runtime function. This will properly add |
549 // the time delta to the current_counter and subtract the delta from its | 719 // the time delta to the current_counter and subtract the delta from its |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 | 1159 |
990 explicit Counters(Isolate* isolate); | 1160 explicit Counters(Isolate* isolate); |
991 | 1161 |
992 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); | 1162 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); |
993 }; | 1163 }; |
994 | 1164 |
995 } // namespace internal | 1165 } // namespace internal |
996 } // namespace v8 | 1166 } // namespace v8 |
997 | 1167 |
998 #endif // V8_COUNTERS_H_ | 1168 #endif // V8_COUNTERS_H_ |
OLD | NEW |