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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 &generator, NULL, TimeDelta::FromMicroseconds(100))); | 276 &generator, NULL, TimeDelta::FromMicroseconds(100))); |
277 processor->Start(); | 277 processor->Start(); |
278 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); | 278 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); |
279 | 279 |
280 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); | 280 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); |
281 | 281 |
282 i::TickSample* sample = processor->StartTickSample(); | 282 i::TickSample* sample = processor->StartTickSample(); |
283 sample->pc = code->address(); | 283 sample->pc = code->address(); |
284 sample->tos = 0; | 284 sample->tos = 0; |
285 sample->frames_count = i::TickSample::kMaxFramesCount; | 285 sample->frames_count = i::TickSample::kMaxFramesCount; |
286 for (int i = 0; i < sample->frames_count; ++i) { | 286 for (unsigned i = 0; i < sample->frames_count; ++i) { |
287 sample->stack[i] = code->address(); | 287 sample->stack[i] = code->address(); |
288 } | 288 } |
289 processor->FinishTickSample(); | 289 processor->FinishTickSample(); |
290 | 290 |
291 processor->StopSynchronously(); | 291 processor->StopSynchronously(); |
292 CpuProfile* profile = profiles->StopProfiling(""); | 292 CpuProfile* profile = profiles->StopProfiling(""); |
293 CHECK_NE(NULL, profile); | 293 CHECK_NE(NULL, profile); |
294 | 294 |
295 int actual_depth = 0; | 295 int actual_depth = 0; |
296 const ProfileNode* node = profile->top_down()->root(); | 296 const ProfileNode* node = profile->top_down()->root(); |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "apply"); | 1241 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "apply"); |
1242 CheckChildrenNames(unresolvedNode, names); | 1242 CheckChildrenNames(unresolvedNode, names); |
1243 GetChild(env->GetIsolate(), unresolvedNode, "apply"); | 1243 GetChild(env->GetIsolate(), unresolvedNode, "apply"); |
1244 } | 1244 } |
1245 } | 1245 } |
1246 | 1246 |
1247 profile->Delete(); | 1247 profile->Delete(); |
1248 } | 1248 } |
1249 | 1249 |
1250 | 1250 |
| 1251 static const char* cpu_profiler_deep_stack_test_source = |
| 1252 "function foo(n) {\n" |
| 1253 " if (n)\n" |
| 1254 " foo(n - 1);\n" |
| 1255 " else\n" |
| 1256 " startProfiling('my_profile');\n" |
| 1257 "}\n" |
| 1258 "function start() {\n" |
| 1259 " foo(250);\n" |
| 1260 "}\n"; |
| 1261 |
| 1262 |
| 1263 // Check a deep stack |
| 1264 // |
| 1265 // [Top down]: |
| 1266 // 0 (root) 0 #1 |
| 1267 // 2 (program) 0 #2 |
| 1268 // 0 start 21 #3 no reason |
| 1269 // 0 foo 21 #4 no reason |
| 1270 // 0 foo 21 #5 no reason |
| 1271 // .... |
| 1272 // 0 foo 21 #253 no reason |
| 1273 // 1 startProfiling 0 #254 |
| 1274 TEST(CpuProfileDeepStack) { |
| 1275 v8::HandleScope scope(CcTest::isolate()); |
| 1276 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| 1277 v8::Context::Scope context_scope(env); |
| 1278 |
| 1279 v8::Script::Compile(v8::String::NewFromUtf8( |
| 1280 env->GetIsolate(), cpu_profiler_deep_stack_test_source))->Run(); |
| 1281 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1282 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 1283 |
| 1284 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1285 v8::Local<v8::String> profile_name = |
| 1286 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile"); |
| 1287 function->Call(env->Global(), 0, NULL); |
| 1288 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
| 1289 CHECK_NE(NULL, profile); |
| 1290 // Dump collected profile to have a better diagnostic in case of failure. |
| 1291 reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
| 1292 |
| 1293 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1294 { |
| 1295 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1296 names[0] = v8::String::NewFromUtf8( |
| 1297 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 1298 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 1299 ProfileGenerator::kProgramEntryName); |
| 1300 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 1301 CheckChildrenNames(root, names); |
| 1302 } |
| 1303 |
| 1304 const v8::CpuProfileNode* node = |
| 1305 GetChild(env->GetIsolate(), root, "start"); |
| 1306 for (int i = 0; i < 250; ++i) { |
| 1307 node = GetChild(env->GetIsolate(), node, "foo"); |
| 1308 } |
| 1309 // TODO(alph): |
| 1310 // In theory there must be one more 'foo' and a 'startProfiling' nodes, |
| 1311 // but due to unstable top frame extraction these might be missing. |
| 1312 |
| 1313 profile->Delete(); |
| 1314 } |
| 1315 |
| 1316 |
1251 static const char* js_native_js_test_source = | 1317 static const char* js_native_js_test_source = |
1252 "var is_profiling = false;\n" | 1318 "var is_profiling = false;\n" |
1253 "function foo(iterations) {\n" | 1319 "function foo(iterations) {\n" |
1254 " if (!is_profiling) {\n" | 1320 " if (!is_profiling) {\n" |
1255 " is_profiling = true;\n" | 1321 " is_profiling = true;\n" |
1256 " startProfiling('my_profile');\n" | 1322 " startProfiling('my_profile');\n" |
1257 " }\n" | 1323 " }\n" |
1258 " var r = 0;\n" | 1324 " var r = 0;\n" |
1259 " for (var i = 0; i < iterations; i++) { r += i; }\n" | 1325 " for (var i = 0; i < iterations; i++) { r += i; }\n" |
1260 " return r;\n" | 1326 " return r;\n" |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 inner_profile = NULL; | 1727 inner_profile = NULL; |
1662 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1728 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1663 | 1729 |
1664 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); | 1730 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); |
1665 CHECK(outer_profile); | 1731 CHECK(outer_profile); |
1666 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 1732 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
1667 outer_profile->Delete(); | 1733 outer_profile->Delete(); |
1668 outer_profile = NULL; | 1734 outer_profile = NULL; |
1669 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1735 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1670 } | 1736 } |
OLD | NEW |