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])) return true; | 441 if (string->Equals(vector[i])) |
| 442 return true; |
442 } | 443 } |
443 return false; | 444 return false; |
444 } | 445 } |
445 | 446 |
446 | 447 |
447 static void CheckChildrenNames(const v8::CpuProfileNode* node, | 448 static void CheckChildrenNames(const v8::CpuProfileNode* node, |
448 const Vector<v8::Handle<v8::String> >& names) { | 449 const Vector<v8::Handle<v8::String> >& names) { |
449 int count = node->GetChildrenCount(); | 450 int count = node->GetChildrenCount(); |
450 for (int i = 0; i < count; i++) { | 451 for (int i = 0; i < count; i++) { |
451 v8::Handle<v8::String> name = node->GetChild(i)->GetFunctionName(); | 452 v8::Handle<v8::String> name = node->GetChild(i)->GetFunctionName(); |
452 if (!ContainsString(name, names)) { | 453 CHECK(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 } | |
460 // Check that there are no duplicates. | 454 // Check that there are no duplicates. |
461 for (int j = 0; j < count; j++) { | 455 for (int j = 0; j < count; j++) { |
462 if (j == i) continue; | 456 if (j == i) continue; |
463 if (name->Equals(node->GetChild(j)->GetFunctionName())) { | 457 CHECK(!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 } | |
471 } | 458 } |
472 } | 459 } |
473 } | 460 } |
474 | 461 |
475 | 462 |
476 static const v8::CpuProfileNode* FindChild(const v8::CpuProfileNode* node, | 463 static const v8::CpuProfileNode* FindChild(const v8::CpuProfileNode* node, |
477 const char* name) { | 464 const char* name) { |
478 int count = node->GetChildrenCount(); | 465 int count = node->GetChildrenCount(); |
479 v8::Handle<v8::String> nameHandle = v8_str(name); | 466 v8::Handle<v8::String> nameHandle = v8_str(name); |
480 for (int i = 0; i < count; i++) { | 467 for (int i = 0; i < count; i++) { |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 CHECK(func->shared()->code() == func->code() || !i::FLAG_crankshaft); | 1067 CHECK(func->shared()->code() == func->code() || !i::FLAG_crankshaft); |
1081 code = func->shared()->code(); | 1068 code = func->shared()->code(); |
1082 } | 1069 } |
1083 CHECK(code); | 1070 CHECK(code); |
1084 i::Address code_address = code->instruction_start(); | 1071 i::Address code_address = code->instruction_start(); |
1085 CHECK(code_address); | 1072 CHECK(code_address); |
1086 | 1073 |
1087 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); | 1074 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); |
1088 profiles->StartProfiling("", false); | 1075 profiles->StartProfiling("", false); |
1089 ProfileGenerator generator(profiles); | 1076 ProfileGenerator generator(profiles); |
1090 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( | 1077 ProfilerEventsProcessor* processor = new ProfilerEventsProcessor( |
1091 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); | 1078 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)); |
1092 processor->Start(); | 1079 processor->Start(); |
1093 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); | 1080 CpuProfiler profiler(isolate, profiles, &generator, processor); |
1094 | 1081 |
1095 // Enqueue code creation events. | 1082 // Enqueue code creation events. |
1096 i::Handle<i::String> str = factory->NewStringFromAsciiChecked(func_name); | 1083 i::Handle<i::String> str = factory->NewStringFromAsciiChecked(func_name); |
1097 int line = 1; | 1084 int line = 1; |
1098 int column = 1; | 1085 int column = 1; |
1099 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, code, func->shared(), NULL, | 1086 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, code, func->shared(), NULL, |
1100 *str, line, column); | 1087 *str, line, column); |
1101 | 1088 |
1102 // Enqueue a tick event to enable code events processing. | 1089 // Enqueue a tick event to enable code events processing. |
1103 EnqueueTickSampleEvent(processor.get(), code_address); | 1090 EnqueueTickSampleEvent(processor, code_address); |
1104 | 1091 |
1105 processor->StopSynchronously(); | 1092 processor->StopSynchronously(); |
1106 | 1093 |
1107 CpuProfile* profile = profiles->StopProfiling(""); | 1094 CpuProfile* profile = profiles->StopProfiling(""); |
1108 CHECK(profile); | 1095 CHECK(profile); |
1109 | 1096 |
1110 // Check the state of profile generator. | 1097 // Check the state of profile generator. |
1111 CodeEntry* func_entry = generator.code_map()->FindEntry(code_address); | 1098 CodeEntry* func_entry = generator.code_map()->FindEntry(code_address); |
1112 CHECK(func_entry); | 1099 CHECK(func_entry); |
1113 CHECK_EQ(0, strcmp(func_name, func_entry->name())); | 1100 CHECK_EQ(0, strcmp(func_name, func_entry->name())); |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 v8::HandleScope scope(CcTest::isolate()); | 1762 v8::HandleScope scope(CcTest::isolate()); |
1776 | 1763 |
1777 const char* source = | 1764 const char* source = |
1778 "function CompareStatementWithThis() {\n" | 1765 "function CompareStatementWithThis() {\n" |
1779 " if (this === 1) {}\n" | 1766 " if (this === 1) {}\n" |
1780 "}\n" | 1767 "}\n" |
1781 "CompareStatementWithThis();\n"; | 1768 "CompareStatementWithThis();\n"; |
1782 | 1769 |
1783 v8::Script::Compile(v8_str(source))->Run(); | 1770 v8::Script::Compile(v8_str(source))->Run(); |
1784 } | 1771 } |
OLD | NEW |