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

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

Issue 18478002: Revert "Correctly report callstack when current function is FunctionCall builtin" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 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
« no previous file with comments | « src/profile-generator-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); 1016 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
1017 names[2] = v8::String::New("start"); 1017 names[2] = v8::String::New("start");
1018 // Don't allow |foo| node to be at the top level. 1018 // Don't allow |foo| node to be at the top level.
1019 CheckChildrenNames(root, names); 1019 CheckChildrenNames(root, names);
1020 1020
1021 const v8::CpuProfileNode* startNode = GetChild(root, "start"); 1021 const v8::CpuProfileNode* startNode = GetChild(root, "start");
1022 GetChild(startNode, "foo"); 1022 GetChild(startNode, "foo");
1023 1023
1024 cpu_profiler->DeleteAllCpuProfiles(); 1024 cpu_profiler->DeleteAllCpuProfiles();
1025 } 1025 }
1026
1027
1028 static const char* call_function_test_source = "function bar(iterations) {\n"
1029 "}\n"
1030 "function start(duration) {\n"
1031 " var start = Date.now();\n"
1032 " while (Date.now() - start < duration) {\n"
1033 " try {\n"
1034 " bar.call(this, 10 * 1000);\n"
1035 " } catch(e) {}\n"
1036 " }\n"
1037 "}";
1038
1039
1040 // Test that if we sampled thread when it was inside FunctionCall buitin then
1041 // its caller frame will be '(unresolved function)' as we have no reliable way
1042 // to resolve it.
1043 //
1044 // [Top down]:
1045 // 96 0 (root) [-1] #1
1046 // 1 1 (garbage collector) [-1] #4
1047 // 5 0 (unresolved function) [-1] #5
1048 // 5 5 call [-1] #6
1049 // 71 70 start [-1] #3
1050 // 1 1 bar [-1] #7
1051 // 19 19 (program) [-1] #2
1052 TEST(FunctionCallSample) {
1053 LocalContext env;
1054 v8::HandleScope scope(env->GetIsolate());
1055
1056 v8::Script::Compile(v8::String::New(call_function_test_source))->Run();
1057 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1058 env->Global()->Get(v8::String::New("start")));
1059
1060 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1061 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
1062
1063 cpu_profiler->StartCpuProfiling(profile_name);
1064 int32_t duration_ms = 100;
1065 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1066 function->Call(env->Global(), ARRAY_SIZE(args), args);
1067 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
1068
1069 CHECK_NE(NULL, profile);
1070 // Dump collected profile to have a better diagnostic in case of failure.
1071 reinterpret_cast<i::CpuProfile*>(
1072 const_cast<v8::CpuProfile*>(profile))->Print();
1073
1074 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1075 {
1076 ScopedVector<v8::Handle<v8::String> > names(4);
1077 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
1078 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
1079 names[2] = v8::String::New("start");
1080 names[3] = v8::String::New(i::ProfileGenerator::kUnresolvedFunctionName);
1081 // Don't allow |bar| and |call| nodes to be at the top level.
1082 CheckChildrenNames(root, names);
1083 }
1084
1085 const v8::CpuProfileNode* startNode = GetChild(root, "start");
1086 {
1087 ScopedVector<v8::Handle<v8::String> > names(1);
1088 names[0] = v8::String::New("bar");
1089 CheckChildrenNames(startNode, names);
1090 }
1091
1092 const v8::CpuProfileNode* unresolvedNode =
1093 FindChild(root, i::ProfileGenerator::kUnresolvedFunctionName);
1094 if (unresolvedNode) {
1095 ScopedVector<v8::Handle<v8::String> > names(1);
1096 names[0] = v8::String::New("call");
1097 CheckChildrenNames(unresolvedNode, names);
1098 }
1099
1100 cpu_profiler->DeleteAllCpuProfiles();
1101 }
1102
OLDNEW
« no previous file with comments | « src/profile-generator-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698