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

Side by Side Diff: test/cctest/test-cpu-profiler.cc

Issue 17642009: CPUProfiler: propagate scriptId to the front-end (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: unnecessary line was removed Created 7 years, 6 months 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 | Annotate | Revision Log
OLDNEW
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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 const char* names[], int length) { 461 const char* names[], int length) {
462 for (int i = 0; i < length; i++) { 462 for (int i = 0; i < length; i++) {
463 const char* name = names[i]; 463 const char* name = names[i];
464 node = GetChild(node, name); 464 node = GetChild(node, name);
465 int expectedChildrenCount = (i == length - 1) ? 0 : 1; 465 int expectedChildrenCount = (i == length - 1) ? 0 : 1;
466 CHECK_EQ(expectedChildrenCount, node->GetChildrenCount()); 466 CHECK_EQ(expectedChildrenCount, node->GetChildrenCount());
467 } 467 }
468 } 468 }
469 469
470 470
471 static void CheckScriptIds(int scriptId, const v8::CpuProfileNode* node) {
472 v8::String::Utf8Value function_name(node->GetFunctionName());
473 if (function_name.length() && (*function_name)[0] != '(')
yurys 2013/06/25 09:16:55 Missing {}
474 CHECK_EQ(scriptId, node->GetScriptId());
475 int length = node->GetChildrenCount();
476 for (int i = 0; i < length; i++) {
477 CheckScriptIds(scriptId, node->GetChild(i));
478 }
479 }
480
481
471 static const char* cpu_profiler_test_source = "function loop(timeout) {\n" 482 static const char* cpu_profiler_test_source = "function loop(timeout) {\n"
472 " this.mmm = 0;\n" 483 " this.mmm = 0;\n"
473 " var start = Date.now();\n" 484 " var start = Date.now();\n"
474 " while (Date.now() - start < timeout) {\n" 485 " while (Date.now() - start < timeout) {\n"
475 " var n = 100*1000;\n" 486 " var n = 100*1000;\n"
476 " while(n > 1) {\n" 487 " while(n > 1) {\n"
477 " n--;\n" 488 " n--;\n"
478 " this.mmm += n * n * n;\n" 489 " this.mmm += n * n * n;\n"
479 " }\n" 490 " }\n"
480 " }\n" 491 " }\n"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 // 522 522 loop [-1] 525 // 522 522 loop [-1]
515 // 263 0 bar [-1] 526 // 263 0 bar [-1]
516 // 263 1 delay [-1] 527 // 263 1 delay [-1]
517 // 262 262 loop [-1] 528 // 262 262 loop [-1]
518 // 2 2 (program) [-1] 529 // 2 2 (program) [-1]
519 // 6 6 (garbage collector) [-1] 530 // 6 6 (garbage collector) [-1]
520 TEST(CollectCpuProfile) { 531 TEST(CollectCpuProfile) {
521 LocalContext env; 532 LocalContext env;
522 v8::HandleScope scope(env->GetIsolate()); 533 v8::HandleScope scope(env->GetIsolate());
523 534
524 v8::Script::Compile(v8::String::New(cpu_profiler_test_source))->Run(); 535 v8::Handle<v8::Script> script =
536 v8::Script::Compile(v8::String::New(cpu_profiler_test_source));
537 script->Run();
525 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 538 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
526 env->Global()->Get(v8::String::New("start"))); 539 env->Global()->Get(v8::String::New("start")));
527 540
528 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 541 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
529 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); 542 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
530 543
531 cpu_profiler->StartCpuProfiling(profile_name); 544 cpu_profiler->StartCpuProfiling(profile_name);
532 int32_t profiling_interval_ms = 200; 545 int32_t profiling_interval_ms = 200;
533 #if defined(_WIN32) || defined(_WIN64) 546 #if defined(_WIN32) || defined(_WIN64)
534 // 200ms is not enough on Windows. See 547 // 200ms is not enough on Windows. See
(...skipping 22 matching lines...) Expand all
557 570
558 const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo"); 571 const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo");
559 CHECK_EQ(3, fooNode->GetChildrenCount()); 572 CHECK_EQ(3, fooNode->GetChildrenCount());
560 573
561 const char* barBranch[] = { "bar", "delay", "loop" }; 574 const char* barBranch[] = { "bar", "delay", "loop" };
562 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); 575 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch));
563 const char* bazBranch[] = { "baz", "delay", "loop" }; 576 const char* bazBranch[] = { "baz", "delay", "loop" };
564 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); 577 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch));
565 const char* delayBranch[] = { "delay", "loop" }; 578 const char* delayBranch[] = { "delay", "loop" };
566 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch)); 579 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch));
580 CheckScriptIds(script->Id()->ToInt32()->Value(), root);
yurys 2013/06/25 09:16:55 Would be nice to have additional test for a profil
567 581
568 cpu_profiler->DeleteAllCpuProfiles(); 582 cpu_profiler->DeleteAllCpuProfiles();
569 } 583 }
570 584
571 585
572 586
573 static const char* cpu_profiler_test_source2 = "function loop() {}\n" 587 static const char* cpu_profiler_test_source2 = "function loop() {}\n"
574 "function delay() { loop(); }\n" 588 "function delay() { loop(); }\n"
575 "function start(count) {\n" 589 "function start(count) {\n"
576 " var k = 0;\n" 590 " var k = 0;\n"
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 reinterpret_cast<i::CpuProfile*>( 921 reinterpret_cast<i::CpuProfile*>(
908 const_cast<v8::CpuProfile*>(profile))->Print(); 922 const_cast<v8::CpuProfile*>(profile))->Print();
909 923
910 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 924 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
911 GetChild(root, "start"); 925 GetChild(root, "start");
912 const v8::CpuProfileNode* startNode = GetChild(root, "start"); 926 const v8::CpuProfileNode* startNode = GetChild(root, "start");
913 GetChild(startNode, "fooMethod"); 927 GetChild(startNode, "fooMethod");
914 928
915 cpu_profiler->DeleteAllCpuProfiles(); 929 cpu_profiler->DeleteAllCpuProfiles();
916 } 930 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698