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

Side by Side Diff: src/log.cc

Issue 10837021: add ETW for V8 symbols
Patch Set: Created 8 years, 4 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
« no previous file with comments | « src/log.h ('k') | no next file » | 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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 logging_nesting_(0), 523 logging_nesting_(0),
524 cpu_profiler_nesting_(0), 524 cpu_profiler_nesting_(0),
525 log_(new Log(this)), 525 log_(new Log(this)),
526 name_buffer_(new NameBuffer), 526 name_buffer_(new NameBuffer),
527 address_to_name_map_(NULL), 527 address_to_name_map_(NULL),
528 is_initialized_(false), 528 is_initialized_(false),
529 last_address_(NULL), 529 last_address_(NULL),
530 prev_sp_(NULL), 530 prev_sp_(NULL),
531 prev_function_(NULL), 531 prev_function_(NULL),
532 prev_to_(NULL), 532 prev_to_(NULL),
533 prev_code_(NULL) { 533 prev_code_(NULL),
534 notified_reset_(0) {
534 } 535 }
535 536
536 537
537 Logger::~Logger() { 538 Logger::~Logger() {
538 delete address_to_name_map_; 539 delete address_to_name_map_;
539 delete name_buffer_; 540 delete name_buffer_;
540 delete log_; 541 delete log_;
541 } 542 }
542 543
543 544
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 case Code::OPTIMIZED_FUNCTION: return "*"; 934 case Code::OPTIMIZED_FUNCTION: return "*";
934 default: return ""; 935 default: return "";
935 } 936 }
936 } 937 }
937 938
938 939
939 void Logger::CodeCreateEvent(LogEventsAndTags tag, 940 void Logger::CodeCreateEvent(LogEventsAndTags tag,
940 Code* code, 941 Code* code,
941 SharedFunctionInfo* shared, 942 SharedFunctionInfo* shared,
942 String* name) { 943 String* name) {
943 if (!log_->IsEnabled()) return; 944 if (!log_->IsEnabled() && !CodeAddressNotification::IsEnabled()) return;
944 if (FLAG_ll_prof || Serializer::enabled()) { 945 if (FLAG_ll_prof || Serializer::enabled()) {
945 name_buffer_->Reset(); 946 name_buffer_->Reset();
946 name_buffer_->AppendBytes(kLogEventsNames[tag]); 947 name_buffer_->AppendBytes(kLogEventsNames[tag]);
947 name_buffer_->AppendByte(':'); 948 name_buffer_->AppendByte(':');
948 name_buffer_->AppendBytes(ComputeMarker(code)); 949 name_buffer_->AppendBytes(ComputeMarker(code));
949 name_buffer_->AppendString(name); 950 name_buffer_->AppendString(name);
950 } 951 }
951 if (FLAG_ll_prof) { 952 if (FLAG_ll_prof) {
952 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size()); 953 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
953 } 954 }
954 if (Serializer::enabled()) { 955 if (Serializer::enabled()) {
955 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size()); 956 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
956 } 957 }
958 if (CodeAddressNotification::IsEnabled()) {
959 name_buffer_->Reset();
960 name_buffer_->AppendString(name);
961 name_buffer_->AppendByte('\0');
962 CodeAddressNotification::WriteSymbolMap(this,
963 Add,
964 code->instruction_start(),
965 code->instruction_size(),
966 name_buffer_->get(),
967 tag,
968 shared->script(),
969 0);
970 }
957 if (!FLAG_log_code) return; 971 if (!FLAG_log_code) return;
958 if (code == Isolate::Current()->builtins()->builtin( 972 if (code == Isolate::Current()->builtins()->builtin(
959 Builtins::kLazyCompile)) 973 Builtins::kLazyCompile))
960 return; 974 return;
961 975
962 LogMessageBuilder msg(this); 976 LogMessageBuilder msg(this);
963 SmartArrayPointer<char> str = 977 SmartArrayPointer<char> str =
964 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 978 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
965 msg.Append("%s,%s,", 979 msg.Append("%s,%s,",
966 kLogEventsNames[CODE_CREATION_EVENT], 980 kLogEventsNames[CODE_CREATION_EVENT],
967 kLogEventsNames[tag]); 981 kLogEventsNames[tag]);
968 msg.AppendAddress(code->address()); 982 msg.AppendAddress(code->address());
969 msg.Append(",%d,\"%s\",", code->ExecutableSize(), *str); 983 msg.Append(",%d,\"%s\",", code->ExecutableSize(), *str);
970 msg.AppendAddress(shared->address()); 984 msg.AppendAddress(shared->address());
971 msg.Append(",%s", ComputeMarker(code)); 985 msg.Append(",%s", ComputeMarker(code));
972 msg.Append('\n'); 986 msg.Append('\n');
973 msg.WriteToLogFile(); 987 msg.WriteToLogFile();
974 } 988 }
975 989
976 990
977 // Although, it is possible to extract source and line from 991 // Although, it is possible to extract source and line from
978 // the SharedFunctionInfo object, we left it to caller 992 // the SharedFunctionInfo object, we left it to caller
979 // to leave logging functions free from heap allocations. 993 // to leave logging functions free from heap allocations.
980 void Logger::CodeCreateEvent(LogEventsAndTags tag, 994 void Logger::CodeCreateEvent(LogEventsAndTags tag,
981 Code* code, 995 Code* code,
982 SharedFunctionInfo* shared, 996 SharedFunctionInfo* shared,
983 String* source, int line) { 997 String* source, int line) {
984 if (!log_->IsEnabled()) return; 998 if (!log_->IsEnabled() && !CodeAddressNotification::IsEnabled()) return;
985 if (FLAG_ll_prof || Serializer::enabled()) { 999 if (FLAG_ll_prof || Serializer::enabled()) {
986 name_buffer_->Reset(); 1000 name_buffer_->Reset();
987 name_buffer_->AppendBytes(kLogEventsNames[tag]); 1001 name_buffer_->AppendBytes(kLogEventsNames[tag]);
988 name_buffer_->AppendByte(':'); 1002 name_buffer_->AppendByte(':');
989 name_buffer_->AppendBytes(ComputeMarker(code)); 1003 name_buffer_->AppendBytes(ComputeMarker(code));
990 name_buffer_->AppendString(shared->DebugName()); 1004 name_buffer_->AppendString(shared->DebugName());
991 name_buffer_->AppendByte(' '); 1005 name_buffer_->AppendByte(' ');
992 name_buffer_->AppendString(source); 1006 name_buffer_->AppendString(source);
993 name_buffer_->AppendByte(':'); 1007 name_buffer_->AppendByte(':');
994 name_buffer_->AppendInt(line); 1008 name_buffer_->AppendInt(line);
995 } 1009 }
996 if (FLAG_ll_prof) { 1010 if (FLAG_ll_prof) {
997 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size()); 1011 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
998 } 1012 }
999 if (Serializer::enabled()) { 1013 if (Serializer::enabled()) {
1000 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size()); 1014 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
1001 } 1015 }
1016 if (CodeAddressNotification::IsEnabled()) {
1017 name_buffer_->Reset();
1018 name_buffer_->AppendString(shared->DebugName());
1019 name_buffer_->AppendByte('\0');
1020 CodeAddressNotification::WriteSymbolMap(this,
1021 Add,
1022 code->instruction_start(),
1023 code->instruction_size(),
1024 name_buffer_->get(),
1025 tag,
1026 shared->script(),
1027 line);
1028 }
1002 if (!FLAG_log_code) return; 1029 if (!FLAG_log_code) return;
1003 LogMessageBuilder msg(this); 1030 LogMessageBuilder msg(this);
1004 SmartArrayPointer<char> name = 1031 SmartArrayPointer<char> name =
1005 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 1032 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1006 SmartArrayPointer<char> sourcestr = 1033 SmartArrayPointer<char> sourcestr =
1007 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 1034 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1008 msg.Append("%s,%s,", 1035 msg.Append("%s,%s,",
1009 kLogEventsNames[CODE_CREATION_EVENT], 1036 kLogEventsNames[CODE_CREATION_EVENT],
1010 kLogEventsNames[tag]); 1037 kLogEventsNames[tag]);
1011 msg.AppendAddress(code->address()); 1038 msg.AppendAddress(code->address());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 1075
1049 1076
1050 void Logger::CodeMovingGCEvent() { 1077 void Logger::CodeMovingGCEvent() {
1051 if (!log_->IsEnabled() || !FLAG_ll_prof) return; 1078 if (!log_->IsEnabled() || !FLAG_ll_prof) return;
1052 LowLevelLogWriteBytes(&kCodeMovingGCTag, sizeof(kCodeMovingGCTag)); 1079 LowLevelLogWriteBytes(&kCodeMovingGCTag, sizeof(kCodeMovingGCTag));
1053 OS::SignalCodeMovingGC(); 1080 OS::SignalCodeMovingGC();
1054 } 1081 }
1055 1082
1056 1083
1057 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { 1084 void Logger::RegExpCodeCreateEvent(Code* code, String* source) {
1058 if (!log_->IsEnabled()) return; 1085 if (!log_->IsEnabled() && !CodeAddressNotification::IsEnabled()) return;
1059 if (FLAG_ll_prof || Serializer::enabled()) { 1086 if (FLAG_ll_prof || Serializer::enabled()) {
1060 name_buffer_->Reset(); 1087 name_buffer_->Reset();
1061 name_buffer_->AppendBytes(kLogEventsNames[REG_EXP_TAG]); 1088 name_buffer_->AppendBytes(kLogEventsNames[REG_EXP_TAG]);
1062 name_buffer_->AppendByte(':'); 1089 name_buffer_->AppendByte(':');
1063 name_buffer_->AppendString(source); 1090 name_buffer_->AppendString(source);
1064 } 1091 }
1065 if (FLAG_ll_prof) { 1092 if (FLAG_ll_prof) {
1066 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size()); 1093 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
1067 } 1094 }
1068 if (Serializer::enabled()) { 1095 if (Serializer::enabled()) {
1069 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size()); 1096 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
1070 } 1097 }
1098 if (CodeAddressNotification::IsEnabled()) {
1099 name_buffer_->Reset();
1100 name_buffer_->AppendBytes(kLogEventsNames[REG_EXP_TAG]);
1101 name_buffer_->AppendByte(':');
1102 name_buffer_->AppendString(source);
1103 name_buffer_->AppendByte('\0');
1104 CodeAddressNotification::WriteSymbolMap(this,
1105 Add,
1106 code->instruction_start(),
1107 code->instruction_size(),
1108 name_buffer_->get(),
1109 REG_EXP_TAG,
1110 NULL,
1111 0);
1112 }
1071 if (!FLAG_log_code) return; 1113 if (!FLAG_log_code) return;
1072 LogMessageBuilder msg(this); 1114 LogMessageBuilder msg(this);
1073 msg.Append("%s,%s,", 1115 msg.Append("%s,%s,",
1074 kLogEventsNames[CODE_CREATION_EVENT], 1116 kLogEventsNames[CODE_CREATION_EVENT],
1075 kLogEventsNames[REG_EXP_TAG]); 1117 kLogEventsNames[REG_EXP_TAG]);
1076 msg.AppendAddress(code->address()); 1118 msg.AppendAddress(code->address());
1077 msg.Append(",%d,\"", code->ExecutableSize()); 1119 msg.Append(",%d,\"", code->ExecutableSize());
1078 msg.AppendDetailed(source, false); 1120 msg.AppendDetailed(source, false);
1079 msg.Append('\"'); 1121 msg.Append('\"');
1080 msg.Append('\n'); 1122 msg.Append('\n');
1081 msg.WriteToLogFile(); 1123 msg.WriteToLogFile();
1082 } 1124 }
1083 1125
1084 1126
1085 void Logger::CodeMoveEvent(Address from, Address to) { 1127 void Logger::CodeMoveEvent(Address from, Address to) {
1086 if (!log_->IsEnabled()) return; 1128 if (!log_->IsEnabled() && !CodeAddressNotification::IsEnabled()) return;
1087 if (FLAG_ll_prof) LowLevelCodeMoveEvent(from, to); 1129 if (FLAG_ll_prof) LowLevelCodeMoveEvent(from, to);
1088 if (Serializer::enabled() && address_to_name_map_ != NULL) { 1130 if (Serializer::enabled() && address_to_name_map_ != NULL) {
1089 address_to_name_map_->Move(from, to); 1131 address_to_name_map_->Move(from, to);
1090 } 1132 }
1133 if (CodeAddressNotification::IsEnabled()) {
1134 CodeAddressNotification::WriteSymbolMap(this,
1135 Move,
1136 from,
1137 0,
1138 NULL,
1139 CODE_MOVE_EVENT,
1140 to,
1141 0);
1142 }
1091 MoveEventInternal(CODE_MOVE_EVENT, from, to); 1143 MoveEventInternal(CODE_MOVE_EVENT, from, to);
1092 } 1144 }
1093 1145
1094 1146
1095 void Logger::CodeDeleteEvent(Address from) { 1147 void Logger::CodeDeleteEvent(Address from) {
1096 if (!log_->IsEnabled()) return; 1148 if (!log_->IsEnabled() && !CodeAddressNotification::IsEnabled()) return;
1097 if (FLAG_ll_prof) LowLevelCodeDeleteEvent(from); 1149 if (FLAG_ll_prof) LowLevelCodeDeleteEvent(from);
1098 if (Serializer::enabled() && address_to_name_map_ != NULL) { 1150 if (Serializer::enabled() && address_to_name_map_ != NULL) {
1099 address_to_name_map_->Remove(from); 1151 address_to_name_map_->Remove(from);
1100 } 1152 }
1153 if (CodeAddressNotification::IsEnabled()) {
1154 CodeAddressNotification::WriteSymbolMap(this,
1155 Remove,
1156 from,
1157 0,
1158 NULL,
1159 CODE_DELETE_EVENT,
1160 NULL,
1161 0);
1162 }
1101 DeleteEventInternal(CODE_DELETE_EVENT, from); 1163 DeleteEventInternal(CODE_DELETE_EVENT, from);
1102 } 1164 }
1103 1165
1104 1166
1105 void Logger::SnapshotPositionEvent(Address addr, int pos) { 1167 void Logger::SnapshotPositionEvent(Address addr, int pos) {
1106 if (!log_->IsEnabled()) return; 1168 if (!log_->IsEnabled()) return;
1107 if (FLAG_ll_prof) LowLevelSnapshotPositionEvent(addr, pos); 1169 if (FLAG_ll_prof) LowLevelSnapshotPositionEvent(addr, pos);
1108 if (Serializer::enabled() && address_to_name_map_ != NULL) { 1170 if (Serializer::enabled() && address_to_name_map_ != NULL) {
1109 const char* code_name = address_to_name_map_->Lookup(addr); 1171 const char* code_name = address_to_name_map_->Lookup(addr);
1110 if (code_name == NULL) return; // Not a code object. 1172 if (code_name == NULL) return; // Not a code object.
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 void Logger::LogFailure() { 1380 void Logger::LogFailure() {
1319 PauseProfiler(); 1381 PauseProfiler();
1320 } 1382 }
1321 1383
1322 1384
1323 bool Logger::IsProfilerSamplerActive() { 1385 bool Logger::IsProfilerSamplerActive() {
1324 return ticker_->IsActive(); 1386 return ticker_->IsActive();
1325 } 1387 }
1326 1388
1327 1389
1390 // This returns true if API callback for symbol address is enabled.
1391 bool Logger::CodeAddressCallbackEnabled() {
1392 return CodeAddressNotification::IsEnabled();
1393 }
1394
1395
1328 class EnumerateOptimizedFunctionsVisitor: public OptimizedFunctionVisitor { 1396 class EnumerateOptimizedFunctionsVisitor: public OptimizedFunctionVisitor {
1329 public: 1397 public:
1330 EnumerateOptimizedFunctionsVisitor(Handle<SharedFunctionInfo>* sfis, 1398 EnumerateOptimizedFunctionsVisitor(Handle<SharedFunctionInfo>* sfis,
1331 Handle<Code>* code_objects, 1399 Handle<Code>* code_objects,
1332 int* count) 1400 int* count)
1333 : sfis_(sfis), code_objects_(code_objects), count_(count) { } 1401 : sfis_(sfis), code_objects_(code_objects), count_(count) { }
1334 1402
1335 virtual void EnterContext(Context* context) {} 1403 virtual void EnterContext(Context* context) {}
1336 virtual void LeaveContext(Context* context) {} 1404 virtual void LeaveContext(Context* context) {}
1337 1405
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 1850
1783 void SamplerRegistry::RemoveActiveSampler(Sampler* sampler) { 1851 void SamplerRegistry::RemoveActiveSampler(Sampler* sampler) {
1784 ASSERT(sampler->IsActive()); 1852 ASSERT(sampler->IsActive());
1785 ScopedLock lock(active_samplers_mutex); 1853 ScopedLock lock(active_samplers_mutex);
1786 ASSERT(active_samplers_ != NULL); 1854 ASSERT(active_samplers_ != NULL);
1787 bool removed = active_samplers_->RemoveElement(sampler); 1855 bool removed = active_samplers_->RemoveElement(sampler);
1788 ASSERT(removed); 1856 ASSERT(removed);
1789 USE(removed); 1857 USE(removed);
1790 } 1858 }
1791 1859
1860
1861 // External code address mapping notifications.
1862
1863 // Counter to indicate that enumeration of compiled functions is required.
1864 // Incremented each time notification enabled and enumeration requested.
1865 // Callback setting is not isolated. Set global and check from each logger.
1866 volatile Atomic32 NeedReset = 0;
1867 Atomic32 EnumIncr = 1;
1868 // The current callback (only one)
1869 volatile AtomicWord ExtCallback = NULL;
1870
1871 // Called by host to set callbacks - null turns off callbacks.
1872 // Callback may still be called after it is turned off. The caller must
1873 // close the isolate before unloading the callback code.
1874 void CodeAddressNotification::SetCodeAddressEventCallback(CodeAddressEvent cb,
1875 bool enumExisting) {
1876 AtomicWord newcb = (AtomicWord)cb;
1877 AtomicWord old = NoBarrier_AtomicExchange(&ExtCallback, newcb);
1878
1879 if (cb != NULL && enumExisting) {
1880 NoBarrier_AtomicIncrement(&NeedReset, EnumIncr);
1881 }
1882 }
1883
1884
1885 // Called by v8 when a symbol map is created or changed.
1886 void CodeAddressNotification::WriteSymbolMap(Logger* logger,
1887 CodeAddressOperation op,
1888 const void* addr1,
1889 int len,
1890 const char* symbol,
1891 Logger::LogEventsAndTags tag,
1892 const void* addr2,
1893 int line) {
1894 CodeAddressEvent cb = (CodeAddressEvent)ExtCallback;
1895 if (cb != NULL) {
1896 if (logger->notified_reset_ < NeedReset) {
1897 // Enumeration needed. Log a reset, then log existing functions.
1898 logger->notified_reset_ = NeedReset;
1899 cb(CodeAddressOperation::Reset,
1900 NULL,
1901 0,
1902 "",
1903 Logger::CODE_CREATION_EVENT,
1904 NULL,
1905 0);
1906 logger->LogCompiledFunctions();
1907 }
1908
1909 if (op == Add) {
1910 switch (tag) {
1911 case Logger::SCRIPT_TAG:
1912 case Logger::NATIVE_SCRIPT_TAG:
1913 op = Source;
1914 break;
1915 case Logger::FUNCTION_TAG:
1916 case Logger::LAZY_COMPILE_TAG:
1917 case Logger::NATIVE_FUNCTION_TAG:
1918 case Logger::NATIVE_LAZY_COMPILE_TAG:
1919 case Logger::REG_EXP_TAG:
1920 break;
1921 default:
1922 return;
1923 }
1924 }
1925 cb(op, addr1, len, symbol, static_cast<int>(tag), addr2, line);
1926 }
1927 }
1928
1929
1930 // Called by v8 to determine if callbacks are enabled.
1931 bool CodeAddressNotification::IsEnabled() {
1932 return ExtCallback != NULL;
1933 }
1934
1792 } } // namespace v8::internal 1935 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/log.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698