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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 "function bar() { delay(); }\n" | 459 "function bar() { delay(); }\n" |
460 "function baz() { delay(); }\n" | 460 "function baz() { delay(); }\n" |
461 "function foo() {\n" | 461 "function foo() {\n" |
462 " try {\n" | 462 " try {\n" |
463 " delay();\n" | 463 " delay();\n" |
464 " bar();\n" | 464 " bar();\n" |
465 " delay();\n" | 465 " delay();\n" |
466 " baz();\n" | 466 " baz();\n" |
467 " } catch (e) { }\n" | 467 " } catch (e) { }\n" |
468 "}\n" | 468 "}\n" |
469 "function start() {\n" | 469 "function start(timeout) {\n" |
470 " var start = Date.now();\n" | 470 " var start = Date.now();\n" |
471 " do {\n" | 471 " do {\n" |
472 " foo();\n" | 472 " foo();\n" |
473 " var duration = Date.now() - start;\n" | 473 " var duration = Date.now() - start;\n" |
474 " } while (duration < 200);\n" | 474 " } while (duration < timeout);\n" |
475 " return duration;\n" | 475 " return duration;\n" |
476 "}\n"; | 476 "}\n"; |
477 | 477 |
478 | 478 |
479 // Check that the profile tree for the script above will look like the | 479 // Check that the profile tree for the script above will look like the |
480 // following: | 480 // following: |
481 // | 481 // |
482 // [Top down]: | 482 // [Top down]: |
483 // 1062 0 (root) [-1] | 483 // 1062 0 (root) [-1] |
484 // 1054 0 start [-1] | 484 // 1054 0 start [-1] |
(...skipping 13 matching lines...) Expand all Loading... |
498 v8::HandleScope scope(env->GetIsolate()); | 498 v8::HandleScope scope(env->GetIsolate()); |
499 | 499 |
500 v8::Script::Compile(v8::String::New(cpu_profiler_test_source))->Run(); | 500 v8::Script::Compile(v8::String::New(cpu_profiler_test_source))->Run(); |
501 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 501 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
502 env->Global()->Get(v8::String::New("start"))); | 502 env->Global()->Get(v8::String::New("start"))); |
503 | 503 |
504 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 504 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
505 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | 505 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
506 | 506 |
507 cpu_profiler->StartCpuProfiling(profile_name); | 507 cpu_profiler->StartCpuProfiling(profile_name); |
508 function->Call(env->Global(), 0, 0); | 508 int32_t profiling_interval_ms = 200; |
| 509 #if defined(_WIN32) || defined(_WIN64) |
| 510 // 200ms is not enough on Windows. See |
| 511 // https://code.google.com/p/v8/issues/detail?id=2628 |
| 512 profiling_interval_ms = 500; |
| 513 #endif |
| 514 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; |
| 515 function->Call(env->Global(), ARRAY_SIZE(args), args); |
509 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 516 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
510 | 517 |
511 CHECK_NE(NULL, profile); | 518 CHECK_NE(NULL, profile); |
512 // Dump collected profile to have a better diagnostic in case of failure. | 519 // Dump collected profile to have a better diagnostic in case of failure. |
513 reinterpret_cast<i::CpuProfile*>( | 520 reinterpret_cast<i::CpuProfile*>( |
514 const_cast<v8::CpuProfile*>(profile))->Print(); | 521 const_cast<v8::CpuProfile*>(profile))->Print(); |
515 | 522 |
516 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 523 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
517 | 524 |
518 ScopedVector<v8::Handle<v8::String> > names(3); | 525 ScopedVector<v8::Handle<v8::String> > names(3); |
(...skipping 10 matching lines...) Expand all Loading... |
529 | 536 |
530 const char* barBranch[] = { "bar", "delay", "loop" }; | 537 const char* barBranch[] = { "bar", "delay", "loop" }; |
531 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); | 538 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); |
532 const char* bazBranch[] = { "baz", "delay", "loop" }; | 539 const char* bazBranch[] = { "baz", "delay", "loop" }; |
533 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); | 540 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); |
534 const char* delayBranch[] = { "delay", "loop" }; | 541 const char* delayBranch[] = { "delay", "loop" }; |
535 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch)); | 542 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch)); |
536 | 543 |
537 cpu_profiler->DeleteAllCpuProfiles(); | 544 cpu_profiler->DeleteAllCpuProfiles(); |
538 } | 545 } |
OLD | NEW |