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

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

Issue 19775017: Fix call stack sampling for the case when native callback invokes JS function (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed test failure in debug mode 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 | « test/cctest/test-api.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 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 ScopedVector<v8::Handle<v8::String> > names(1); 1074 ScopedVector<v8::Handle<v8::String> > names(1);
1075 names[0] = v8::String::New("apply"); 1075 names[0] = v8::String::New("apply");
1076 CheckChildrenNames(unresolvedNode, names); 1076 CheckChildrenNames(unresolvedNode, names);
1077 GetChild(unresolvedNode, "apply"); 1077 GetChild(unresolvedNode, "apply");
1078 } 1078 }
1079 } 1079 }
1080 1080
1081 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 1081 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1082 cpu_profiler->DeleteAllCpuProfiles(); 1082 cpu_profiler->DeleteAllCpuProfiles();
1083 } 1083 }
1084
1085
1086 static const char* js_native_js_test_source = "function foo(iterations) {\n"
1087 " var r = 0;\n"
1088 " for (var i = 0; i < iterations; i++) { r += i; }\n"
1089 " return r;\n"
1090 "}\n"
1091 "function bar(iterations) {\n"
1092 " try { foo(iterations); } catch(e) {}\n"
1093 "}\n"
1094 "function start(duration) {\n"
1095 " var start = Date.now();\n"
1096 " while (Date.now() - start < duration) {\n"
1097 " try {\n"
1098 " CallJsFunction(bar, 10 * 1000);\n"
1099 " } catch(e) {}\n"
1100 " }\n"
1101 "}";
1102
1103 static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) {
1104 v8::Handle<v8::Function> function = info[0].As<v8::Function>();
1105 v8::Handle<v8::Value> argv[] = { info[1] };
1106 function->Call(info.This(), ARRAY_SIZE(argv), argv);
1107 }
1108
1109
1110 // [Top down]:
1111 // 58 0 (root) #0 1
1112 // 2 2 (program) #0 2
1113 // 56 1 start #16 3
1114 // 55 0 CallJsFunction #0 4
1115 // 55 1 bar #16 5
1116 // 54 54 foo #16 6
1117 TEST(JsNativeJsSample) {
1118 LocalContext env;
1119 v8::HandleScope scope(env->GetIsolate());
1120
1121 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1122 CallJsFunction);
1123 v8::Local<v8::Function> func = func_template->GetFunction();
1124 func->SetName(v8::String::New("CallJsFunction"));
1125 env->Global()->Set(v8::String::New("CallJsFunction"), func);
1126
1127 v8::Script::Compile(v8::String::New(js_native_js_test_source))->Run();
1128 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1129 env->Global()->Get(v8::String::New("start")));
1130
1131 int32_t duration_ms = 20;
1132 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1133 const v8::CpuProfile* profile =
1134 RunProfiler(env, function, args, ARRAY_SIZE(args), 50);
1135
1136 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1137 {
1138 ScopedVector<v8::Handle<v8::String> > names(3);
1139 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
1140 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
1141 names[2] = v8::String::New("start");
1142 CheckChildrenNames(root, names);
1143 }
1144
1145 const v8::CpuProfileNode* startNode = GetChild(root, "start");
1146 CHECK_EQ(1, startNode->GetChildrenCount());
1147 const v8::CpuProfileNode* nativeFunctionNode =
1148 GetChild(startNode, "CallJsFunction");
1149
1150 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount());
1151 const v8::CpuProfileNode* barNode = GetChild(nativeFunctionNode, "bar");
1152
1153 CHECK_EQ(1, barNode->GetChildrenCount());
1154 GetChild(barNode, "foo");
1155
1156 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1157 cpu_profiler->DeleteAllCpuProfiles();
1158 }
1159
1160
1161 static const char* js_native_js_runtime_js_test_source =
1162 "function foo(iterations) {\n"
1163 " var r = 0;\n"
1164 " for (var i = 0; i < iterations; i++) { r += i; }\n"
1165 " return r;\n"
1166 "}\n"
1167 "var bound = foo.bind(this);\n"
1168 "function bar(iterations) {\n"
1169 " try { bound(iterations); } catch(e) {}\n"
1170 "}\n"
1171 "function start(duration) {\n"
1172 " var start = Date.now();\n"
1173 " while (Date.now() - start < duration) {\n"
1174 " try {\n"
1175 " CallJsFunction(bar, 10 * 1000);\n"
1176 " } catch(e) {}\n"
1177 " }\n"
1178 "}";
1179
1180
1181 // [Top down]:
1182 // 57 0 (root) #0 1
1183 // 55 1 start #16 3
1184 // 54 0 CallJsFunction #0 4
1185 // 54 3 bar #16 5
1186 // 51 51 foo #16 6
1187 // 2 2 (program) #0 2
1188 TEST(JsNativeJsRuntimeJsSample) {
1189 LocalContext env;
1190 v8::HandleScope scope(env->GetIsolate());
1191
1192 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1193 CallJsFunction);
1194 v8::Local<v8::Function> func = func_template->GetFunction();
1195 func->SetName(v8::String::New("CallJsFunction"));
1196 env->Global()->Set(v8::String::New("CallJsFunction"), func);
1197
1198 v8::Script::Compile(v8::String::New(js_native_js_runtime_js_test_source))->
1199 Run();
1200 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1201 env->Global()->Get(v8::String::New("start")));
1202
1203 int32_t duration_ms = 20;
1204 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1205 const v8::CpuProfile* profile =
1206 RunProfiler(env, function, args, ARRAY_SIZE(args), 50);
1207
1208 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1209 ScopedVector<v8::Handle<v8::String> > names(3);
1210 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
1211 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
1212 names[2] = v8::String::New("start");
1213 CheckChildrenNames(root, names);
1214
1215 const v8::CpuProfileNode* startNode = GetChild(root, "start");
1216 CHECK_EQ(1, startNode->GetChildrenCount());
1217 const v8::CpuProfileNode* nativeFunctionNode =
1218 GetChild(startNode, "CallJsFunction");
1219
1220 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount());
1221 const v8::CpuProfileNode* barNode = GetChild(nativeFunctionNode, "bar");
1222
1223 CHECK_EQ(1, barNode->GetChildrenCount());
1224 GetChild(barNode, "foo");
1225
1226 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1227 cpu_profiler->DeleteAllCpuProfiles();
1228 }
1229
1230
1231 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) {
1232 CallJsFunction(info);
1233 }
1234
1235
1236 static const char* js_native1_js_native2_js_test_source =
1237 "function foo(iterations) {\n"
1238 " var r = 0;\n"
1239 " for (var i = 0; i < iterations; i++) { r += i; }\n"
1240 " return r;\n"
1241 "}\n"
1242 "function bar(iterations) {\n"
1243 " CallJsFunction2(foo, iterations);\n"
1244 "}\n"
1245 "function start(duration) {\n"
1246 " var start = Date.now();\n"
1247 " while (Date.now() - start < duration) {\n"
1248 " try {\n"
1249 " CallJsFunction1(bar, 10 * 1000);\n"
1250 " } catch(e) {}\n"
1251 " }\n"
1252 "}";
1253
1254
1255 // [Top down]:
1256 // 57 0 (root) #0 1
1257 // 55 1 start #16 3
1258 // 54 0 CallJsFunction1 #0 4
1259 // 54 0 bar #16 5
1260 // 54 0 CallJsFunction2 #0 6
1261 // 54 54 foo #16 7
1262 // 2 2 (program) #0 2
1263 TEST(JsNative1JsNative2JsSample) {
1264 LocalContext env;
1265 v8::HandleScope scope(env->GetIsolate());
1266
1267 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1268 CallJsFunction);
1269 v8::Local<v8::Function> func1 = func_template->GetFunction();
1270 func1->SetName(v8::String::New("CallJsFunction1"));
1271 env->Global()->Set(v8::String::New("CallJsFunction1"), func1);
1272
1273 v8::Local<v8::Function> func2 = v8::FunctionTemplate::New(
1274 CallJsFunction2)->GetFunction();
1275 func2->SetName(v8::String::New("CallJsFunction2"));
1276 env->Global()->Set(v8::String::New("CallJsFunction2"), func2);
1277
1278 v8::Script::Compile(v8::String::New(js_native1_js_native2_js_test_source))->
1279 Run();
1280 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1281 env->Global()->Get(v8::String::New("start")));
1282
1283 int32_t duration_ms = 20;
1284 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1285 const v8::CpuProfile* profile =
1286 RunProfiler(env, function, args, ARRAY_SIZE(args), 50);
1287
1288 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1289 ScopedVector<v8::Handle<v8::String> > names(3);
1290 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
1291 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
1292 names[2] = v8::String::New("start");
1293 CheckChildrenNames(root, names);
1294
1295 const v8::CpuProfileNode* startNode = GetChild(root, "start");
1296 CHECK_EQ(1, startNode->GetChildrenCount());
1297 const v8::CpuProfileNode* nativeNode1 =
1298 GetChild(startNode, "CallJsFunction1");
1299
1300 CHECK_EQ(1, nativeNode1->GetChildrenCount());
1301 const v8::CpuProfileNode* barNode = GetChild(nativeNode1, "bar");
1302
1303 CHECK_EQ(1, barNode->GetChildrenCount());
1304 const v8::CpuProfileNode* nativeNode2 = GetChild(barNode, "CallJsFunction2");
1305
1306 CHECK_EQ(1, nativeNode2->GetChildrenCount());
1307 GetChild(nativeNode2, "foo");
1308
1309 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1310 cpu_profiler->DeleteAllCpuProfiles();
1311 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698