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

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

Issue 18269003: Correctly report stack trace when current function is FunctionApply builtin (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix test 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/sampler.cc ('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 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); 1082 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
1083 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); 1083 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
1084 names[2] = v8::String::New("start"); 1084 names[2] = v8::String::New("start");
1085 names[3] = v8::String::New(i::ProfileGenerator::kUnresolvedFunctionName); 1085 names[3] = v8::String::New(i::ProfileGenerator::kUnresolvedFunctionName);
1086 // Don't allow |bar| and |call| nodes to be at the top level. 1086 // Don't allow |bar| and |call| nodes to be at the top level.
1087 CheckChildrenNames(root, names); 1087 CheckChildrenNames(root, names);
1088 } 1088 }
1089 1089
1090 const v8::CpuProfileNode* startNode = GetChild(root, "start"); 1090 const v8::CpuProfileNode* startNode = GetChild(root, "start");
1091 { 1091 {
1092 ScopedVector<v8::Handle<v8::String> > names(1); 1092 ScopedVector<v8::Handle<v8::String> > names(2);
1093 names[0] = v8::String::New("bar"); 1093 names[0] = v8::String::New("bar");
1094 names[1] = v8::String::New("call");
1094 CheckChildrenNames(startNode, names); 1095 CheckChildrenNames(startNode, names);
1095 } 1096 }
1096 1097
1097 const v8::CpuProfileNode* unresolvedNode = 1098 const v8::CpuProfileNode* unresolvedNode =
1098 FindChild(root, i::ProfileGenerator::kUnresolvedFunctionName); 1099 FindChild(root, i::ProfileGenerator::kUnresolvedFunctionName);
1099 if (unresolvedNode) { 1100 if (unresolvedNode) {
1100 ScopedVector<v8::Handle<v8::String> > names(1); 1101 ScopedVector<v8::Handle<v8::String> > names(1);
1101 names[0] = v8::String::New("call"); 1102 names[0] = v8::String::New("call");
1102 CheckChildrenNames(unresolvedNode, names); 1103 CheckChildrenNames(unresolvedNode, names);
1103 } 1104 }
1104 1105
1105 cpu_profiler->DeleteAllCpuProfiles(); 1106 cpu_profiler->DeleteAllCpuProfiles();
1106 } 1107 }
1107 1108
1109
1110 static const char* function_apply_test_source = "function bar(iterations) {\n"
1111 "}\n"
1112 "function test() {\n"
1113 " bar.apply(this, [10 * 1000]);\n"
1114 "}\n"
1115 "function start(duration) {\n"
1116 " var start = Date.now();\n"
1117 " while (Date.now() - start < duration) {\n"
1118 " try {\n"
1119 " test();\n"
1120 " } catch(e) {}\n"
1121 " }\n"
1122 "}";
1123
1124
1125 // [Top down]:
1126 // 94 0 (root) [-1] #0 1
1127 // 2 2 (garbage collector) [-1] #0 7
1128 // 82 49 start [-1] #16 3
1129 // 1 0 (unresolved function) [-1] #0 8
1130 // 1 1 apply [-1] #0 9
1131 // 32 21 test [-1] #16 4
1132 // 2 2 bar [-1] #16 6
1133 // 9 9 apply [-1] #0 5
1134 // 10 10 (program) [-1] #0 2
1135 TEST(FunctionApplySample) {
1136 LocalContext env;
1137 v8::HandleScope scope(env->GetIsolate());
1138
1139 v8::Script::Compile(v8::String::New(function_apply_test_source))->Run();
1140 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1141 env->Global()->Get(v8::String::New("start")));
1142
1143 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1144 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
1145
1146 cpu_profiler->StartCpuProfiling(profile_name);
1147 int32_t duration_ms = 100;
1148 #if defined(_WIN32) || defined(_WIN64)
1149 // 100ms is not enough on Windows. See
1150 // https://code.google.com/p/v8/issues/detail?id=2628
1151 duration_ms = 400;
1152 #endif
1153 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1154 function->Call(env->Global(), ARRAY_SIZE(args), args);
1155 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
1156
1157 CHECK_NE(NULL, profile);
1158 // Dump collected profile to have a better diagnostic in case of failure.
1159 reinterpret_cast<i::CpuProfile*>(
1160 const_cast<v8::CpuProfile*>(profile))->Print();
1161
1162 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1163 {
1164 ScopedVector<v8::Handle<v8::String> > names(3);
1165 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
1166 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
1167 names[2] = v8::String::New("start");
1168 // Don't allow |test|, |bar| and |apply| nodes to be at the top level.
1169 CheckChildrenNames(root, names);
1170 }
1171
1172 // In case of GC stress tests all samples may be in GC phase and there
1173 // won't be |start| node in the profile.
1174 bool is_gc_stress_testing =
1175 (i::FLAG_gc_interval != -1) || i::FLAG_stress_compaction;
1176
1177 const v8::CpuProfileNode* startNode = FindChild(root, "start");
1178 CHECK(is_gc_stress_testing || startNode);
1179 if (startNode) {
1180 {
1181 ScopedVector<v8::Handle<v8::String> > names(2);
1182 names[0] = v8::String::New("test");
1183 names[1] = v8::String::New(ProfileGenerator::kUnresolvedFunctionName);
1184 CheckChildrenNames(startNode, names);
1185 }
1186
1187 const v8::CpuProfileNode* testNode = FindChild(startNode, "test");
1188 CHECK(is_gc_stress_testing || testNode);
1189 if (testNode) {
1190 ScopedVector<v8::Handle<v8::String> > names(2);
1191 names[0] = v8::String::New("bar");
1192 names[1] = v8::String::New("apply");
1193 CheckChildrenNames(testNode, names);
1194 }
1195
1196 if (const v8::CpuProfileNode* unresolvedNode =
1197 FindChild(startNode, ProfileGenerator::kUnresolvedFunctionName)) {
1198 ScopedVector<v8::Handle<v8::String> > names(1);
1199 names[0] = v8::String::New("apply");
1200 CheckChildrenNames(unresolvedNode, names);
1201 GetChild(unresolvedNode, "apply");
1202 }
1203 }
1204
1205 cpu_profiler->DeleteAllCpuProfiles();
1206 }
OLDNEW
« no previous file with comments | « src/sampler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698