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

Side by Side Diff: src/log.cc

Issue 402100: Add logging of callbacks in prof-lazy mode. (Closed)
Patch Set: Comments addressed Created 11 years, 1 month 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') | test/cctest/test-log.cc » ('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 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 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <stdarg.h> 28 #include <stdarg.h>
29 29
30 #include "v8.h" 30 #include "v8.h"
31 31
32 #include "bootstrapper.h" 32 #include "bootstrapper.h"
33 #include "global-handles.h"
33 #include "log.h" 34 #include "log.h"
34 #include "macro-assembler.h" 35 #include "macro-assembler.h"
35 #include "serialize.h" 36 #include "serialize.h"
36 #include "string-stream.h" 37 #include "string-stream.h"
37 38
38 namespace v8 { 39 namespace v8 {
39 namespace internal { 40 namespace internal {
40 41
41 #ifdef ENABLE_LOGGING_AND_PROFILING 42 #ifdef ENABLE_LOGGING_AND_PROFILING
42 43
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 void Logger::DeleteEvent(const char* name, void* object) { 631 void Logger::DeleteEvent(const char* name, void* object) {
631 #ifdef ENABLE_LOGGING_AND_PROFILING 632 #ifdef ENABLE_LOGGING_AND_PROFILING
632 if (!Log::IsEnabled() || !FLAG_log) return; 633 if (!Log::IsEnabled() || !FLAG_log) return;
633 LogMessageBuilder msg; 634 LogMessageBuilder msg;
634 msg.Append("delete,%s,0x%" V8PRIxPTR "\n", name, object); 635 msg.Append("delete,%s,0x%" V8PRIxPTR "\n", name, object);
635 msg.WriteToLogFile(); 636 msg.WriteToLogFile();
636 #endif 637 #endif
637 } 638 }
638 639
639 640
641 void Logger::CallbackEvent(const char* class_name, const char* method_name,
642 Address entry_point) {
643 #ifdef ENABLE_LOGGING_AND_PROFILING
644 if (!Log::IsEnabled() || !FLAG_log_code) return;
645 LogMessageBuilder msg;
646 msg.Append("%s,%s,",
647 log_events_[CODE_CREATION_EVENT], log_events_[CALLBACK_TAG]);
648 msg.AppendAddress(entry_point);
649 msg.Append(",0,\"");
650 if (class_name != NULL) {
651 msg.Append("%s.", class_name);
652 }
653 msg.Append("%s\"\n", method_name);
654 msg.WriteToLogFile();
655 #endif
656 }
657
658
640 #ifdef ENABLE_LOGGING_AND_PROFILING 659 #ifdef ENABLE_LOGGING_AND_PROFILING
641 660
642 // A class that contains all common code dealing with record compression. 661 // A class that contains all common code dealing with record compression.
643 class CompressionHelper { 662 class CompressionHelper {
644 public: 663 public:
645 explicit CompressionHelper(int window_size) 664 explicit CompressionHelper(int window_size)
646 : compressor_(window_size), repeat_count_(0) { } 665 : compressor_(window_size), repeat_count_(0) { }
647 666
648 // Handles storing message in compressor, retrieving the previous one and 667 // Handles storing message in compressor, retrieving the previous one and
649 // prefixing it with repeat count, if needed. 668 // prefixing it with repeat count, if needed.
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 const int modules_to_enable = ~GetActiveProfilerModules() & flags; 1083 const int modules_to_enable = ~GetActiveProfilerModules() & flags;
1065 if (modules_to_enable != PROFILER_MODULE_NONE) { 1084 if (modules_to_enable != PROFILER_MODULE_NONE) {
1066 is_logging_ = true; 1085 is_logging_ = true;
1067 } 1086 }
1068 if (modules_to_enable & PROFILER_MODULE_CPU) { 1087 if (modules_to_enable & PROFILER_MODULE_CPU) {
1069 if (FLAG_prof_lazy) { 1088 if (FLAG_prof_lazy) {
1070 profiler_->Engage(); 1089 profiler_->Engage();
1071 LOG(UncheckedStringEvent("profiler", "resume")); 1090 LOG(UncheckedStringEvent("profiler", "resume"));
1072 FLAG_log_code = true; 1091 FLAG_log_code = true;
1073 LogCompiledFunctions(); 1092 LogCompiledFunctions();
1093 LogCallbacks();
1074 if (!FLAG_sliding_state_window) ticker_->Start(); 1094 if (!FLAG_sliding_state_window) ticker_->Start();
1075 } 1095 }
1076 profiler_->resume(); 1096 profiler_->resume();
1077 } 1097 }
1078 if (modules_to_enable & 1098 if (modules_to_enable &
1079 (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) { 1099 (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) {
1080 FLAG_log_gc = true; 1100 FLAG_log_gc = true;
1081 } 1101 }
1082 } 1102 }
1083 1103
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 continue; 1214 continue;
1195 } 1215 }
1196 } 1216 }
1197 // If no script or script has no name. 1217 // If no script or script has no name.
1198 LOG(CodeCreateEvent(Logger::LAZY_COMPILE_TAG, shared->code(), *func_name)); 1218 LOG(CodeCreateEvent(Logger::LAZY_COMPILE_TAG, shared->code(), *func_name));
1199 } 1219 }
1200 1220
1201 DeleteArray(sfis); 1221 DeleteArray(sfis);
1202 } 1222 }
1203 1223
1224
1225 namespace {
1226
1227 class FunctionTemplateInfosVisitor : public ObjectVisitor {
1228 public:
1229 virtual ~FunctionTemplateInfosVisitor() {}
1230 virtual void VisitPointers(Object** start, Object** end) {
1231 for (Object** p = start; p < end; ++p) {
1232 VisitFTI(*p);
1233 }
1234 }
1235
1236 private:
1237 void VisitFTI(Object* o) {
1238 // The data about callbacks is in fact dynamically typed
1239 // (Object ptrs are used), so we use runtime type checking
1240 // to be sure that we retrieve the right thing.
1241 if (!o->IsFunctionTemplateInfo())
1242 return;
1243 AssertNoAllocation no_alloc;
1244 FunctionTemplateInfo* fti = FunctionTemplateInfo::cast(o);
1245 if (!fti->prototype_template()->IsObjectTemplateInfo())
1246 return;
1247 SmartPointer<char> class_name;
1248 if (fti->class_name()->IsString()) {
1249 class_name = String::cast(fti->class_name())->
1250 ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1251 }
1252 ObjectTemplateInfo* proto =
1253 ObjectTemplateInfo::cast(fti->prototype_template());
1254 NeanderArray props(Handle<Object>(proto->property_list()));
1255 // Properties are triples: [property name, entry point, attributes].
1256 // See Template::Set in api.cc.
1257 for (int i = 0; i < props.length(); i += 3) {
1258 if (!props.get(i)->IsString()
1259 || !props.get(i + 1)->IsFunctionTemplateInfo())
1260 continue;
1261 FunctionTemplateInfo* native_fti =
1262 FunctionTemplateInfo::cast(props.get(i + 1));
1263 Object* raw_call_data = native_fti->call_code();
1264 if (raw_call_data->IsUndefined())
1265 continue;
1266 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data);
1267 Object* callback_obj = call_data->callback();
1268 Address entry_point = v8::ToCData<Address>(callback_obj);
1269 SmartPointer<char> method_name(
1270 String::cast(props.get(i))->
1271 ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL));
1272 LOG(CallbackEvent(*class_name, *method_name, entry_point));
1273 }
1274 }
1275 };
1276
1277 } // anonymous namespace
1278
1279
1280 void Logger::LogCallbacks() {
1281 // We are looking for callbacks information exposed via persistent
1282 // FunctionTemplate objects.
1283 FunctionTemplateInfosVisitor visitor;
1284 GlobalHandles::IterateStrongRoots(&visitor);
1285 }
1286
1204 #endif 1287 #endif
1205 1288
1206 1289
1207 bool Logger::Setup() { 1290 bool Logger::Setup() {
1208 #ifdef ENABLE_LOGGING_AND_PROFILING 1291 #ifdef ENABLE_LOGGING_AND_PROFILING
1209 // --log-all enables all the log flags. 1292 // --log-all enables all the log flags.
1210 if (FLAG_log_all) { 1293 if (FLAG_log_all) {
1211 FLAG_log_runtime = true; 1294 FLAG_log_runtime = true;
1212 FLAG_log_api = true; 1295 FLAG_log_api = true;
1213 FLAG_log_code = true; 1296 FLAG_log_code = true;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 // Otherwise, if the sliding state window computation has not been 1438 // Otherwise, if the sliding state window computation has not been
1356 // started we do it now. 1439 // started we do it now.
1357 if (sliding_state_window_ == NULL) { 1440 if (sliding_state_window_ == NULL) {
1358 sliding_state_window_ = new SlidingStateWindow(); 1441 sliding_state_window_ = new SlidingStateWindow();
1359 } 1442 }
1360 #endif 1443 #endif
1361 } 1444 }
1362 1445
1363 1446
1364 } } // namespace v8::internal 1447 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/log.h ('k') | test/cctest/test-log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698