Chromium Code Reviews| 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 " baz();\n" | 490 " baz();\n" |
| 491 " } catch (e) { }\n" | 491 " } catch (e) { }\n" |
| 492 "}\n" | 492 "}\n" |
| 493 "function start(timeout) {\n" | 493 "function start(timeout) {\n" |
| 494 " var start = Date.now();\n" | 494 " var start = Date.now();\n" |
| 495 " do {\n" | 495 " do {\n" |
| 496 " foo();\n" | 496 " foo();\n" |
| 497 " var duration = Date.now() - start;\n" | 497 " var duration = Date.now() - start;\n" |
| 498 " } while (duration < timeout);\n" | 498 " } while (duration < timeout);\n" |
| 499 " return duration;\n" | 499 " return duration;\n" |
| 500 "}\n"; | 500 "}\n" |
| 501 "//# sourceURL=cpu_profiler_test_source.js"; | |
| 501 | 502 |
| 502 | 503 |
| 503 // Check that the profile tree for the script above will look like the | 504 // Check that the profile tree for the script above will look like the |
| 504 // following: | 505 // following: |
| 505 // | 506 // |
| 506 // [Top down]: | 507 // [Top down]: |
| 507 // 1062 0 (root) [-1] | 508 // 1062 0 (root) [-1] |
| 508 // 1054 0 start [-1] | 509 // 1054 0 start [-1] |
| 509 // 1054 1 foo [-1] | 510 // 1054 1 foo [-1] |
| 510 // 265 0 baz [-1] | 511 // 265 0 baz [-1] |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 521 LocalContext env; | 522 LocalContext env; |
| 522 v8::HandleScope scope(env->GetIsolate()); | 523 v8::HandleScope scope(env->GetIsolate()); |
| 523 | 524 |
| 524 v8::Script::Compile(v8::String::New(cpu_profiler_test_source))->Run(); | 525 v8::Script::Compile(v8::String::New(cpu_profiler_test_source))->Run(); |
| 525 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 526 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 526 env->Global()->Get(v8::String::New("start"))); | 527 env->Global()->Get(v8::String::New("start"))); |
| 527 | 528 |
| 528 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 529 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 529 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | 530 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
| 530 | 531 |
| 531 cpu_profiler->StartCpuProfiling(profile_name); | |
| 532 int32_t profiling_interval_ms = 200; | 532 int32_t profiling_interval_ms = 200; |
| 533 #if defined(_WIN32) || defined(_WIN64) | 533 #if defined(_WIN32) || defined(_WIN64) |
| 534 // 200ms is not enough on Windows. See | 534 // 200ms is not enough on Windows. See |
| 535 // https://code.google.com/p/v8/issues/detail?id=2628 | 535 // https://code.google.com/p/v8/issues/detail?id=2628 |
| 536 profiling_interval_ms = 500; | 536 profiling_interval_ms = 500; |
| 537 #endif | 537 #endif |
| 538 | |
| 539 // Warm up. | |
| 538 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; | 540 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; |
| 539 function->Call(env->Global(), ARRAY_SIZE(args), args); | 541 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 542 | |
| 543 cpu_profiler->StartCpuProfiling(profile_name); | |
| 544 | |
| 545 function->Call(env->Global(), ARRAY_SIZE(args), args); | |
| 546 | |
| 540 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 547 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 541 | 548 |
| 542 CHECK_NE(NULL, profile); | 549 CHECK_NE(NULL, profile); |
| 543 // Dump collected profile to have a better diagnostic in case of failure. | 550 // Dump collected profile to have a better diagnostic in case of failure. |
| 544 reinterpret_cast<i::CpuProfile*>( | 551 reinterpret_cast<i::CpuProfile*>( |
| 545 const_cast<v8::CpuProfile*>(profile))->Print(); | 552 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 546 | 553 |
| 547 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 554 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 548 | 555 |
| 549 ScopedVector<v8::Handle<v8::String> > names(3); | 556 ScopedVector<v8::Handle<v8::String> > names(3); |
| 550 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 557 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 551 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 558 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 552 names[2] = v8::String::New("start"); | 559 names[2] = v8::String::New("start"); |
| 553 CheckChildrenNames(root, names); | 560 CheckChildrenNames(root, names); |
| 554 | 561 |
| 555 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 562 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 563 CHECK_EQ(v8::String::New("cpu_profiler_test_source.js"), | |
|
yurys
2013/06/11 11:23:06
I'd rather have it tested in a separate test.
| |
| 564 startNode->GetScriptResourceName()); | |
| 556 CHECK_EQ(1, startNode->GetChildrenCount()); | 565 CHECK_EQ(1, startNode->GetChildrenCount()); |
| 557 | 566 |
| 558 const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo"); | 567 const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo"); |
| 559 CHECK_EQ(3, fooNode->GetChildrenCount()); | 568 CHECK_EQ(3, fooNode->GetChildrenCount()); |
| 560 | 569 |
| 561 const char* barBranch[] = { "bar", "delay", "loop" }; | 570 const char* barBranch[] = { "bar", "delay", "loop" }; |
| 562 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); | 571 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); |
| 563 const char* bazBranch[] = { "baz", "delay", "loop" }; | 572 const char* bazBranch[] = { "baz", "delay", "loop" }; |
| 564 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); | 573 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); |
| 565 const char* delayBranch[] = { "delay", "loop" }; | 574 const char* delayBranch[] = { "delay", "loop" }; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 792 | 801 |
| 793 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 802 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 794 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 803 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 795 // TODO(yurys): in LoadIC should be changed to report external callback | 804 // TODO(yurys): in LoadIC should be changed to report external callback |
| 796 // invocation. See r13768 where it was LoadCallbackProperty was removed. | 805 // invocation. See r13768 where it was LoadCallbackProperty was removed. |
| 797 // GetChild(startNode, "get foo"); | 806 // GetChild(startNode, "get foo"); |
| 798 GetChild(startNode, "set foo"); | 807 GetChild(startNode, "set foo"); |
| 799 | 808 |
| 800 cpu_profiler->DeleteAllCpuProfiles(); | 809 cpu_profiler->DeleteAllCpuProfiles(); |
| 801 } | 810 } |
| OLD | NEW |