OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 // Dump collected profile to have a better diagnostic in case of failure. | 431 // Dump collected profile to have a better diagnostic in case of failure. |
432 reinterpret_cast<i::CpuProfile*>(profile)->Print(); | 432 reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
433 | 433 |
434 return profile; | 434 return profile; |
435 } | 435 } |
436 | 436 |
437 | 437 |
438 static bool ContainsString(v8::Handle<v8::String> string, | 438 static bool ContainsString(v8::Handle<v8::String> string, |
439 const Vector<v8::Handle<v8::String> >& vector) { | 439 const Vector<v8::Handle<v8::String> >& vector) { |
440 for (int i = 0; i < vector.length(); i++) { | 440 for (int i = 0; i < vector.length(); i++) { |
441 if (string->Equals(vector[i])) | 441 if (string->Equals(vector[i])) return true; |
442 return true; | |
443 } | 442 } |
444 return false; | 443 return false; |
445 } | 444 } |
446 | 445 |
447 | 446 |
448 static void CheckChildrenNames(const v8::CpuProfileNode* node, | 447 static void CheckChildrenNames(const v8::CpuProfileNode* node, |
449 const Vector<v8::Handle<v8::String> >& names) { | 448 const Vector<v8::Handle<v8::String> >& names) { |
450 int count = node->GetChildrenCount(); | 449 int count = node->GetChildrenCount(); |
451 for (int i = 0; i < count; i++) { | 450 for (int i = 0; i < count; i++) { |
452 v8::Handle<v8::String> name = node->GetChild(i)->GetFunctionName(); | 451 v8::Handle<v8::String> name = node->GetChild(i)->GetFunctionName(); |
453 CHECK(ContainsString(name, names)); | 452 if (!ContainsString(name, names)) { |
| 453 char buffer[100]; |
| 454 i::SNPrintF(Vector<char>(buffer, arraysize(buffer)), |
| 455 "Unexpected child '%s' found in '%s'", |
| 456 *v8::String::Utf8Value(name), |
| 457 *v8::String::Utf8Value(node->GetFunctionName())); |
| 458 FATAL(buffer); |
| 459 } |
454 // Check that there are no duplicates. | 460 // Check that there are no duplicates. |
455 for (int j = 0; j < count; j++) { | 461 for (int j = 0; j < count; j++) { |
456 if (j == i) continue; | 462 if (j == i) continue; |
457 CHECK(!name->Equals(node->GetChild(j)->GetFunctionName())); | 463 if (name->Equals(node->GetChild(j)->GetFunctionName())) { |
| 464 char buffer[100]; |
| 465 i::SNPrintF(Vector<char>(buffer, arraysize(buffer)), |
| 466 "Second child with the same name '%s' found in '%s'", |
| 467 *v8::String::Utf8Value(name), |
| 468 *v8::String::Utf8Value(node->GetFunctionName())); |
| 469 FATAL(buffer); |
| 470 } |
458 } | 471 } |
459 } | 472 } |
460 } | 473 } |
461 | 474 |
462 | 475 |
463 static const v8::CpuProfileNode* FindChild(const v8::CpuProfileNode* node, | 476 static const v8::CpuProfileNode* FindChild(const v8::CpuProfileNode* node, |
464 const char* name) { | 477 const char* name) { |
465 int count = node->GetChildrenCount(); | 478 int count = node->GetChildrenCount(); |
466 v8::Handle<v8::String> nameHandle = v8_str(name); | 479 v8::Handle<v8::String> nameHandle = v8_str(name); |
467 for (int i = 0; i < count; i++) { | 480 for (int i = 0; i < count; i++) { |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 CHECK(func->shared()->code() == func->code() || !i::FLAG_crankshaft); | 1080 CHECK(func->shared()->code() == func->code() || !i::FLAG_crankshaft); |
1068 code = func->shared()->code(); | 1081 code = func->shared()->code(); |
1069 } | 1082 } |
1070 CHECK(code); | 1083 CHECK(code); |
1071 i::Address code_address = code->instruction_start(); | 1084 i::Address code_address = code->instruction_start(); |
1072 CHECK(code_address); | 1085 CHECK(code_address); |
1073 | 1086 |
1074 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); | 1087 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); |
1075 profiles->StartProfiling("", false); | 1088 profiles->StartProfiling("", false); |
1076 ProfileGenerator generator(profiles); | 1089 ProfileGenerator generator(profiles); |
1077 ProfilerEventsProcessor* processor = new ProfilerEventsProcessor( | 1090 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( |
1078 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)); | 1091 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); |
1079 processor->Start(); | 1092 processor->Start(); |
1080 CpuProfiler profiler(isolate, profiles, &generator, processor); | 1093 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); |
1081 | 1094 |
1082 // Enqueue code creation events. | 1095 // Enqueue code creation events. |
1083 i::Handle<i::String> str = factory->NewStringFromAsciiChecked(func_name); | 1096 i::Handle<i::String> str = factory->NewStringFromAsciiChecked(func_name); |
1084 int line = 1; | 1097 int line = 1; |
1085 int column = 1; | 1098 int column = 1; |
1086 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, code, func->shared(), NULL, | 1099 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, code, func->shared(), NULL, |
1087 *str, line, column); | 1100 *str, line, column); |
1088 | 1101 |
1089 // Enqueue a tick event to enable code events processing. | 1102 // Enqueue a tick event to enable code events processing. |
1090 EnqueueTickSampleEvent(processor, code_address); | 1103 EnqueueTickSampleEvent(processor.get(), code_address); |
1091 | 1104 |
1092 processor->StopSynchronously(); | 1105 processor->StopSynchronously(); |
1093 | 1106 |
1094 CpuProfile* profile = profiles->StopProfiling(""); | 1107 CpuProfile* profile = profiles->StopProfiling(""); |
1095 CHECK(profile); | 1108 CHECK(profile); |
1096 | 1109 |
1097 // Check the state of profile generator. | 1110 // Check the state of profile generator. |
1098 CodeEntry* func_entry = generator.code_map()->FindEntry(code_address); | 1111 CodeEntry* func_entry = generator.code_map()->FindEntry(code_address); |
1099 CHECK(func_entry); | 1112 CHECK(func_entry); |
1100 CHECK_EQ(0, strcmp(func_name, func_entry->name())); | 1113 CHECK_EQ(0, strcmp(func_name, func_entry->name())); |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1794 v8::HandleScope scope(CcTest::isolate()); | 1807 v8::HandleScope scope(CcTest::isolate()); |
1795 | 1808 |
1796 const char* source = | 1809 const char* source = |
1797 "function CompareStatementWithThis() {\n" | 1810 "function CompareStatementWithThis() {\n" |
1798 " if (this === 1) {}\n" | 1811 " if (this === 1) {}\n" |
1799 "}\n" | 1812 "}\n" |
1800 "CompareStatementWithThis();\n"; | 1813 "CompareStatementWithThis();\n"; |
1801 | 1814 |
1802 v8::Script::Compile(v8_str(source))->Run(); | 1815 v8::Script::Compile(v8_str(source))->Run(); |
1803 } | 1816 } |
OLD | NEW |