Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: src/log.cc

Issue 7350014: Remove the ability to compile without logging and profiling (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed review comments Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/log.h ('k') | src/log-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 25 matching lines...) Expand all
36 #include "log.h" 36 #include "log.h"
37 #include "macro-assembler.h" 37 #include "macro-assembler.h"
38 #include "runtime-profiler.h" 38 #include "runtime-profiler.h"
39 #include "serialize.h" 39 #include "serialize.h"
40 #include "string-stream.h" 40 #include "string-stream.h"
41 #include "vm-state-inl.h" 41 #include "vm-state-inl.h"
42 42
43 namespace v8 { 43 namespace v8 {
44 namespace internal { 44 namespace internal {
45 45
46 #ifdef ENABLE_LOGGING_AND_PROFILING
47
48 // 46 //
49 // Sliding state window. Updates counters to keep track of the last 47 // Sliding state window. Updates counters to keep track of the last
50 // window of kBufferSize states. This is useful to track where we 48 // window of kBufferSize states. This is useful to track where we
51 // spent our time. 49 // spent our time.
52 // 50 //
53 class SlidingStateWindow { 51 class SlidingStateWindow {
54 public: 52 public:
55 explicit SlidingStateWindow(Isolate* isolate); 53 explicit SlidingStateWindow(Isolate* isolate);
56 ~SlidingStateWindow(); 54 ~SlidingStateWindow();
57 void AddState(StateTag state); 55 void AddState(StateTag state);
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 #undef DECLARE_EVENT 545 #undef DECLARE_EVENT
548 546
549 547
550 void Logger::ProfilerBeginEvent() { 548 void Logger::ProfilerBeginEvent() {
551 if (!log_->IsEnabled()) return; 549 if (!log_->IsEnabled()) return;
552 LogMessageBuilder msg(this); 550 LogMessageBuilder msg(this);
553 msg.Append("profiler,\"begin\",%d\n", kSamplingIntervalMs); 551 msg.Append("profiler,\"begin\",%d\n", kSamplingIntervalMs);
554 msg.WriteToLogFile(); 552 msg.WriteToLogFile();
555 } 553 }
556 554
557 #endif // ENABLE_LOGGING_AND_PROFILING
558
559 555
560 void Logger::StringEvent(const char* name, const char* value) { 556 void Logger::StringEvent(const char* name, const char* value) {
561 #ifdef ENABLE_LOGGING_AND_PROFILING
562 if (FLAG_log) UncheckedStringEvent(name, value); 557 if (FLAG_log) UncheckedStringEvent(name, value);
563 #endif
564 } 558 }
565 559
566 560
567 #ifdef ENABLE_LOGGING_AND_PROFILING
568 void Logger::UncheckedStringEvent(const char* name, const char* value) { 561 void Logger::UncheckedStringEvent(const char* name, const char* value) {
569 if (!log_->IsEnabled()) return; 562 if (!log_->IsEnabled()) return;
570 LogMessageBuilder msg(this); 563 LogMessageBuilder msg(this);
571 msg.Append("%s,\"%s\"\n", name, value); 564 msg.Append("%s,\"%s\"\n", name, value);
572 msg.WriteToLogFile(); 565 msg.WriteToLogFile();
573 } 566 }
574 #endif
575 567
576 568
577 void Logger::IntEvent(const char* name, int value) { 569 void Logger::IntEvent(const char* name, int value) {
578 #ifdef ENABLE_LOGGING_AND_PROFILING
579 if (FLAG_log) UncheckedIntEvent(name, value); 570 if (FLAG_log) UncheckedIntEvent(name, value);
580 #endif
581 } 571 }
582 572
583 573
584 void Logger::IntPtrTEvent(const char* name, intptr_t value) { 574 void Logger::IntPtrTEvent(const char* name, intptr_t value) {
585 #ifdef ENABLE_LOGGING_AND_PROFILING
586 if (FLAG_log) UncheckedIntPtrTEvent(name, value); 575 if (FLAG_log) UncheckedIntPtrTEvent(name, value);
587 #endif
588 } 576 }
589 577
590 578
591 #ifdef ENABLE_LOGGING_AND_PROFILING
592 void Logger::UncheckedIntEvent(const char* name, int value) { 579 void Logger::UncheckedIntEvent(const char* name, int value) {
593 if (!log_->IsEnabled()) return; 580 if (!log_->IsEnabled()) return;
594 LogMessageBuilder msg(this); 581 LogMessageBuilder msg(this);
595 msg.Append("%s,%d\n", name, value); 582 msg.Append("%s,%d\n", name, value);
596 msg.WriteToLogFile(); 583 msg.WriteToLogFile();
597 } 584 }
598 #endif
599 585
600 586
601 #ifdef ENABLE_LOGGING_AND_PROFILING
602 void Logger::UncheckedIntPtrTEvent(const char* name, intptr_t value) { 587 void Logger::UncheckedIntPtrTEvent(const char* name, intptr_t value) {
603 if (!log_->IsEnabled()) return; 588 if (!log_->IsEnabled()) return;
604 LogMessageBuilder msg(this); 589 LogMessageBuilder msg(this);
605 msg.Append("%s,%" V8_PTR_PREFIX "d\n", name, value); 590 msg.Append("%s,%" V8_PTR_PREFIX "d\n", name, value);
606 msg.WriteToLogFile(); 591 msg.WriteToLogFile();
607 } 592 }
608 #endif
609 593
610 594
611 void Logger::HandleEvent(const char* name, Object** location) { 595 void Logger::HandleEvent(const char* name, Object** location) {
612 #ifdef ENABLE_LOGGING_AND_PROFILING
613 if (!log_->IsEnabled() || !FLAG_log_handles) return; 596 if (!log_->IsEnabled() || !FLAG_log_handles) return;
614 LogMessageBuilder msg(this); 597 LogMessageBuilder msg(this);
615 msg.Append("%s,0x%" V8PRIxPTR "\n", name, location); 598 msg.Append("%s,0x%" V8PRIxPTR "\n", name, location);
616 msg.WriteToLogFile(); 599 msg.WriteToLogFile();
617 #endif
618 } 600 }
619 601
620 602
621 #ifdef ENABLE_LOGGING_AND_PROFILING
622 // ApiEvent is private so all the calls come from the Logger class. It is the 603 // ApiEvent is private so all the calls come from the Logger class. It is the
623 // caller's responsibility to ensure that log is enabled and that 604 // caller's responsibility to ensure that log is enabled and that
624 // FLAG_log_api is true. 605 // FLAG_log_api is true.
625 void Logger::ApiEvent(const char* format, ...) { 606 void Logger::ApiEvent(const char* format, ...) {
626 ASSERT(log_->IsEnabled() && FLAG_log_api); 607 ASSERT(log_->IsEnabled() && FLAG_log_api);
627 LogMessageBuilder msg(this); 608 LogMessageBuilder msg(this);
628 va_list ap; 609 va_list ap;
629 va_start(ap, format); 610 va_start(ap, format);
630 msg.AppendVA(format, ap); 611 msg.AppendVA(format, ap);
631 va_end(ap); 612 va_end(ap);
632 msg.WriteToLogFile(); 613 msg.WriteToLogFile();
633 } 614 }
634 #endif
635 615
636 616
637 void Logger::ApiNamedSecurityCheck(Object* key) { 617 void Logger::ApiNamedSecurityCheck(Object* key) {
638 #ifdef ENABLE_LOGGING_AND_PROFILING
639 if (!log_->IsEnabled() || !FLAG_log_api) return; 618 if (!log_->IsEnabled() || !FLAG_log_api) return;
640 if (key->IsString()) { 619 if (key->IsString()) {
641 SmartPointer<char> str = 620 SmartPointer<char> str =
642 String::cast(key)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 621 String::cast(key)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
643 ApiEvent("api,check-security,\"%s\"\n", *str); 622 ApiEvent("api,check-security,\"%s\"\n", *str);
644 } else if (key->IsUndefined()) { 623 } else if (key->IsUndefined()) {
645 ApiEvent("api,check-security,undefined\n"); 624 ApiEvent("api,check-security,undefined\n");
646 } else { 625 } else {
647 ApiEvent("api,check-security,['no-name']\n"); 626 ApiEvent("api,check-security,['no-name']\n");
648 } 627 }
649 #endif
650 } 628 }
651 629
652 630
653 void Logger::SharedLibraryEvent(const char* library_path, 631 void Logger::SharedLibraryEvent(const char* library_path,
654 uintptr_t start, 632 uintptr_t start,
655 uintptr_t end) { 633 uintptr_t end) {
656 #ifdef ENABLE_LOGGING_AND_PROFILING
657 if (!log_->IsEnabled() || !FLAG_prof) return; 634 if (!log_->IsEnabled() || !FLAG_prof) return;
658 LogMessageBuilder msg(this); 635 LogMessageBuilder msg(this);
659 msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n", 636 msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n",
660 library_path, 637 library_path,
661 start, 638 start,
662 end); 639 end);
663 msg.WriteToLogFile(); 640 msg.WriteToLogFile();
664 #endif
665 } 641 }
666 642
667 643
668 void Logger::SharedLibraryEvent(const wchar_t* library_path, 644 void Logger::SharedLibraryEvent(const wchar_t* library_path,
669 uintptr_t start, 645 uintptr_t start,
670 uintptr_t end) { 646 uintptr_t end) {
671 #ifdef ENABLE_LOGGING_AND_PROFILING
672 if (!log_->IsEnabled() || !FLAG_prof) return; 647 if (!log_->IsEnabled() || !FLAG_prof) return;
673 LogMessageBuilder msg(this); 648 LogMessageBuilder msg(this);
674 msg.Append("shared-library,\"%ls\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n", 649 msg.Append("shared-library,\"%ls\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n",
675 library_path, 650 library_path,
676 start, 651 start,
677 end); 652 end);
678 msg.WriteToLogFile(); 653 msg.WriteToLogFile();
679 #endif
680 } 654 }
681 655
682 656
683 #ifdef ENABLE_LOGGING_AND_PROFILING
684 void Logger::LogRegExpSource(Handle<JSRegExp> regexp) { 657 void Logger::LogRegExpSource(Handle<JSRegExp> regexp) {
685 // Prints "/" + re.source + "/" + 658 // Prints "/" + re.source + "/" +
686 // (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"") 659 // (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"")
687 LogMessageBuilder msg(this); 660 LogMessageBuilder msg(this);
688 661
689 Handle<Object> source = GetProperty(regexp, "source"); 662 Handle<Object> source = GetProperty(regexp, "source");
690 if (!source->IsString()) { 663 if (!source->IsString()) {
691 msg.Append("no source"); 664 msg.Append("no source");
692 return; 665 return;
693 } 666 }
(...skipping 20 matching lines...) Expand all
714 msg.Append('i'); 687 msg.Append('i');
715 } 688 }
716 // multiline flag 689 // multiline flag
717 Handle<Object> multiline = GetProperty(regexp, "multiline"); 690 Handle<Object> multiline = GetProperty(regexp, "multiline");
718 if (multiline->IsTrue()) { 691 if (multiline->IsTrue()) {
719 msg.Append('m'); 692 msg.Append('m');
720 } 693 }
721 694
722 msg.WriteToLogFile(); 695 msg.WriteToLogFile();
723 } 696 }
724 #endif // ENABLE_LOGGING_AND_PROFILING
725 697
726 698
727 void Logger::RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache) { 699 void Logger::RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache) {
728 #ifdef ENABLE_LOGGING_AND_PROFILING
729 if (!log_->IsEnabled() || !FLAG_log_regexp) return; 700 if (!log_->IsEnabled() || !FLAG_log_regexp) return;
730 LogMessageBuilder msg(this); 701 LogMessageBuilder msg(this);
731 msg.Append("regexp-compile,"); 702 msg.Append("regexp-compile,");
732 LogRegExpSource(regexp); 703 LogRegExpSource(regexp);
733 msg.Append(in_cache ? ",hit\n" : ",miss\n"); 704 msg.Append(in_cache ? ",hit\n" : ",miss\n");
734 msg.WriteToLogFile(); 705 msg.WriteToLogFile();
735 #endif
736 } 706 }
737 707
738 708
739 void Logger::LogRuntime(Vector<const char> format, JSArray* args) { 709 void Logger::LogRuntime(Vector<const char> format, JSArray* args) {
740 #ifdef ENABLE_LOGGING_AND_PROFILING
741 if (!log_->IsEnabled() || !FLAG_log_runtime) return; 710 if (!log_->IsEnabled() || !FLAG_log_runtime) return;
742 HandleScope scope; 711 HandleScope scope;
743 LogMessageBuilder msg(this); 712 LogMessageBuilder msg(this);
744 for (int i = 0; i < format.length(); i++) { 713 for (int i = 0; i < format.length(); i++) {
745 char c = format[i]; 714 char c = format[i];
746 if (c == '%' && i <= format.length() - 2) { 715 if (c == '%' && i <= format.length() - 2) {
747 i++; 716 i++;
748 ASSERT('0' <= format[i] && format[i] <= '9'); 717 ASSERT('0' <= format[i] && format[i] <= '9');
749 MaybeObject* maybe = args->GetElement(format[i] - '0'); 718 MaybeObject* maybe = args->GetElement(format[i] - '0');
750 Object* obj; 719 Object* obj;
(...skipping 20 matching lines...) Expand all
771 break; 740 break;
772 default: 741 default:
773 UNREACHABLE(); 742 UNREACHABLE();
774 } 743 }
775 } else { 744 } else {
776 msg.Append(c); 745 msg.Append(c);
777 } 746 }
778 } 747 }
779 msg.Append('\n'); 748 msg.Append('\n');
780 msg.WriteToLogFile(); 749 msg.WriteToLogFile();
781 #endif
782 } 750 }
783 751
784 752
785 void Logger::ApiIndexedSecurityCheck(uint32_t index) { 753 void Logger::ApiIndexedSecurityCheck(uint32_t index) {
786 #ifdef ENABLE_LOGGING_AND_PROFILING
787 if (!log_->IsEnabled() || !FLAG_log_api) return; 754 if (!log_->IsEnabled() || !FLAG_log_api) return;
788 ApiEvent("api,check-security,%u\n", index); 755 ApiEvent("api,check-security,%u\n", index);
789 #endif
790 } 756 }
791 757
792 758
793 void Logger::ApiNamedPropertyAccess(const char* tag, 759 void Logger::ApiNamedPropertyAccess(const char* tag,
794 JSObject* holder, 760 JSObject* holder,
795 Object* name) { 761 Object* name) {
796 #ifdef ENABLE_LOGGING_AND_PROFILING
797 ASSERT(name->IsString()); 762 ASSERT(name->IsString());
798 if (!log_->IsEnabled() || !FLAG_log_api) return; 763 if (!log_->IsEnabled() || !FLAG_log_api) return;
799 String* class_name_obj = holder->class_name(); 764 String* class_name_obj = holder->class_name();
800 SmartPointer<char> class_name = 765 SmartPointer<char> class_name =
801 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 766 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
802 SmartPointer<char> property_name = 767 SmartPointer<char> property_name =
803 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 768 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
804 ApiEvent("api,%s,\"%s\",\"%s\"\n", tag, *class_name, *property_name); 769 ApiEvent("api,%s,\"%s\",\"%s\"\n", tag, *class_name, *property_name);
805 #endif
806 } 770 }
807 771
808 void Logger::ApiIndexedPropertyAccess(const char* tag, 772 void Logger::ApiIndexedPropertyAccess(const char* tag,
809 JSObject* holder, 773 JSObject* holder,
810 uint32_t index) { 774 uint32_t index) {
811 #ifdef ENABLE_LOGGING_AND_PROFILING
812 if (!log_->IsEnabled() || !FLAG_log_api) return; 775 if (!log_->IsEnabled() || !FLAG_log_api) return;
813 String* class_name_obj = holder->class_name(); 776 String* class_name_obj = holder->class_name();
814 SmartPointer<char> class_name = 777 SmartPointer<char> class_name =
815 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 778 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
816 ApiEvent("api,%s,\"%s\",%u\n", tag, *class_name, index); 779 ApiEvent("api,%s,\"%s\",%u\n", tag, *class_name, index);
817 #endif
818 } 780 }
819 781
820 void Logger::ApiObjectAccess(const char* tag, JSObject* object) { 782 void Logger::ApiObjectAccess(const char* tag, JSObject* object) {
821 #ifdef ENABLE_LOGGING_AND_PROFILING
822 if (!log_->IsEnabled() || !FLAG_log_api) return; 783 if (!log_->IsEnabled() || !FLAG_log_api) return;
823 String* class_name_obj = object->class_name(); 784 String* class_name_obj = object->class_name();
824 SmartPointer<char> class_name = 785 SmartPointer<char> class_name =
825 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 786 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
826 ApiEvent("api,%s,\"%s\"\n", tag, *class_name); 787 ApiEvent("api,%s,\"%s\"\n", tag, *class_name);
827 #endif
828 } 788 }
829 789
830 790
831 void Logger::ApiEntryCall(const char* name) { 791 void Logger::ApiEntryCall(const char* name) {
832 #ifdef ENABLE_LOGGING_AND_PROFILING
833 if (!log_->IsEnabled() || !FLAG_log_api) return; 792 if (!log_->IsEnabled() || !FLAG_log_api) return;
834 ApiEvent("api,%s\n", name); 793 ApiEvent("api,%s\n", name);
835 #endif
836 } 794 }
837 795
838 796
839 void Logger::NewEvent(const char* name, void* object, size_t size) { 797 void Logger::NewEvent(const char* name, void* object, size_t size) {
840 #ifdef ENABLE_LOGGING_AND_PROFILING
841 if (!log_->IsEnabled() || !FLAG_log) return; 798 if (!log_->IsEnabled() || !FLAG_log) return;
842 LogMessageBuilder msg(this); 799 LogMessageBuilder msg(this);
843 msg.Append("new,%s,0x%" V8PRIxPTR ",%u\n", name, object, 800 msg.Append("new,%s,0x%" V8PRIxPTR ",%u\n", name, object,
844 static_cast<unsigned int>(size)); 801 static_cast<unsigned int>(size));
845 msg.WriteToLogFile(); 802 msg.WriteToLogFile();
846 #endif
847 } 803 }
848 804
849 805
850 void Logger::DeleteEvent(const char* name, void* object) { 806 void Logger::DeleteEvent(const char* name, void* object) {
851 #ifdef ENABLE_LOGGING_AND_PROFILING
852 if (!log_->IsEnabled() || !FLAG_log) return; 807 if (!log_->IsEnabled() || !FLAG_log) return;
853 LogMessageBuilder msg(this); 808 LogMessageBuilder msg(this);
854 msg.Append("delete,%s,0x%" V8PRIxPTR "\n", name, object); 809 msg.Append("delete,%s,0x%" V8PRIxPTR "\n", name, object);
855 msg.WriteToLogFile(); 810 msg.WriteToLogFile();
856 #endif
857 } 811 }
858 812
859 813
860 void Logger::NewEventStatic(const char* name, void* object, size_t size) { 814 void Logger::NewEventStatic(const char* name, void* object, size_t size) {
861 LOGGER->NewEvent(name, object, size); 815 LOGGER->NewEvent(name, object, size);
862 } 816 }
863 817
864 818
865 void Logger::DeleteEventStatic(const char* name, void* object) { 819 void Logger::DeleteEventStatic(const char* name, void* object) {
866 LOGGER->DeleteEvent(name, object); 820 LOGGER->DeleteEvent(name, object);
867 } 821 }
868 822
869 #ifdef ENABLE_LOGGING_AND_PROFILING
870 void Logger::CallbackEventInternal(const char* prefix, const char* name, 823 void Logger::CallbackEventInternal(const char* prefix, const char* name,
871 Address entry_point) { 824 Address entry_point) {
872 if (!log_->IsEnabled() || !FLAG_log_code) return; 825 if (!log_->IsEnabled() || !FLAG_log_code) return;
873 LogMessageBuilder msg(this); 826 LogMessageBuilder msg(this);
874 msg.Append("%s,%s,", 827 msg.Append("%s,%s,",
875 kLogEventsNames[CODE_CREATION_EVENT], 828 kLogEventsNames[CODE_CREATION_EVENT],
876 kLogEventsNames[CALLBACK_TAG]); 829 kLogEventsNames[CALLBACK_TAG]);
877 msg.AppendAddress(entry_point); 830 msg.AppendAddress(entry_point);
878 msg.Append(",1,\"%s%s\"", prefix, name); 831 msg.Append(",1,\"%s%s\"", prefix, name);
879 msg.Append('\n'); 832 msg.Append('\n');
880 msg.WriteToLogFile(); 833 msg.WriteToLogFile();
881 } 834 }
882 #endif
883 835
884 836
885 void Logger::CallbackEvent(String* name, Address entry_point) { 837 void Logger::CallbackEvent(String* name, Address entry_point) {
886 #ifdef ENABLE_LOGGING_AND_PROFILING
887 if (!log_->IsEnabled() || !FLAG_log_code) return; 838 if (!log_->IsEnabled() || !FLAG_log_code) return;
888 SmartPointer<char> str = 839 SmartPointer<char> str =
889 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 840 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
890 CallbackEventInternal("", *str, entry_point); 841 CallbackEventInternal("", *str, entry_point);
891 #endif
892 } 842 }
893 843
894 844
895 void Logger::GetterCallbackEvent(String* name, Address entry_point) { 845 void Logger::GetterCallbackEvent(String* name, Address entry_point) {
896 #ifdef ENABLE_LOGGING_AND_PROFILING
897 if (!log_->IsEnabled() || !FLAG_log_code) return; 846 if (!log_->IsEnabled() || !FLAG_log_code) return;
898 SmartPointer<char> str = 847 SmartPointer<char> str =
899 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 848 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
900 CallbackEventInternal("get ", *str, entry_point); 849 CallbackEventInternal("get ", *str, entry_point);
901 #endif
902 } 850 }
903 851
904 852
905 void Logger::SetterCallbackEvent(String* name, Address entry_point) { 853 void Logger::SetterCallbackEvent(String* name, Address entry_point) {
906 #ifdef ENABLE_LOGGING_AND_PROFILING
907 if (!log_->IsEnabled() || !FLAG_log_code) return; 854 if (!log_->IsEnabled() || !FLAG_log_code) return;
908 SmartPointer<char> str = 855 SmartPointer<char> str =
909 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 856 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
910 CallbackEventInternal("set ", *str, entry_point); 857 CallbackEventInternal("set ", *str, entry_point);
911 #endif
912 } 858 }
913 859
914 860
915 void Logger::CodeCreateEvent(LogEventsAndTags tag, 861 void Logger::CodeCreateEvent(LogEventsAndTags tag,
916 Code* code, 862 Code* code,
917 const char* comment) { 863 const char* comment) {
918 #ifdef ENABLE_LOGGING_AND_PROFILING
919 if (!log_->IsEnabled()) return; 864 if (!log_->IsEnabled()) return;
920 if (FLAG_ll_prof || Serializer::enabled()) { 865 if (FLAG_ll_prof || Serializer::enabled()) {
921 name_buffer_->Reset(); 866 name_buffer_->Reset();
922 name_buffer_->AppendBytes(kLogEventsNames[tag]); 867 name_buffer_->AppendBytes(kLogEventsNames[tag]);
923 name_buffer_->AppendByte(':'); 868 name_buffer_->AppendByte(':');
924 name_buffer_->AppendBytes(comment); 869 name_buffer_->AppendBytes(comment);
925 } 870 }
926 if (FLAG_ll_prof) { 871 if (FLAG_ll_prof) {
927 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size()); 872 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
928 } 873 }
929 if (Serializer::enabled()) { 874 if (Serializer::enabled()) {
930 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size()); 875 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
931 } 876 }
932 if (!FLAG_log_code) return; 877 if (!FLAG_log_code) return;
933 LogMessageBuilder msg(this); 878 LogMessageBuilder msg(this);
934 msg.Append("%s,%s,", 879 msg.Append("%s,%s,",
935 kLogEventsNames[CODE_CREATION_EVENT], 880 kLogEventsNames[CODE_CREATION_EVENT],
936 kLogEventsNames[tag]); 881 kLogEventsNames[tag]);
937 msg.AppendAddress(code->address()); 882 msg.AppendAddress(code->address());
938 msg.Append(",%d,\"", code->ExecutableSize()); 883 msg.Append(",%d,\"", code->ExecutableSize());
939 for (const char* p = comment; *p != '\0'; p++) { 884 for (const char* p = comment; *p != '\0'; p++) {
940 if (*p == '"') { 885 if (*p == '"') {
941 msg.Append('\\'); 886 msg.Append('\\');
942 } 887 }
943 msg.Append(*p); 888 msg.Append(*p);
944 } 889 }
945 msg.Append('"'); 890 msg.Append('"');
946 msg.Append('\n'); 891 msg.Append('\n');
947 msg.WriteToLogFile(); 892 msg.WriteToLogFile();
948 #endif
949 } 893 }
950 894
951 895
952 void Logger::CodeCreateEvent(LogEventsAndTags tag, 896 void Logger::CodeCreateEvent(LogEventsAndTags tag,
953 Code* code, 897 Code* code,
954 String* name) { 898 String* name) {
955 #ifdef ENABLE_LOGGING_AND_PROFILING
956 if (!log_->IsEnabled()) return; 899 if (!log_->IsEnabled()) return;
957 if (FLAG_ll_prof || Serializer::enabled()) { 900 if (FLAG_ll_prof || Serializer::enabled()) {
958 name_buffer_->Reset(); 901 name_buffer_->Reset();
959 name_buffer_->AppendBytes(kLogEventsNames[tag]); 902 name_buffer_->AppendBytes(kLogEventsNames[tag]);
960 name_buffer_->AppendByte(':'); 903 name_buffer_->AppendByte(':');
961 name_buffer_->AppendString(name); 904 name_buffer_->AppendString(name);
962 } 905 }
963 if (FLAG_ll_prof) { 906 if (FLAG_ll_prof) {
964 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size()); 907 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
965 } 908 }
966 if (Serializer::enabled()) { 909 if (Serializer::enabled()) {
967 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size()); 910 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
968 } 911 }
969 if (!FLAG_log_code) return; 912 if (!FLAG_log_code) return;
970 LogMessageBuilder msg(this); 913 LogMessageBuilder msg(this);
971 msg.Append("%s,%s,", 914 msg.Append("%s,%s,",
972 kLogEventsNames[CODE_CREATION_EVENT], 915 kLogEventsNames[CODE_CREATION_EVENT],
973 kLogEventsNames[tag]); 916 kLogEventsNames[tag]);
974 msg.AppendAddress(code->address()); 917 msg.AppendAddress(code->address());
975 msg.Append(",%d,\"", code->ExecutableSize()); 918 msg.Append(",%d,\"", code->ExecutableSize());
976 msg.AppendDetailed(name, false); 919 msg.AppendDetailed(name, false);
977 msg.Append('"'); 920 msg.Append('"');
978 msg.Append('\n'); 921 msg.Append('\n');
979 msg.WriteToLogFile(); 922 msg.WriteToLogFile();
980 #endif
981 } 923 }
982 924
983 925
984 #ifdef ENABLE_LOGGING_AND_PROFILING
985 // ComputeMarker must only be used when SharedFunctionInfo is known. 926 // ComputeMarker must only be used when SharedFunctionInfo is known.
986 static const char* ComputeMarker(Code* code) { 927 static const char* ComputeMarker(Code* code) {
987 switch (code->kind()) { 928 switch (code->kind()) {
988 case Code::FUNCTION: return code->optimizable() ? "~" : ""; 929 case Code::FUNCTION: return code->optimizable() ? "~" : "";
989 case Code::OPTIMIZED_FUNCTION: return "*"; 930 case Code::OPTIMIZED_FUNCTION: return "*";
990 default: return ""; 931 default: return "";
991 } 932 }
992 } 933 }
993 #endif
994 934
995 935
996 void Logger::CodeCreateEvent(LogEventsAndTags tag, 936 void Logger::CodeCreateEvent(LogEventsAndTags tag,
997 Code* code, 937 Code* code,
998 SharedFunctionInfo* shared, 938 SharedFunctionInfo* shared,
999 String* name) { 939 String* name) {
1000 #ifdef ENABLE_LOGGING_AND_PROFILING
1001 if (!log_->IsEnabled()) return; 940 if (!log_->IsEnabled()) return;
1002 if (FLAG_ll_prof || Serializer::enabled()) { 941 if (FLAG_ll_prof || Serializer::enabled()) {
1003 name_buffer_->Reset(); 942 name_buffer_->Reset();
1004 name_buffer_->AppendBytes(kLogEventsNames[tag]); 943 name_buffer_->AppendBytes(kLogEventsNames[tag]);
1005 name_buffer_->AppendByte(':'); 944 name_buffer_->AppendByte(':');
1006 name_buffer_->AppendBytes(ComputeMarker(code)); 945 name_buffer_->AppendBytes(ComputeMarker(code));
1007 name_buffer_->AppendString(name); 946 name_buffer_->AppendString(name);
1008 } 947 }
1009 if (FLAG_ll_prof) { 948 if (FLAG_ll_prof) {
1010 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size()); 949 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
(...skipping 11 matching lines...) Expand all
1022 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 961 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1023 msg.Append("%s,%s,", 962 msg.Append("%s,%s,",
1024 kLogEventsNames[CODE_CREATION_EVENT], 963 kLogEventsNames[CODE_CREATION_EVENT],
1025 kLogEventsNames[tag]); 964 kLogEventsNames[tag]);
1026 msg.AppendAddress(code->address()); 965 msg.AppendAddress(code->address());
1027 msg.Append(",%d,\"%s\",", code->ExecutableSize(), *str); 966 msg.Append(",%d,\"%s\",", code->ExecutableSize(), *str);
1028 msg.AppendAddress(shared->address()); 967 msg.AppendAddress(shared->address());
1029 msg.Append(",%s", ComputeMarker(code)); 968 msg.Append(",%s", ComputeMarker(code));
1030 msg.Append('\n'); 969 msg.Append('\n');
1031 msg.WriteToLogFile(); 970 msg.WriteToLogFile();
1032 #endif
1033 } 971 }
1034 972
1035 973
1036 // Although, it is possible to extract source and line from 974 // Although, it is possible to extract source and line from
1037 // the SharedFunctionInfo object, we left it to caller 975 // the SharedFunctionInfo object, we left it to caller
1038 // to leave logging functions free from heap allocations. 976 // to leave logging functions free from heap allocations.
1039 void Logger::CodeCreateEvent(LogEventsAndTags tag, 977 void Logger::CodeCreateEvent(LogEventsAndTags tag,
1040 Code* code, 978 Code* code,
1041 SharedFunctionInfo* shared, 979 SharedFunctionInfo* shared,
1042 String* source, int line) { 980 String* source, int line) {
1043 #ifdef ENABLE_LOGGING_AND_PROFILING
1044 if (!log_->IsEnabled()) return; 981 if (!log_->IsEnabled()) return;
1045 if (FLAG_ll_prof || Serializer::enabled()) { 982 if (FLAG_ll_prof || Serializer::enabled()) {
1046 name_buffer_->Reset(); 983 name_buffer_->Reset();
1047 name_buffer_->AppendBytes(kLogEventsNames[tag]); 984 name_buffer_->AppendBytes(kLogEventsNames[tag]);
1048 name_buffer_->AppendByte(':'); 985 name_buffer_->AppendByte(':');
1049 name_buffer_->AppendBytes(ComputeMarker(code)); 986 name_buffer_->AppendBytes(ComputeMarker(code));
1050 name_buffer_->AppendString(shared->DebugName()); 987 name_buffer_->AppendString(shared->DebugName());
1051 name_buffer_->AppendByte(' '); 988 name_buffer_->AppendByte(' ');
1052 name_buffer_->AppendString(source); 989 name_buffer_->AppendString(source);
1053 name_buffer_->AppendByte(':'); 990 name_buffer_->AppendByte(':');
(...skipping 17 matching lines...) Expand all
1071 msg.AppendAddress(code->address()); 1008 msg.AppendAddress(code->address());
1072 msg.Append(",%d,\"%s %s:%d\",", 1009 msg.Append(",%d,\"%s %s:%d\",",
1073 code->ExecutableSize(), 1010 code->ExecutableSize(),
1074 *name, 1011 *name,
1075 *sourcestr, 1012 *sourcestr,
1076 line); 1013 line);
1077 msg.AppendAddress(shared->address()); 1014 msg.AppendAddress(shared->address());
1078 msg.Append(",%s", ComputeMarker(code)); 1015 msg.Append(",%s", ComputeMarker(code));
1079 msg.Append('\n'); 1016 msg.Append('\n');
1080 msg.WriteToLogFile(); 1017 msg.WriteToLogFile();
1081 #endif
1082 } 1018 }
1083 1019
1084 1020
1085 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count) { 1021 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count) {
1086 #ifdef ENABLE_LOGGING_AND_PROFILING
1087 if (!log_->IsEnabled()) return; 1022 if (!log_->IsEnabled()) return;
1088 if (FLAG_ll_prof || Serializer::enabled()) { 1023 if (FLAG_ll_prof || Serializer::enabled()) {
1089 name_buffer_->Reset(); 1024 name_buffer_->Reset();
1090 name_buffer_->AppendBytes(kLogEventsNames[tag]); 1025 name_buffer_->AppendBytes(kLogEventsNames[tag]);
1091 name_buffer_->AppendByte(':'); 1026 name_buffer_->AppendByte(':');
1092 name_buffer_->AppendInt(args_count); 1027 name_buffer_->AppendInt(args_count);
1093 } 1028 }
1094 if (FLAG_ll_prof) { 1029 if (FLAG_ll_prof) {
1095 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size()); 1030 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
1096 } 1031 }
1097 if (Serializer::enabled()) { 1032 if (Serializer::enabled()) {
1098 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size()); 1033 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
1099 } 1034 }
1100 if (!FLAG_log_code) return; 1035 if (!FLAG_log_code) return;
1101 LogMessageBuilder msg(this); 1036 LogMessageBuilder msg(this);
1102 msg.Append("%s,%s,", 1037 msg.Append("%s,%s,",
1103 kLogEventsNames[CODE_CREATION_EVENT], 1038 kLogEventsNames[CODE_CREATION_EVENT],
1104 kLogEventsNames[tag]); 1039 kLogEventsNames[tag]);
1105 msg.AppendAddress(code->address()); 1040 msg.AppendAddress(code->address());
1106 msg.Append(",%d,\"args_count: %d\"", code->ExecutableSize(), args_count); 1041 msg.Append(",%d,\"args_count: %d\"", code->ExecutableSize(), args_count);
1107 msg.Append('\n'); 1042 msg.Append('\n');
1108 msg.WriteToLogFile(); 1043 msg.WriteToLogFile();
1109 #endif
1110 } 1044 }
1111 1045
1112 1046
1113 void Logger::CodeMovingGCEvent() { 1047 void Logger::CodeMovingGCEvent() {
1114 #ifdef ENABLE_LOGGING_AND_PROFILING
1115 if (!log_->IsEnabled() || !FLAG_ll_prof) return; 1048 if (!log_->IsEnabled() || !FLAG_ll_prof) return;
1116 LowLevelLogWriteBytes(&kCodeMovingGCTag, sizeof(kCodeMovingGCTag)); 1049 LowLevelLogWriteBytes(&kCodeMovingGCTag, sizeof(kCodeMovingGCTag));
1117 OS::SignalCodeMovingGC(); 1050 OS::SignalCodeMovingGC();
1118 #endif
1119 } 1051 }
1120 1052
1121 1053
1122 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { 1054 void Logger::RegExpCodeCreateEvent(Code* code, String* source) {
1123 #ifdef ENABLE_LOGGING_AND_PROFILING
1124 if (!log_->IsEnabled()) return; 1055 if (!log_->IsEnabled()) return;
1125 if (FLAG_ll_prof || Serializer::enabled()) { 1056 if (FLAG_ll_prof || Serializer::enabled()) {
1126 name_buffer_->Reset(); 1057 name_buffer_->Reset();
1127 name_buffer_->AppendBytes(kLogEventsNames[REG_EXP_TAG]); 1058 name_buffer_->AppendBytes(kLogEventsNames[REG_EXP_TAG]);
1128 name_buffer_->AppendByte(':'); 1059 name_buffer_->AppendByte(':');
1129 name_buffer_->AppendString(source); 1060 name_buffer_->AppendString(source);
1130 } 1061 }
1131 if (FLAG_ll_prof) { 1062 if (FLAG_ll_prof) {
1132 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size()); 1063 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
1133 } 1064 }
1134 if (Serializer::enabled()) { 1065 if (Serializer::enabled()) {
1135 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size()); 1066 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
1136 } 1067 }
1137 if (!FLAG_log_code) return; 1068 if (!FLAG_log_code) return;
1138 LogMessageBuilder msg(this); 1069 LogMessageBuilder msg(this);
1139 msg.Append("%s,%s,", 1070 msg.Append("%s,%s,",
1140 kLogEventsNames[CODE_CREATION_EVENT], 1071 kLogEventsNames[CODE_CREATION_EVENT],
1141 kLogEventsNames[REG_EXP_TAG]); 1072 kLogEventsNames[REG_EXP_TAG]);
1142 msg.AppendAddress(code->address()); 1073 msg.AppendAddress(code->address());
1143 msg.Append(",%d,\"", code->ExecutableSize()); 1074 msg.Append(",%d,\"", code->ExecutableSize());
1144 msg.AppendDetailed(source, false); 1075 msg.AppendDetailed(source, false);
1145 msg.Append('\"'); 1076 msg.Append('\"');
1146 msg.Append('\n'); 1077 msg.Append('\n');
1147 msg.WriteToLogFile(); 1078 msg.WriteToLogFile();
1148 #endif
1149 } 1079 }
1150 1080
1151 1081
1152 void Logger::CodeMoveEvent(Address from, Address to) { 1082 void Logger::CodeMoveEvent(Address from, Address to) {
1153 #ifdef ENABLE_LOGGING_AND_PROFILING
1154 if (!log_->IsEnabled()) return; 1083 if (!log_->IsEnabled()) return;
1155 if (FLAG_ll_prof) LowLevelCodeMoveEvent(from, to); 1084 if (FLAG_ll_prof) LowLevelCodeMoveEvent(from, to);
1156 if (Serializer::enabled() && address_to_name_map_ != NULL) { 1085 if (Serializer::enabled() && address_to_name_map_ != NULL) {
1157 address_to_name_map_->Move(from, to); 1086 address_to_name_map_->Move(from, to);
1158 } 1087 }
1159 MoveEventInternal(CODE_MOVE_EVENT, from, to); 1088 MoveEventInternal(CODE_MOVE_EVENT, from, to);
1160 #endif
1161 } 1089 }
1162 1090
1163 1091
1164 void Logger::CodeDeleteEvent(Address from) { 1092 void Logger::CodeDeleteEvent(Address from) {
1165 #ifdef ENABLE_LOGGING_AND_PROFILING
1166 if (!log_->IsEnabled()) return; 1093 if (!log_->IsEnabled()) return;
1167 if (FLAG_ll_prof) LowLevelCodeDeleteEvent(from); 1094 if (FLAG_ll_prof) LowLevelCodeDeleteEvent(from);
1168 if (Serializer::enabled() && address_to_name_map_ != NULL) { 1095 if (Serializer::enabled() && address_to_name_map_ != NULL) {
1169 address_to_name_map_->Remove(from); 1096 address_to_name_map_->Remove(from);
1170 } 1097 }
1171 DeleteEventInternal(CODE_DELETE_EVENT, from); 1098 DeleteEventInternal(CODE_DELETE_EVENT, from);
1172 #endif
1173 } 1099 }
1174 1100
1175 1101
1176 void Logger::SnapshotPositionEvent(Address addr, int pos) { 1102 void Logger::SnapshotPositionEvent(Address addr, int pos) {
1177 #ifdef ENABLE_LOGGING_AND_PROFILING
1178 if (!log_->IsEnabled()) return; 1103 if (!log_->IsEnabled()) return;
1179 if (FLAG_ll_prof) LowLevelSnapshotPositionEvent(addr, pos); 1104 if (FLAG_ll_prof) LowLevelSnapshotPositionEvent(addr, pos);
1180 if (Serializer::enabled() && address_to_name_map_ != NULL) { 1105 if (Serializer::enabled() && address_to_name_map_ != NULL) {
1181 const char* code_name = address_to_name_map_->Lookup(addr); 1106 const char* code_name = address_to_name_map_->Lookup(addr);
1182 if (code_name == NULL) return; // Not a code object. 1107 if (code_name == NULL) return; // Not a code object.
1183 LogMessageBuilder msg(this); 1108 LogMessageBuilder msg(this);
1184 msg.Append("%s,%d,\"", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos); 1109 msg.Append("%s,%d,\"", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos);
1185 for (const char* p = code_name; *p != '\0'; ++p) { 1110 for (const char* p = code_name; *p != '\0'; ++p) {
1186 if (*p == '"') msg.Append('\\'); 1111 if (*p == '"') msg.Append('\\');
1187 msg.Append(*p); 1112 msg.Append(*p);
1188 } 1113 }
1189 msg.Append("\"\n"); 1114 msg.Append("\"\n");
1190 msg.WriteToLogFile(); 1115 msg.WriteToLogFile();
1191 } 1116 }
1192 if (!FLAG_log_snapshot_positions) return; 1117 if (!FLAG_log_snapshot_positions) return;
1193 LogMessageBuilder msg(this); 1118 LogMessageBuilder msg(this);
1194 msg.Append("%s,", kLogEventsNames[SNAPSHOT_POSITION_EVENT]); 1119 msg.Append("%s,", kLogEventsNames[SNAPSHOT_POSITION_EVENT]);
1195 msg.AppendAddress(addr); 1120 msg.AppendAddress(addr);
1196 msg.Append(",%d", pos); 1121 msg.Append(",%d", pos);
1197 msg.Append('\n'); 1122 msg.Append('\n');
1198 msg.WriteToLogFile(); 1123 msg.WriteToLogFile();
1199 #endif
1200 } 1124 }
1201 1125
1202 1126
1203 void Logger::SharedFunctionInfoMoveEvent(Address from, Address to) { 1127 void Logger::SharedFunctionInfoMoveEvent(Address from, Address to) {
1204 #ifdef ENABLE_LOGGING_AND_PROFILING
1205 MoveEventInternal(SHARED_FUNC_MOVE_EVENT, from, to); 1128 MoveEventInternal(SHARED_FUNC_MOVE_EVENT, from, to);
1206 #endif
1207 } 1129 }
1208 1130
1209 1131
1210 #ifdef ENABLE_LOGGING_AND_PROFILING
1211 void Logger::MoveEventInternal(LogEventsAndTags event, 1132 void Logger::MoveEventInternal(LogEventsAndTags event,
1212 Address from, 1133 Address from,
1213 Address to) { 1134 Address to) {
1214 if (!log_->IsEnabled() || !FLAG_log_code) return; 1135 if (!log_->IsEnabled() || !FLAG_log_code) return;
1215 LogMessageBuilder msg(this); 1136 LogMessageBuilder msg(this);
1216 msg.Append("%s,", kLogEventsNames[event]); 1137 msg.Append("%s,", kLogEventsNames[event]);
1217 msg.AppendAddress(from); 1138 msg.AppendAddress(from);
1218 msg.Append(','); 1139 msg.Append(',');
1219 msg.AppendAddress(to); 1140 msg.AppendAddress(to);
1220 msg.Append('\n'); 1141 msg.Append('\n');
1221 msg.WriteToLogFile(); 1142 msg.WriteToLogFile();
1222 } 1143 }
1223 #endif
1224 1144
1225 1145
1226 #ifdef ENABLE_LOGGING_AND_PROFILING
1227 void Logger::DeleteEventInternal(LogEventsAndTags event, Address from) { 1146 void Logger::DeleteEventInternal(LogEventsAndTags event, Address from) {
1228 if (!log_->IsEnabled() || !FLAG_log_code) return; 1147 if (!log_->IsEnabled() || !FLAG_log_code) return;
1229 LogMessageBuilder msg(this); 1148 LogMessageBuilder msg(this);
1230 msg.Append("%s,", kLogEventsNames[event]); 1149 msg.Append("%s,", kLogEventsNames[event]);
1231 msg.AppendAddress(from); 1150 msg.AppendAddress(from);
1232 msg.Append('\n'); 1151 msg.Append('\n');
1233 msg.WriteToLogFile(); 1152 msg.WriteToLogFile();
1234 } 1153 }
1235 #endif
1236 1154
1237 1155
1238 void Logger::ResourceEvent(const char* name, const char* tag) { 1156 void Logger::ResourceEvent(const char* name, const char* tag) {
1239 #ifdef ENABLE_LOGGING_AND_PROFILING
1240 if (!log_->IsEnabled() || !FLAG_log) return; 1157 if (!log_->IsEnabled() || !FLAG_log) return;
1241 LogMessageBuilder msg(this); 1158 LogMessageBuilder msg(this);
1242 msg.Append("%s,%s,", name, tag); 1159 msg.Append("%s,%s,", name, tag);
1243 1160
1244 uint32_t sec, usec; 1161 uint32_t sec, usec;
1245 if (OS::GetUserTime(&sec, &usec) != -1) { 1162 if (OS::GetUserTime(&sec, &usec) != -1) {
1246 msg.Append("%d,%d,", sec, usec); 1163 msg.Append("%d,%d,", sec, usec);
1247 } 1164 }
1248 msg.Append("%.0f", OS::TimeCurrentMillis()); 1165 msg.Append("%.0f", OS::TimeCurrentMillis());
1249 1166
1250 msg.Append('\n'); 1167 msg.Append('\n');
1251 msg.WriteToLogFile(); 1168 msg.WriteToLogFile();
1252 #endif
1253 } 1169 }
1254 1170
1255 1171
1256 void Logger::SuspectReadEvent(String* name, Object* obj) { 1172 void Logger::SuspectReadEvent(String* name, Object* obj) {
1257 #ifdef ENABLE_LOGGING_AND_PROFILING
1258 if (!log_->IsEnabled() || !FLAG_log_suspect) return; 1173 if (!log_->IsEnabled() || !FLAG_log_suspect) return;
1259 LogMessageBuilder msg(this); 1174 LogMessageBuilder msg(this);
1260 String* class_name = obj->IsJSObject() 1175 String* class_name = obj->IsJSObject()
1261 ? JSObject::cast(obj)->class_name() 1176 ? JSObject::cast(obj)->class_name()
1262 : HEAP->empty_string(); 1177 : HEAP->empty_string();
1263 msg.Append("suspect-read,"); 1178 msg.Append("suspect-read,");
1264 msg.Append(class_name); 1179 msg.Append(class_name);
1265 msg.Append(','); 1180 msg.Append(',');
1266 msg.Append('"'); 1181 msg.Append('"');
1267 msg.Append(name); 1182 msg.Append(name);
1268 msg.Append('"'); 1183 msg.Append('"');
1269 msg.Append('\n'); 1184 msg.Append('\n');
1270 msg.WriteToLogFile(); 1185 msg.WriteToLogFile();
1271 #endif
1272 } 1186 }
1273 1187
1274 1188
1275 void Logger::HeapSampleBeginEvent(const char* space, const char* kind) { 1189 void Logger::HeapSampleBeginEvent(const char* space, const char* kind) {
1276 #ifdef ENABLE_LOGGING_AND_PROFILING
1277 if (!log_->IsEnabled() || !FLAG_log_gc) return; 1190 if (!log_->IsEnabled() || !FLAG_log_gc) return;
1278 LogMessageBuilder msg(this); 1191 LogMessageBuilder msg(this);
1279 // Using non-relative system time in order to be able to synchronize with 1192 // Using non-relative system time in order to be able to synchronize with
1280 // external memory profiling events (e.g. DOM memory size). 1193 // external memory profiling events (e.g. DOM memory size).
1281 msg.Append("heap-sample-begin,\"%s\",\"%s\",%.0f\n", 1194 msg.Append("heap-sample-begin,\"%s\",\"%s\",%.0f\n",
1282 space, kind, OS::TimeCurrentMillis()); 1195 space, kind, OS::TimeCurrentMillis());
1283 msg.WriteToLogFile(); 1196 msg.WriteToLogFile();
1284 #endif
1285 } 1197 }
1286 1198
1287 1199
1288 void Logger::HeapSampleEndEvent(const char* space, const char* kind) { 1200 void Logger::HeapSampleEndEvent(const char* space, const char* kind) {
1289 #ifdef ENABLE_LOGGING_AND_PROFILING
1290 if (!log_->IsEnabled() || !FLAG_log_gc) return; 1201 if (!log_->IsEnabled() || !FLAG_log_gc) return;
1291 LogMessageBuilder msg(this); 1202 LogMessageBuilder msg(this);
1292 msg.Append("heap-sample-end,\"%s\",\"%s\"\n", space, kind); 1203 msg.Append("heap-sample-end,\"%s\",\"%s\"\n", space, kind);
1293 msg.WriteToLogFile(); 1204 msg.WriteToLogFile();
1294 #endif
1295 } 1205 }
1296 1206
1297 1207
1298 void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) { 1208 void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) {
1299 #ifdef ENABLE_LOGGING_AND_PROFILING
1300 if (!log_->IsEnabled() || !FLAG_log_gc) return; 1209 if (!log_->IsEnabled() || !FLAG_log_gc) return;
1301 LogMessageBuilder msg(this); 1210 LogMessageBuilder msg(this);
1302 msg.Append("heap-sample-item,%s,%d,%d\n", type, number, bytes); 1211 msg.Append("heap-sample-item,%s,%d,%d\n", type, number, bytes);
1303 msg.WriteToLogFile(); 1212 msg.WriteToLogFile();
1304 #endif
1305 } 1213 }
1306 1214
1307 1215
1308 void Logger::DebugTag(const char* call_site_tag) { 1216 void Logger::DebugTag(const char* call_site_tag) {
1309 #ifdef ENABLE_LOGGING_AND_PROFILING
1310 if (!log_->IsEnabled() || !FLAG_log) return; 1217 if (!log_->IsEnabled() || !FLAG_log) return;
1311 LogMessageBuilder msg(this); 1218 LogMessageBuilder msg(this);
1312 msg.Append("debug-tag,%s\n", call_site_tag); 1219 msg.Append("debug-tag,%s\n", call_site_tag);
1313 msg.WriteToLogFile(); 1220 msg.WriteToLogFile();
1314 #endif
1315 } 1221 }
1316 1222
1317 1223
1318 void Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) { 1224 void Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) {
1319 #ifdef ENABLE_LOGGING_AND_PROFILING
1320 if (!log_->IsEnabled() || !FLAG_log) return; 1225 if (!log_->IsEnabled() || !FLAG_log) return;
1321 StringBuilder s(parameter.length() + 1); 1226 StringBuilder s(parameter.length() + 1);
1322 for (int i = 0; i < parameter.length(); ++i) { 1227 for (int i = 0; i < parameter.length(); ++i) {
1323 s.AddCharacter(static_cast<char>(parameter[i])); 1228 s.AddCharacter(static_cast<char>(parameter[i]));
1324 } 1229 }
1325 char* parameter_string = s.Finalize(); 1230 char* parameter_string = s.Finalize();
1326 LogMessageBuilder msg(this); 1231 LogMessageBuilder msg(this);
1327 msg.Append("debug-queue-event,%s,%15.3f,%s\n", 1232 msg.Append("debug-queue-event,%s,%15.3f,%s\n",
1328 event_type, 1233 event_type,
1329 OS::TimeCurrentMillis(), 1234 OS::TimeCurrentMillis(),
1330 parameter_string); 1235 parameter_string);
1331 DeleteArray(parameter_string); 1236 DeleteArray(parameter_string);
1332 msg.WriteToLogFile(); 1237 msg.WriteToLogFile();
1333 #endif
1334 } 1238 }
1335 1239
1336 1240
1337 #ifdef ENABLE_LOGGING_AND_PROFILING
1338 void Logger::TickEvent(TickSample* sample, bool overflow) { 1241 void Logger::TickEvent(TickSample* sample, bool overflow) {
1339 if (!log_->IsEnabled() || !FLAG_prof) return; 1242 if (!log_->IsEnabled() || !FLAG_prof) return;
1340 LogMessageBuilder msg(this); 1243 LogMessageBuilder msg(this);
1341 msg.Append("%s,", kLogEventsNames[TICK_EVENT]); 1244 msg.Append("%s,", kLogEventsNames[TICK_EVENT]);
1342 msg.AppendAddress(sample->pc); 1245 msg.AppendAddress(sample->pc);
1343 msg.Append(','); 1246 msg.Append(',');
1344 msg.AppendAddress(sample->sp); 1247 msg.AppendAddress(sample->sp);
1345 if (sample->has_external_callback) { 1248 if (sample->has_external_callback) {
1346 msg.Append(",1,"); 1249 msg.Append(",1,");
1347 msg.AppendAddress(sample->external_callback); 1250 msg.AppendAddress(sample->external_callback);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 description = "A keyed call IC from the snapshot"; 1441 description = "A keyed call IC from the snapshot";
1539 tag = Logger::KEYED_CALL_IC_TAG; 1442 tag = Logger::KEYED_CALL_IC_TAG;
1540 break; 1443 break;
1541 } 1444 }
1542 PROFILE(ISOLATE, CodeCreateEvent(tag, code_object, description)); 1445 PROFILE(ISOLATE, CodeCreateEvent(tag, code_object, description));
1543 } 1446 }
1544 } 1447 }
1545 1448
1546 1449
1547 void Logger::LogCodeInfo() { 1450 void Logger::LogCodeInfo() {
1548 #ifdef ENABLE_LOGGING_AND_PROFILING
1549 if (!log_->IsEnabled() || !FLAG_ll_prof) return; 1451 if (!log_->IsEnabled() || !FLAG_ll_prof) return;
1550 #if V8_TARGET_ARCH_IA32 1452 #if V8_TARGET_ARCH_IA32
1551 const char arch[] = "ia32"; 1453 const char arch[] = "ia32";
1552 #elif V8_TARGET_ARCH_X64 1454 #elif V8_TARGET_ARCH_X64
1553 const char arch[] = "x64"; 1455 const char arch[] = "x64";
1554 #elif V8_TARGET_ARCH_ARM 1456 #elif V8_TARGET_ARCH_ARM
1555 const char arch[] = "arm"; 1457 const char arch[] = "arm";
1556 #else 1458 #else
1557 const char arch[] = "unknown"; 1459 const char arch[] = "unknown";
1558 #endif 1460 #endif
1559 LowLevelLogWriteBytes(arch, sizeof(arch)); 1461 LowLevelLogWriteBytes(arch, sizeof(arch));
1560 #endif // ENABLE_LOGGING_AND_PROFILING
1561 } 1462 }
1562 1463
1563 1464
1564 void Logger::RegisterSnapshotCodeName(Code* code, 1465 void Logger::RegisterSnapshotCodeName(Code* code,
1565 const char* name, 1466 const char* name,
1566 int name_size) { 1467 int name_size) {
1567 ASSERT(Serializer::enabled()); 1468 ASSERT(Serializer::enabled());
1568 if (address_to_name_map_ == NULL) { 1469 if (address_to_name_map_ == NULL) {
1569 address_to_name_map_ = new NameMap; 1470 address_to_name_map_ = new NameMap;
1570 } 1471 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 if (getter_entry != 0) { 1604 if (getter_entry != 0) {
1704 PROFILE(isolate, GetterCallbackEvent(name, getter_entry)); 1605 PROFILE(isolate, GetterCallbackEvent(name, getter_entry));
1705 } 1606 }
1706 Address setter_entry = v8::ToCData<Address>(ai->setter()); 1607 Address setter_entry = v8::ToCData<Address>(ai->setter());
1707 if (setter_entry != 0) { 1608 if (setter_entry != 0) {
1708 PROFILE(isolate, SetterCallbackEvent(name, setter_entry)); 1609 PROFILE(isolate, SetterCallbackEvent(name, setter_entry));
1709 } 1610 }
1710 } 1611 }
1711 } 1612 }
1712 1613
1713 #endif
1714
1715 1614
1716 bool Logger::Setup() { 1615 bool Logger::Setup() {
1717 #ifdef ENABLE_LOGGING_AND_PROFILING
1718 // Tests and EnsureInitialize() can call this twice in a row. It's harmless. 1616 // Tests and EnsureInitialize() can call this twice in a row. It's harmless.
1719 if (is_initialized_) return true; 1617 if (is_initialized_) return true;
1720 is_initialized_ = true; 1618 is_initialized_ = true;
1721 1619
1722 // --ll-prof implies --log-code and --log-snapshot-positions. 1620 // --ll-prof implies --log-code and --log-snapshot-positions.
1723 if (FLAG_ll_prof) { 1621 if (FLAG_ll_prof) {
1724 FLAG_log_snapshot_positions = true; 1622 FLAG_log_snapshot_positions = true;
1725 } 1623 }
1726 1624
1727 // --prof_lazy controls --log-code, implies --noprof_auto. 1625 // --prof_lazy controls --log-code, implies --noprof_auto.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 profiler_->pause(); 1657 profiler_->pause();
1760 } else { 1658 } else {
1761 logging_nesting_ = 1; 1659 logging_nesting_ = 1;
1762 } 1660 }
1763 if (!FLAG_prof_lazy) { 1661 if (!FLAG_prof_lazy) {
1764 profiler_->Engage(); 1662 profiler_->Engage();
1765 } 1663 }
1766 } 1664 }
1767 1665
1768 return true; 1666 return true;
1769
1770 #else
1771 return false;
1772 #endif
1773 } 1667 }
1774 1668
1775 1669
1776 Sampler* Logger::sampler() { 1670 Sampler* Logger::sampler() {
1777 #ifdef ENABLE_LOGGING_AND_PROFILING
1778 return ticker_; 1671 return ticker_;
1779 #else
1780 return NULL;
1781 #endif
1782 } 1672 }
1783 1673
1784 1674
1785 void Logger::EnsureTickerStarted() { 1675 void Logger::EnsureTickerStarted() {
1786 #ifdef ENABLE_LOGGING_AND_PROFILING
1787 ASSERT(ticker_ != NULL); 1676 ASSERT(ticker_ != NULL);
1788 if (!ticker_->IsActive()) ticker_->Start(); 1677 if (!ticker_->IsActive()) ticker_->Start();
1789 #endif
1790 } 1678 }
1791 1679
1792 1680
1793 void Logger::EnsureTickerStopped() { 1681 void Logger::EnsureTickerStopped() {
1794 #ifdef ENABLE_LOGGING_AND_PROFILING
1795 if (ticker_ != NULL && ticker_->IsActive()) ticker_->Stop(); 1682 if (ticker_ != NULL && ticker_->IsActive()) ticker_->Stop();
1796 #endif
1797 } 1683 }
1798 1684
1799 1685
1800 void Logger::TearDown() { 1686 void Logger::TearDown() {
1801 #ifdef ENABLE_LOGGING_AND_PROFILING
1802 if (!is_initialized_) return; 1687 if (!is_initialized_) return;
1803 is_initialized_ = false; 1688 is_initialized_ = false;
1804 1689
1805 // Stop the profiler before closing the file. 1690 // Stop the profiler before closing the file.
1806 if (profiler_ != NULL) { 1691 if (profiler_ != NULL) {
1807 profiler_->Disengage(); 1692 profiler_->Disengage();
1808 delete profiler_; 1693 delete profiler_;
1809 profiler_ = NULL; 1694 profiler_ = NULL;
1810 } 1695 }
1811 1696
1812 delete sliding_state_window_; 1697 delete sliding_state_window_;
1813 sliding_state_window_ = NULL; 1698 sliding_state_window_ = NULL;
1814 1699
1815 delete ticker_; 1700 delete ticker_;
1816 ticker_ = NULL; 1701 ticker_ = NULL;
1817 1702
1818 log_->Close(); 1703 log_->Close();
1819 #endif
1820 } 1704 }
1821 1705
1822 1706
1823 void Logger::EnableSlidingStateWindow() { 1707 void Logger::EnableSlidingStateWindow() {
1824 #ifdef ENABLE_LOGGING_AND_PROFILING
1825 // If the ticker is NULL, Logger::Setup has not been called yet. In 1708 // If the ticker is NULL, Logger::Setup has not been called yet. In
1826 // that case, we set the sliding_state_window flag so that the 1709 // that case, we set the sliding_state_window flag so that the
1827 // sliding window computation will be started when Logger::Setup is 1710 // sliding window computation will be started when Logger::Setup is
1828 // called. 1711 // called.
1829 if (ticker_ == NULL) { 1712 if (ticker_ == NULL) {
1830 FLAG_sliding_state_window = true; 1713 FLAG_sliding_state_window = true;
1831 return; 1714 return;
1832 } 1715 }
1833 // Otherwise, if the sliding state window computation has not been 1716 // Otherwise, if the sliding state window computation has not been
1834 // started we do it now. 1717 // started we do it now.
1835 if (sliding_state_window_ == NULL) { 1718 if (sliding_state_window_ == NULL) {
1836 sliding_state_window_ = new SlidingStateWindow(Isolate::Current()); 1719 sliding_state_window_ = new SlidingStateWindow(Isolate::Current());
1837 } 1720 }
1838 #endif
1839 } 1721 }
1840 1722
1841 1723
1842 Mutex* SamplerRegistry::mutex_ = OS::CreateMutex(); 1724 Mutex* SamplerRegistry::mutex_ = OS::CreateMutex();
1843 List<Sampler*>* SamplerRegistry::active_samplers_ = NULL; 1725 List<Sampler*>* SamplerRegistry::active_samplers_ = NULL;
1844 1726
1845 1727
1846 bool SamplerRegistry::IterateActiveSamplers(VisitSampler func, void* param) { 1728 bool SamplerRegistry::IterateActiveSamplers(VisitSampler func, void* param) {
1847 ScopedLock lock(mutex_); 1729 ScopedLock lock(mutex_);
1848 for (int i = 0; 1730 for (int i = 0;
1849 ActiveSamplersExist() && i < active_samplers_->length(); 1731 ActiveSamplersExist() && i < active_samplers_->length();
1850 ++i) { 1732 ++i) {
1851 func(active_samplers_->at(i), param); 1733 func(active_samplers_->at(i), param);
1852 } 1734 }
1853 return ActiveSamplersExist(); 1735 return ActiveSamplersExist();
1854 } 1736 }
1855 1737
1856 1738
1857 static void ComputeCpuProfiling(Sampler* sampler, void* flag_ptr) { 1739 static void ComputeCpuProfiling(Sampler* sampler, void* flag_ptr) {
1858 #ifdef ENABLE_LOGGING_AND_PROFILING
1859 bool* flag = reinterpret_cast<bool*>(flag_ptr); 1740 bool* flag = reinterpret_cast<bool*>(flag_ptr);
1860 *flag |= sampler->IsProfiling(); 1741 *flag |= sampler->IsProfiling();
1861 #endif
1862 } 1742 }
1863 1743
1864 1744
1865 SamplerRegistry::State SamplerRegistry::GetState() { 1745 SamplerRegistry::State SamplerRegistry::GetState() {
1866 bool flag = false; 1746 bool flag = false;
1867 if (!IterateActiveSamplers(&ComputeCpuProfiling, &flag)) { 1747 if (!IterateActiveSamplers(&ComputeCpuProfiling, &flag)) {
1868 return HAS_NO_SAMPLERS; 1748 return HAS_NO_SAMPLERS;
1869 } 1749 }
1870 return flag ? HAS_CPU_PROFILING_SAMPLERS : HAS_SAMPLERS; 1750 return flag ? HAS_CPU_PROFILING_SAMPLERS : HAS_SAMPLERS;
1871 } 1751 }
(...skipping 14 matching lines...) Expand all
1886 void SamplerRegistry::RemoveActiveSampler(Sampler* sampler) { 1766 void SamplerRegistry::RemoveActiveSampler(Sampler* sampler) {
1887 ASSERT(sampler->IsActive()); 1767 ASSERT(sampler->IsActive());
1888 ScopedLock lock(mutex_); 1768 ScopedLock lock(mutex_);
1889 ASSERT(active_samplers_ != NULL); 1769 ASSERT(active_samplers_ != NULL);
1890 bool removed = active_samplers_->RemoveElement(sampler); 1770 bool removed = active_samplers_->RemoveElement(sampler);
1891 ASSERT(removed); 1771 ASSERT(removed);
1892 USE(removed); 1772 USE(removed);
1893 } 1773 }
1894 1774
1895 } } // namespace v8::internal 1775 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/log.h ('k') | src/log-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698