Revision f230a1cf deps/v8/test/cctest/test-cpu-profiler.cc

View differences:

deps/v8/test/cctest/test-cpu-profiler.cc
127 127
TEST(CodeEvents) {
128 128
  CcTest::InitializeVM();
129 129
  LocalContext env;
130
  i::Isolate* isolate = i::Isolate::Current();
130
  i::Isolate* isolate = CcTest::i_isolate();
131 131
  i::Factory* factory = isolate->factory();
132 132
  TestSetup test_setup;
133 133

  
......
196 196
TEST(TickEvents) {
197 197
  TestSetup test_setup;
198 198
  LocalContext env;
199
  i::Isolate* isolate = i::Isolate::Current();
199
  i::Isolate* isolate = CcTest::i_isolate();
200 200
  i::HandleScope scope(isolate);
201 201

  
202 202
  i::Code* frame1_code = CreateCode(&env);
......
254 254
TEST(CrashIfStoppingLastNonExistentProfile) {
255 255
  CcTest::InitializeVM();
256 256
  TestSetup test_setup;
257
  CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
257
  CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler();
258 258
  profiler->StartProfiling("1");
259 259
  profiler->StopProfiling("2");
260 260
  profiler->StartProfiling("1");
......
267 267
TEST(Issue1398) {
268 268
  TestSetup test_setup;
269 269
  LocalContext env;
270
  i::Isolate* isolate = i::Isolate::Current();
270
  i::Isolate* isolate = CcTest::i_isolate();
271 271
  i::HandleScope scope(isolate);
272 272

  
273 273
  i::Code* code = CreateCode(&env);
......
309 309
TEST(DeleteAllCpuProfiles) {
310 310
  CcTest::InitializeVM();
311 311
  TestSetup test_setup;
312
  CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
312
  CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler();
313 313
  CHECK_EQ(0, profiler->GetProfilesCount());
314 314
  profiler->DeleteAllProfiles();
315 315
  CHECK_EQ(0, profiler->GetProfilesCount());
......
396 396
}
397 397

  
398 398

  
399
TEST(GetProfilerWhenIsolateIsNotInitialized) {
400
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
401
  CHECK(i::Isolate::Current()->IsDefaultIsolate());
402
  CHECK(!i::Isolate::Current()->IsInitialized());
403
  CHECK_EQ(NULL, isolate->GetCpuProfiler());
404
  {
405
    v8::Isolate::Scope isolateScope(isolate);
406
    LocalContext env;
407
    v8::HandleScope scope(isolate);
408
    CHECK_NE(NULL, isolate->GetCpuProfiler());
409
    isolate->GetCpuProfiler()->StartCpuProfiling(v8::String::New("Test"));
410
    isolate->GetCpuProfiler()->StopCpuProfiling(v8::String::New("Test"));
411
  }
412
  CHECK(i::Isolate::Current()->IsInitialized());
413
  CHECK_NE(NULL, isolate->GetCpuProfiler());
414
  isolate->Dispose();
415
  CHECK_EQ(NULL, isolate->GetCpuProfiler());
416
}
417

  
418

  
419 399
TEST(ProfileStartEndTime) {
420 400
  LocalContext env;
421 401
  v8::HandleScope scope(env->GetIsolate());
......
495 475
static const v8::CpuProfileNode* GetChild(const v8::CpuProfileNode* node,
496 476
                                          const char* name) {
497 477
  const v8::CpuProfileNode* result = FindChild(node, name);
498
  CHECK(result);
478
  if (!result) {
479
    char buffer[100];
480
    i::OS::SNPrintF(Vector<char>(buffer, ARRAY_SIZE(buffer)),
481
                    "Failed to GetChild: %s", name);
482
    FATAL(buffer);
483
  }
499 484
  return result;
500 485
}
501 486

  
......
610 595
"  } while (++k < count*100*1000);\n"
611 596
"}\n";
612 597

  
613
// Check that the profile tree doesn't contain unexpecte traces:
598
// Check that the profile tree doesn't contain unexpected traces:
614 599
//  - 'loop' can be called only by 'delay'
615 600
//  - 'delay' may be called only by 'start'
616 601
// The profile will look like the following:
......
973 958
  v8::HandleScope scope(env->GetIsolate());
974 959

  
975 960
  // Collect garbage that might have be generated while installing extensions.
976
  HEAP->CollectAllGarbage(Heap::kNoGCFlags);
961
  CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
977 962

  
978 963
  v8::Script::Compile(v8::String::New(call_function_test_source))->Run();
979 964
  v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
......
1101 1086
}
1102 1087

  
1103 1088

  
1104
static const char* js_native_js_test_source = "function foo(iterations) {\n"
1089
static const char* js_native_js_test_source =
1090
"var is_profiling = false;\n"
1091
"function foo(iterations) {\n"
1092
"  if (!is_profiling) {\n"
1093
"    is_profiling = true;\n"
1094
"    startProfiling('my_profile');\n"
1095
"  }\n"
1105 1096
"  var r = 0;\n"
1106 1097
"  for (var i = 0; i < iterations; i++) { r += i; }\n"
1107 1098
"  return r;\n"
......
1133 1124
//    55     1        bar #16 5
1134 1125
//    54    54          foo #16 6
1135 1126
TEST(JsNativeJsSample) {
1136
  LocalContext env;
1127
  const char* extensions[] = { "v8/profiler" };
1128
  v8::ExtensionConfiguration config(1, extensions);
1129
  LocalContext env(&config);
1137 1130
  v8::HandleScope scope(env->GetIsolate());
1138 1131

  
1139 1132
  v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
......
1149 1142
  int32_t duration_ms = 20;
1150 1143
  v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1151 1144
  const v8::CpuProfile* profile =
1152
      RunProfiler(env, function, args, ARRAY_SIZE(args), 50);
1145
      RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
1153 1146

  
1154 1147
  const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1155 1148
  {
......
1177 1170

  
1178 1171

  
1179 1172
static const char* js_native_js_runtime_js_test_source =
1173
"var is_profiling = false;\n"
1180 1174
"function foo(iterations) {\n"
1175
"  if (!is_profiling) {\n"
1176
"    is_profiling = true;\n"
1177
"    startProfiling('my_profile');\n"
1178
"  }\n"
1181 1179
"  var r = 0;\n"
1182 1180
"  for (var i = 0; i < iterations; i++) { r += i; }\n"
1183 1181
"  return r;\n"
......
1204 1202
//    51    51          foo #16 6
1205 1203
//     2     2    (program) #0 2
1206 1204
TEST(JsNativeJsRuntimeJsSample) {
1207
  LocalContext env;
1205
  const char* extensions[] = { "v8/profiler" };
1206
  v8::ExtensionConfiguration config(1, extensions);
1207
  LocalContext env(&config);
1208 1208
  v8::HandleScope scope(env->GetIsolate());
1209 1209

  
1210 1210
  v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
......
1221 1221
  int32_t duration_ms = 20;
1222 1222
  v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1223 1223
  const v8::CpuProfile* profile =
1224
      RunProfiler(env, function, args, ARRAY_SIZE(args), 50);
1224
      RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
1225 1225

  
1226 1226
  const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1227 1227
  ScopedVector<v8::Handle<v8::String> > names(3);
......
1252 1252

  
1253 1253

  
1254 1254
static const char* js_native1_js_native2_js_test_source =
1255
"var is_profiling = false;\n"
1255 1256
"function foo(iterations) {\n"
1257
"  if (!is_profiling) {\n"
1258
"    is_profiling = true;\n"
1259
"    startProfiling('my_profile');\n"
1260
"  }\n"
1256 1261
"  var r = 0;\n"
1257 1262
"  for (var i = 0; i < iterations; i++) { r += i; }\n"
1258 1263
"  return r;\n"
......
1279 1284
//    54    54            foo #16 7
1280 1285
//     2     2    (program) #0 2
1281 1286
TEST(JsNative1JsNative2JsSample) {
1282
  LocalContext env;
1287
  const char* extensions[] = { "v8/profiler" };
1288
  v8::ExtensionConfiguration config(1, extensions);
1289
  LocalContext env(&config);
1283 1290
  v8::HandleScope scope(env->GetIsolate());
1284 1291

  
1285 1292
  v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
......
1301 1308
  int32_t duration_ms = 20;
1302 1309
  v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
1303 1310
  const v8::CpuProfile* profile =
1304
      RunProfiler(env, function, args, ARRAY_SIZE(args), 50);
1311
      RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
1305 1312

  
1306 1313
  const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1307 1314
  ScopedVector<v8::Handle<v8::String> > names(3);
......
1341 1348
  v8::Local<v8::String> profile_name = v8::String::New("my_profile");
1342 1349
  cpu_profiler->StartCpuProfiling(profile_name);
1343 1350

  
1344
  i::Isolate* isolate = i::Isolate::Current();
1351
  i::Isolate* isolate = CcTest::i_isolate();
1345 1352
  i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor();
1346 1353
  processor->AddCurrentStack(isolate);
1347 1354

  
......
1380 1387

  
1381 1388
  cpu_profiler->DeleteAllCpuProfiles();
1382 1389
}
1390

  
1391

  
1392
static void CheckFunctionDetails(const v8::CpuProfileNode* node,
1393
    const char* name, const char* script_name, int script_id,
1394
    int line, int column) {
1395
  CHECK_EQ(v8::String::New(name), node->GetFunctionName());
1396
  CHECK_EQ(v8::String::New(script_name), node->GetScriptResourceName());
1397
  CHECK_EQ(script_id, node->GetScriptId());
1398
  CHECK_EQ(line, node->GetLineNumber());
1399
  CHECK_EQ(column, node->GetColumnNumber());
1400
}
1401

  
1402

  
1403
TEST(FunctionDetails) {
1404
  const char* extensions[] = { "v8/profiler" };
1405
  v8::ExtensionConfiguration config(1, extensions);
1406
  LocalContext env(&config);
1407
  v8::HandleScope handleScope(env->GetIsolate());
1408

  
1409
  v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
1410
  CHECK_EQ(0, profiler->GetProfileCount());
1411
  v8::Handle<v8::Script> script_a = v8::Script::Compile(v8::String::New(
1412
      "    function foo\n() { try { bar(); } catch(e) {} }\n"
1413
      " function bar() { startProfiling(); }\n"), v8::String::New("script_a"));
1414
  script_a->Run();
1415
  v8::Handle<v8::Script> script_b = v8::Script::Compile(v8::String::New(
1416
      "\n\n   function baz() { try { foo(); } catch(e) {} }\n"
1417
      "\n\nbaz();\n"
1418
      "stopProfiling();\n"), v8::String::New("script_b"));
1419
  script_b->Run();
1420
  CHECK_EQ(1, profiler->GetProfileCount());
1421
  const v8::CpuProfile* profile = profiler->GetCpuProfile(0);
1422
  const v8::CpuProfileNode* current = profile->GetTopDownRoot();
1423
  reinterpret_cast<ProfileNode*>(
1424
      const_cast<v8::CpuProfileNode*>(current))->Print(0);
1425
  // The tree should look like this:
1426
  //  0   (root) 0 #1
1427
  //  0    (anonymous function) 19 #2 no reason script_b:1
1428
  //  0      baz 19 #3 TryCatchStatement script_b:3
1429
  //  0        foo 18 #4 TryCatchStatement script_a:2
1430
  //  1          bar 18 #5 no reason script_a:3
1431
  const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1432
  const v8::CpuProfileNode* script = GetChild(root,
1433
      ProfileGenerator::kAnonymousFunctionName);
1434
  CheckFunctionDetails(script, ProfileGenerator::kAnonymousFunctionName,
1435
      "script_b", script_b->GetId(), 1, 1);
1436
  const v8::CpuProfileNode* baz = GetChild(script, "baz");
1437
  CheckFunctionDetails(baz, "baz", "script_b", script_b->GetId(), 3, 16);
1438
  const v8::CpuProfileNode* foo = GetChild(baz, "foo");
1439
  CheckFunctionDetails(foo, "foo", "script_a", script_a->GetId(), 2, 1);
1440
  const v8::CpuProfileNode* bar = GetChild(foo, "bar");
1441
  CheckFunctionDetails(bar, "bar", "script_a", script_a->GetId(), 3, 14);
1442
}

Also available in: Unified diff