OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 sample->frames_count = i; | 157 sample->frames_count = i; |
158 } | 158 } |
159 | 159 |
160 | 160 |
161 // | 161 // |
162 // Ticker used to provide ticks to the profiler and the sliding state | 162 // Ticker used to provide ticks to the profiler and the sliding state |
163 // window. | 163 // window. |
164 // | 164 // |
165 class Ticker: public Sampler { | 165 class Ticker: public Sampler { |
166 public: | 166 public: |
167 explicit Ticker(int interval, unsigned int low_stack_bound): | 167 explicit Ticker(int interval, uintptr_t low_stack_bound): |
168 Sampler(interval, FLAG_prof), window_(NULL), profiler_(NULL), | 168 Sampler(interval, FLAG_prof), window_(NULL), profiler_(NULL), |
169 stack_tracer_(low_stack_bound) {} | 169 stack_tracer_(low_stack_bound) {} |
170 | 170 |
171 ~Ticker() { if (IsActive()) Stop(); } | 171 ~Ticker() { if (IsActive()) Stop(); } |
172 | 172 |
173 void Tick(TickSample* sample) { | 173 void Tick(TickSample* sample) { |
174 if (IsProfiling()) stack_tracer_.Trace(sample); | 174 if (IsProfiling()) stack_tracer_.Trace(sample); |
175 if (profiler_) profiler_->Insert(sample); | 175 if (profiler_) profiler_->Insert(sample); |
176 if (window_) window_->AddState(sample->state); | 176 if (window_) window_->AddState(sample->state); |
177 } | 177 } |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 msg.Append("%s,%d\n", name, value); | 623 msg.Append("%s,%d\n", name, value); |
624 msg.WriteToLogFile(); | 624 msg.WriteToLogFile(); |
625 #endif | 625 #endif |
626 } | 626 } |
627 | 627 |
628 | 628 |
629 void Logger::HandleEvent(const char* name, Object** location) { | 629 void Logger::HandleEvent(const char* name, Object** location) { |
630 #ifdef ENABLE_LOGGING_AND_PROFILING | 630 #ifdef ENABLE_LOGGING_AND_PROFILING |
631 if (!Log::is_enabled() || !FLAG_log_handles) return; | 631 if (!Log::is_enabled() || !FLAG_log_handles) return; |
632 LogMessageBuilder msg; | 632 LogMessageBuilder msg; |
633 msg.Append("%s,0x%x\n", name, | 633 msg.Append("%s,0x%%"V8PRIp"\n", name, location); |
634 reinterpret_cast<unsigned int>(location)); | |
635 msg.WriteToLogFile(); | 634 msg.WriteToLogFile(); |
636 #endif | 635 #endif |
637 } | 636 } |
638 | 637 |
639 | 638 |
640 #ifdef ENABLE_LOGGING_AND_PROFILING | 639 #ifdef ENABLE_LOGGING_AND_PROFILING |
641 // ApiEvent is private so all the calls come from the Logger class. It is the | 640 // ApiEvent is private so all the calls come from the Logger class. It is the |
642 // caller's responsibility to ensure that log is enabled and that | 641 // caller's responsibility to ensure that log is enabled and that |
643 // FLAG_log_api is true. | 642 // FLAG_log_api is true. |
644 void Logger::ApiEvent(const char* format, ...) { | 643 void Logger::ApiEvent(const char* format, ...) { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 if (!Log::is_enabled() || !FLAG_log_api) return; | 842 if (!Log::is_enabled() || !FLAG_log_api) return; |
844 Logger::ApiEvent("api,%s\n", name); | 843 Logger::ApiEvent("api,%s\n", name); |
845 #endif | 844 #endif |
846 } | 845 } |
847 | 846 |
848 | 847 |
849 void Logger::NewEvent(const char* name, void* object, size_t size) { | 848 void Logger::NewEvent(const char* name, void* object, size_t size) { |
850 #ifdef ENABLE_LOGGING_AND_PROFILING | 849 #ifdef ENABLE_LOGGING_AND_PROFILING |
851 if (!Log::is_enabled() || !FLAG_log) return; | 850 if (!Log::is_enabled() || !FLAG_log) return; |
852 LogMessageBuilder msg; | 851 LogMessageBuilder msg; |
853 msg.Append("new,%s,0x%x,%u\n", name, | 852 msg.Append("new,%s,0x%%"V8PRIp",%u\n", name, object, |
854 reinterpret_cast<unsigned int>(object), | |
855 static_cast<unsigned int>(size)); | 853 static_cast<unsigned int>(size)); |
856 msg.WriteToLogFile(); | 854 msg.WriteToLogFile(); |
857 #endif | 855 #endif |
858 } | 856 } |
859 | 857 |
860 | 858 |
861 void Logger::DeleteEvent(const char* name, void* object) { | 859 void Logger::DeleteEvent(const char* name, void* object) { |
862 #ifdef ENABLE_LOGGING_AND_PROFILING | 860 #ifdef ENABLE_LOGGING_AND_PROFILING |
863 if (!Log::is_enabled() || !FLAG_log) return; | 861 if (!Log::is_enabled() || !FLAG_log) return; |
864 LogMessageBuilder msg; | 862 LogMessageBuilder msg; |
865 msg.Append("delete,%s,0x%x\n", name, | 863 msg.Append("delete,%s,0x%%"V8PRIp"\n", name, object); |
866 reinterpret_cast<unsigned int>(object)); | |
867 msg.WriteToLogFile(); | 864 msg.WriteToLogFile(); |
868 #endif | 865 #endif |
869 } | 866 } |
870 | 867 |
871 | 868 |
872 void Logger::CodeCreateEvent(const char* tag, Code* code, const char* comment) { | 869 void Logger::CodeCreateEvent(const char* tag, Code* code, const char* comment) { |
873 #ifdef ENABLE_LOGGING_AND_PROFILING | 870 #ifdef ENABLE_LOGGING_AND_PROFILING |
874 if (!Log::is_enabled() || !FLAG_log_code) return; | 871 if (!Log::is_enabled() || !FLAG_log_code) return; |
875 LogMessageBuilder msg; | 872 LogMessageBuilder msg; |
876 msg.Append("code-creation,%s,0x%x,%d,\"", tag, | 873 msg.Append("code-creation,%s,0x%"V8PRIp",%d,\"", tag, code->address(), |
877 reinterpret_cast<unsigned int>(code->address()), | |
878 code->ExecutableSize()); | 874 code->ExecutableSize()); |
879 for (const char* p = comment; *p != '\0'; p++) { | 875 for (const char* p = comment; *p != '\0'; p++) { |
880 if (*p == '"') { | 876 if (*p == '"') { |
881 msg.Append('\\'); | 877 msg.Append('\\'); |
882 } | 878 } |
883 msg.Append(*p); | 879 msg.Append(*p); |
884 } | 880 } |
885 msg.Append('"'); | 881 msg.Append('"'); |
886 msg.Append('\n'); | 882 msg.Append('\n'); |
887 msg.WriteToLogFile(); | 883 msg.WriteToLogFile(); |
888 #endif | 884 #endif |
889 } | 885 } |
890 | 886 |
891 | 887 |
892 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name) { | 888 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name) { |
893 #ifdef ENABLE_LOGGING_AND_PROFILING | 889 #ifdef ENABLE_LOGGING_AND_PROFILING |
894 if (!Log::is_enabled() || !FLAG_log_code) return; | 890 if (!Log::is_enabled() || !FLAG_log_code) return; |
895 LogMessageBuilder msg; | 891 LogMessageBuilder msg; |
896 SmartPointer<char> str = | 892 SmartPointer<char> str = |
897 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 893 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
898 msg.Append("code-creation,%s,0x%x,%d,\"%s\"\n", tag, | 894 msg.Append("code-creation,%s,0x%"V8PRIp",%d,\"%s\"\n", tag, code->address(), |
899 reinterpret_cast<unsigned int>(code->address()), | |
900 code->ExecutableSize(), *str); | 895 code->ExecutableSize(), *str); |
901 msg.WriteToLogFile(); | 896 msg.WriteToLogFile(); |
902 #endif | 897 #endif |
903 } | 898 } |
904 | 899 |
905 | 900 |
906 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name, | 901 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name, |
907 String* source, int line) { | 902 String* source, int line) { |
908 #ifdef ENABLE_LOGGING_AND_PROFILING | 903 #ifdef ENABLE_LOGGING_AND_PROFILING |
909 if (!Log::is_enabled() || !FLAG_log_code) return; | 904 if (!Log::is_enabled() || !FLAG_log_code) return; |
910 LogMessageBuilder msg; | 905 LogMessageBuilder msg; |
911 SmartPointer<char> str = | 906 SmartPointer<char> str = |
912 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 907 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
913 SmartPointer<char> sourcestr = | 908 SmartPointer<char> sourcestr = |
914 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 909 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
915 msg.Append("code-creation,%s,0x%x,%d,\"%s %s:%d\"\n", tag, | 910 msg.Append("code-creation,%s,0x%"V8PRIp",%d,\"%s %s:%d\"\n", tag, code->addres
s(), |
916 reinterpret_cast<unsigned int>(code->address()), | |
917 code->ExecutableSize(), | 911 code->ExecutableSize(), |
918 *str, *sourcestr, line); | 912 *str, *sourcestr, line); |
919 msg.WriteToLogFile(); | 913 msg.WriteToLogFile(); |
920 #endif | 914 #endif |
921 } | 915 } |
922 | 916 |
923 | 917 |
924 void Logger::CodeCreateEvent(const char* tag, Code* code, int args_count) { | 918 void Logger::CodeCreateEvent(const char* tag, Code* code, int args_count) { |
925 #ifdef ENABLE_LOGGING_AND_PROFILING | 919 #ifdef ENABLE_LOGGING_AND_PROFILING |
926 if (!Log::is_enabled() || !FLAG_log_code) return; | 920 if (!Log::is_enabled() || !FLAG_log_code) return; |
927 LogMessageBuilder msg; | 921 LogMessageBuilder msg; |
928 msg.Append("code-creation,%s,0x%x,%d,\"args_count: %d\"\n", tag, | 922 msg.Append("code-creation,%s,0x%"V8PRIp",%d,\"args_count: %d\"\n", tag, |
929 reinterpret_cast<unsigned int>(code->address()), | 923 code->address(), |
930 code->ExecutableSize(), | 924 code->ExecutableSize(), |
931 args_count); | 925 args_count); |
932 msg.WriteToLogFile(); | 926 msg.WriteToLogFile(); |
933 #endif | 927 #endif |
934 } | 928 } |
935 | 929 |
936 | 930 |
937 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { | 931 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { |
938 #ifdef ENABLE_LOGGING_AND_PROFILING | 932 #ifdef ENABLE_LOGGING_AND_PROFILING |
939 if (!Log::is_enabled() || !FLAG_log_code) return; | 933 if (!Log::is_enabled() || !FLAG_log_code) return; |
940 LogMessageBuilder msg; | 934 LogMessageBuilder msg; |
941 msg.Append("code-creation,%s,0x%x,%d,\"", "RegExp", | 935 msg.Append("code-creation,%s,0x%"V8PRIp",%d,\"", "RegExp", |
942 reinterpret_cast<unsigned int>(code->address()), | 936 code->address(), |
943 code->ExecutableSize()); | 937 code->ExecutableSize()); |
944 msg.AppendDetailed(source, false); | 938 msg.AppendDetailed(source, false); |
945 msg.Append("\"\n"); | 939 msg.Append("\"\n"); |
946 msg.WriteToLogFile(); | 940 msg.WriteToLogFile(); |
947 #endif | 941 #endif |
948 } | 942 } |
949 | 943 |
950 | 944 |
951 void Logger::CodeAllocateEvent(Code* code, Assembler* assem) { | 945 void Logger::CodeAllocateEvent(Code* code, Assembler* assem) { |
952 #ifdef ENABLE_LOGGING_AND_PROFILING | 946 #ifdef ENABLE_LOGGING_AND_PROFILING |
953 if (!Log::is_enabled() || !FLAG_log_code) return; | 947 if (!Log::is_enabled() || !FLAG_log_code) return; |
954 LogMessageBuilder msg; | 948 LogMessageBuilder msg; |
955 msg.Append("code-allocate,0x%x,0x%x\n", | 949 msg.Append("code-allocate,0x%"V8PRIp",0x%"V8PRIp"\n", code->address(), assem); |
956 reinterpret_cast<unsigned int>(code->address()), | |
957 reinterpret_cast<unsigned int>(assem)); | |
958 msg.WriteToLogFile(); | 950 msg.WriteToLogFile(); |
959 #endif | 951 #endif |
960 } | 952 } |
961 | 953 |
962 | 954 |
963 void Logger::CodeMoveEvent(Address from, Address to) { | 955 void Logger::CodeMoveEvent(Address from, Address to) { |
964 #ifdef ENABLE_LOGGING_AND_PROFILING | 956 #ifdef ENABLE_LOGGING_AND_PROFILING |
965 if (!Log::is_enabled() || !FLAG_log_code) return; | 957 if (!Log::is_enabled() || !FLAG_log_code) return; |
966 LogMessageBuilder msg; | 958 LogMessageBuilder msg; |
967 msg.Append("code-move,0x%x,0x%x\n", | 959 msg.Append("code-move,0x%"V8PRIp",0x%"V8PRIp"\n", from, to); |
968 reinterpret_cast<unsigned int>(from), | |
969 reinterpret_cast<unsigned int>(to)); | |
970 msg.WriteToLogFile(); | 960 msg.WriteToLogFile(); |
971 #endif | 961 #endif |
972 } | 962 } |
973 | 963 |
974 | 964 |
975 void Logger::CodeDeleteEvent(Address from) { | 965 void Logger::CodeDeleteEvent(Address from) { |
976 #ifdef ENABLE_LOGGING_AND_PROFILING | 966 #ifdef ENABLE_LOGGING_AND_PROFILING |
977 if (!Log::is_enabled() || !FLAG_log_code) return; | 967 if (!Log::is_enabled() || !FLAG_log_code) return; |
978 LogMessageBuilder msg; | 968 LogMessageBuilder msg; |
979 msg.Append("code-delete,0x%x\n", reinterpret_cast<unsigned int>(from)); | 969 msg.Append("code-delete,0x%"V8PRIp"\n", from); |
980 msg.WriteToLogFile(); | 970 msg.WriteToLogFile(); |
981 #endif | 971 #endif |
982 } | 972 } |
983 | 973 |
984 | 974 |
985 void Logger::ResourceEvent(const char* name, const char* tag) { | 975 void Logger::ResourceEvent(const char* name, const char* tag) { |
986 #ifdef ENABLE_LOGGING_AND_PROFILING | 976 #ifdef ENABLE_LOGGING_AND_PROFILING |
987 if (!Log::is_enabled() || !FLAG_log) return; | 977 if (!Log::is_enabled() || !FLAG_log) return; |
988 LogMessageBuilder msg; | 978 LogMessageBuilder msg; |
989 msg.Append("%s,%s,", name, tag); | 979 msg.Append("%s,%s,", name, tag); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 #ifdef ENABLE_LOGGING_AND_PROFILING | 1071 #ifdef ENABLE_LOGGING_AND_PROFILING |
1082 void Logger::TickEvent(TickSample* sample, bool overflow) { | 1072 void Logger::TickEvent(TickSample* sample, bool overflow) { |
1083 if (!Log::is_enabled() || !FLAG_prof) return; | 1073 if (!Log::is_enabled() || !FLAG_prof) return; |
1084 LogMessageBuilder msg; | 1074 LogMessageBuilder msg; |
1085 msg.Append("tick,0x%x,0x%x,%d", sample->pc, sample->sp, | 1075 msg.Append("tick,0x%x,0x%x,%d", sample->pc, sample->sp, |
1086 static_cast<int>(sample->state)); | 1076 static_cast<int>(sample->state)); |
1087 if (overflow) { | 1077 if (overflow) { |
1088 msg.Append(",overflow"); | 1078 msg.Append(",overflow"); |
1089 } | 1079 } |
1090 for (int i = 0; i < sample->frames_count; ++i) { | 1080 for (int i = 0; i < sample->frames_count; ++i) { |
1091 msg.Append(",0x%x", reinterpret_cast<uint32_t>(sample->stack[i])); | 1081 msg.Append(",0x%"V8PRIp, sample->stack[i]); |
1092 } | 1082 } |
1093 msg.Append('\n'); | 1083 msg.Append('\n'); |
1094 msg.WriteToLogFile(); | 1084 msg.WriteToLogFile(); |
1095 } | 1085 } |
1096 | 1086 |
1097 | 1087 |
1098 bool Logger::IsProfilerPaused() { | 1088 bool Logger::IsProfilerPaused() { |
1099 return profiler_->paused(); | 1089 return profiler_->paused(); |
1100 } | 1090 } |
1101 | 1091 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 } else { | 1172 } else { |
1183 Log::OpenFile(FLAG_logfile); | 1173 Log::OpenFile(FLAG_logfile); |
1184 } | 1174 } |
1185 } | 1175 } |
1186 | 1176 |
1187 current_state_ = &bottom_state_; | 1177 current_state_ = &bottom_state_; |
1188 | 1178 |
1189 // as log is initialized early with V8, we can assume that JS execution | 1179 // as log is initialized early with V8, we can assume that JS execution |
1190 // frames can never reach this point on stack | 1180 // frames can never reach this point on stack |
1191 int stack_var; | 1181 int stack_var; |
1192 ticker_ = new Ticker(1, reinterpret_cast<unsigned int>(&stack_var)); | 1182 ticker_ = new Ticker(1, reinterpret_cast<uintptr_t>(&stack_var)); |
1193 | 1183 |
1194 if (FLAG_sliding_state_window && sliding_state_window_ == NULL) { | 1184 if (FLAG_sliding_state_window && sliding_state_window_ == NULL) { |
1195 sliding_state_window_ = new SlidingStateWindow(); | 1185 sliding_state_window_ = new SlidingStateWindow(); |
1196 } | 1186 } |
1197 | 1187 |
1198 if (FLAG_prof) { | 1188 if (FLAG_prof) { |
1199 profiler_ = new Profiler(); | 1189 profiler_ = new Profiler(); |
1200 if (!FLAG_prof_auto) | 1190 if (!FLAG_prof_auto) |
1201 profiler_->pause(); | 1191 profiler_->pause(); |
1202 profiler_->Engage(); | 1192 profiler_->Engage(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 } else if (previous_->state_ == EXTERNAL) { | 1312 } else if (previous_->state_ == EXTERNAL) { |
1323 // We are leaving V8. | 1313 // We are leaving V8. |
1324 Heap::Protect(); | 1314 Heap::Protect(); |
1325 } | 1315 } |
1326 } | 1316 } |
1327 #endif | 1317 #endif |
1328 } | 1318 } |
1329 #endif | 1319 #endif |
1330 | 1320 |
1331 } } // namespace v8::internal | 1321 } } // namespace v8::internal |
OLD | NEW |