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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 v8::Local<v8::String> profile_name = v8::String::New("test"); | 404 v8::Local<v8::String> profile_name = v8::String::New("test"); |
405 cpu_profiler->StartCpuProfiling(profile_name); | 405 cpu_profiler->StartCpuProfiling(profile_name); |
406 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 406 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
407 CHECK(profile->GetStartTime() <= profile->GetEndTime()); | 407 CHECK(profile->GetStartTime() <= profile->GetEndTime()); |
408 } | 408 } |
409 | 409 |
410 | 410 |
411 static const v8::CpuProfile* RunProfiler( | 411 static const v8::CpuProfile* RunProfiler( |
412 LocalContext& env, v8::Handle<v8::Function> function, | 412 LocalContext& env, v8::Handle<v8::Function> function, |
413 v8::Handle<v8::Value> argv[], int argc, | 413 v8::Handle<v8::Value> argv[], int argc, |
414 unsigned min_js_samples, bool script_will_start_profiler = false) { | 414 unsigned min_js_samples) { |
415 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 415 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
416 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | 416 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
417 | 417 |
418 if (!script_will_start_profiler) { | 418 cpu_profiler->StartCpuProfiling(profile_name); |
419 cpu_profiler->StartCpuProfiling(profile_name); | |
420 } | |
421 | 419 |
422 i::Sampler* sampler = | 420 i::Sampler* sampler = |
423 reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler(); | 421 reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler(); |
424 sampler->StartCountingSamples(); | 422 sampler->StartCountingSamples(); |
425 do { | 423 do { |
426 function->Call(env->Global(), argc, argv); | 424 function->Call(env->Global(), argc, argv); |
427 } while (sampler->js_and_external_sample_count() < min_js_samples); | 425 } while (sampler->js_and_external_sample_count() < min_js_samples); |
428 | 426 |
429 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 427 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
430 | 428 |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 func->SetName(v8::String::New("CallJsFunction")); | 1135 func->SetName(v8::String::New("CallJsFunction")); |
1138 env->Global()->Set(v8::String::New("CallJsFunction"), func); | 1136 env->Global()->Set(v8::String::New("CallJsFunction"), func); |
1139 | 1137 |
1140 v8::Script::Compile(v8::String::New(js_native_js_test_source))->Run(); | 1138 v8::Script::Compile(v8::String::New(js_native_js_test_source))->Run(); |
1141 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1139 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
1142 env->Global()->Get(v8::String::New("start"))); | 1140 env->Global()->Get(v8::String::New("start"))); |
1143 | 1141 |
1144 int32_t duration_ms = 20; | 1142 int32_t duration_ms = 20; |
1145 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 1143 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
1146 const v8::CpuProfile* profile = | 1144 const v8::CpuProfile* profile = |
1147 RunProfiler(env, function, args, ARRAY_SIZE(args), 10, true); | 1145 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
1148 | 1146 |
1149 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1147 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1150 { | 1148 { |
1151 ScopedVector<v8::Handle<v8::String> > names(3); | 1149 ScopedVector<v8::Handle<v8::String> > names(3); |
1152 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1150 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
1153 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1151 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
1154 names[2] = v8::String::New("start"); | 1152 names[2] = v8::String::New("start"); |
1155 CheckChildrenNames(root, names); | 1153 CheckChildrenNames(root, names); |
1156 } | 1154 } |
1157 | 1155 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 env->Global()->Set(v8::String::New("CallJsFunction"), func); | 1214 env->Global()->Set(v8::String::New("CallJsFunction"), func); |
1217 | 1215 |
1218 v8::Script::Compile(v8::String::New(js_native_js_runtime_js_test_source))-> | 1216 v8::Script::Compile(v8::String::New(js_native_js_runtime_js_test_source))-> |
1219 Run(); | 1217 Run(); |
1220 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1218 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
1221 env->Global()->Get(v8::String::New("start"))); | 1219 env->Global()->Get(v8::String::New("start"))); |
1222 | 1220 |
1223 int32_t duration_ms = 20; | 1221 int32_t duration_ms = 20; |
1224 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 1222 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
1225 const v8::CpuProfile* profile = | 1223 const v8::CpuProfile* profile = |
1226 RunProfiler(env, function, args, ARRAY_SIZE(args), 10, true); | 1224 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
1227 | 1225 |
1228 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1226 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1229 ScopedVector<v8::Handle<v8::String> > names(3); | 1227 ScopedVector<v8::Handle<v8::String> > names(3); |
1230 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1228 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
1231 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1229 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
1232 names[2] = v8::String::New("start"); | 1230 names[2] = v8::String::New("start"); |
1233 CheckChildrenNames(root, names); | 1231 CheckChildrenNames(root, names); |
1234 | 1232 |
1235 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 1233 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
1236 CHECK_EQ(1, startNode->GetChildrenCount()); | 1234 CHECK_EQ(1, startNode->GetChildrenCount()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 env->Global()->Set(v8::String::New("CallJsFunction2"), func2); | 1301 env->Global()->Set(v8::String::New("CallJsFunction2"), func2); |
1304 | 1302 |
1305 v8::Script::Compile(v8::String::New(js_native1_js_native2_js_test_source))-> | 1303 v8::Script::Compile(v8::String::New(js_native1_js_native2_js_test_source))-> |
1306 Run(); | 1304 Run(); |
1307 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1305 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
1308 env->Global()->Get(v8::String::New("start"))); | 1306 env->Global()->Get(v8::String::New("start"))); |
1309 | 1307 |
1310 int32_t duration_ms = 20; | 1308 int32_t duration_ms = 20; |
1311 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 1309 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
1312 const v8::CpuProfile* profile = | 1310 const v8::CpuProfile* profile = |
1313 RunProfiler(env, function, args, ARRAY_SIZE(args), 10, true); | 1311 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
1314 | 1312 |
1315 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1313 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1316 ScopedVector<v8::Handle<v8::String> > names(3); | 1314 ScopedVector<v8::Handle<v8::String> > names(3); |
1317 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1315 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
1318 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1316 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
1319 names[2] = v8::String::New("start"); | 1317 names[2] = v8::String::New("start"); |
1320 CheckChildrenNames(root, names); | 1318 CheckChildrenNames(root, names); |
1321 | 1319 |
1322 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 1320 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
1323 CHECK_EQ(1, startNode->GetChildrenCount()); | 1321 CHECK_EQ(1, startNode->GetChildrenCount()); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 ProfileGenerator::kAnonymousFunctionName); | 1433 ProfileGenerator::kAnonymousFunctionName); |
1436 CheckFunctionDetails(script, ProfileGenerator::kAnonymousFunctionName, | 1434 CheckFunctionDetails(script, ProfileGenerator::kAnonymousFunctionName, |
1437 "script_b", script_b->GetId(), 1, 1); | 1435 "script_b", script_b->GetId(), 1, 1); |
1438 const v8::CpuProfileNode* baz = GetChild(script, "baz"); | 1436 const v8::CpuProfileNode* baz = GetChild(script, "baz"); |
1439 CheckFunctionDetails(baz, "baz", "script_b", script_b->GetId(), 3, 16); | 1437 CheckFunctionDetails(baz, "baz", "script_b", script_b->GetId(), 3, 16); |
1440 const v8::CpuProfileNode* foo = GetChild(baz, "foo"); | 1438 const v8::CpuProfileNode* foo = GetChild(baz, "foo"); |
1441 CheckFunctionDetails(foo, "foo", "script_a", script_a->GetId(), 2, 1); | 1439 CheckFunctionDetails(foo, "foo", "script_a", script_a->GetId(), 2, 1); |
1442 const v8::CpuProfileNode* bar = GetChild(foo, "bar"); | 1440 const v8::CpuProfileNode* bar = GetChild(foo, "bar"); |
1443 CheckFunctionDetails(bar, "bar", "script_a", script_a->GetId(), 3, 14); | 1441 CheckFunctionDetails(bar, "bar", "script_a", script_a->GetId(), 3, 14); |
1444 } | 1442 } |
OLD | NEW |