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

Unified Diff: test/cctest/test-cpu-profiler.cc

Issue 1665303004: Unflake CPU profiler tests. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« test/cctest/profiler-extension.cc ('K') | « test/cctest/profiler-extension.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-cpu-profiler.cc
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc
index cedec3858e88251eea6fc4b8e9a67ac520292336..4b79f27bf94060813f943429f8cc9f074d0a18c7 100644
--- a/test/cctest/test-cpu-profiler.cc
+++ b/test/cctest/test-cpu-profiler.cc
@@ -417,11 +417,10 @@ TEST(ProfileStartEndTime) {
CHECK(profile->GetStartTime() <= profile->GetEndTime());
}
-
static v8::CpuProfile* RunProfiler(v8::Local<v8::Context> env,
v8::Local<v8::Function> function,
v8::Local<v8::Value> argv[], int argc,
- unsigned min_js_samples,
+ unsigned min_js_samples = 0,
bool collect_samples = false) {
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
v8::Local<v8::String> profile_name = v8_str("my_profile");
@@ -446,47 +445,6 @@ static v8::CpuProfile* RunProfiler(v8::Local<v8::Context> env,
}
-static bool ContainsString(v8::Local<v8::Context> context,
- v8::Local<v8::String> string,
- const Vector<v8::Local<v8::String> >& vector) {
- for (int i = 0; i < vector.length(); i++) {
- if (string->Equals(context, vector[i]).FromJust()) return true;
- }
- return false;
-}
-
-
-static void CheckChildrenNames(v8::Local<v8::Context> context,
- const v8::CpuProfileNode* node,
- const Vector<v8::Local<v8::String> >& names) {
- int count = node->GetChildrenCount();
- for (int i = 0; i < count; i++) {
- v8::Local<v8::String> name = node->GetChild(i)->GetFunctionName();
- if (!ContainsString(context, name, names)) {
- char buffer[100];
- i::SNPrintF(Vector<char>(buffer, arraysize(buffer)),
- "Unexpected child '%s' found in '%s'",
- *v8::String::Utf8Value(name),
- *v8::String::Utf8Value(node->GetFunctionName()));
- FATAL(buffer);
- }
- // Check that there are no duplicates.
- for (int j = 0; j < count; j++) {
- if (j == i) continue;
- if (name->Equals(context, node->GetChild(j)->GetFunctionName())
- .FromJust()) {
- char buffer[100];
- i::SNPrintF(Vector<char>(buffer, arraysize(buffer)),
- "Second child with the same name '%s' found in '%s'",
- *v8::String::Utf8Value(name),
- *v8::String::Utf8Value(node->GetFunctionName()));
- FATAL(buffer);
- }
- }
- }
-}
-
-
static const v8::CpuProfileNode* FindChild(v8::Local<v8::Context> context,
const v8::CpuProfileNode* node,
const char* name) {
@@ -522,8 +480,6 @@ static void CheckSimpleBranch(v8::Local<v8::Context> context,
for (int i = 0; i < length; i++) {
const char* name = names[i];
node = GetChild(context, node, name);
- int expectedChildrenCount = (i == length - 1) ? 0 : 1;
- CHECK_EQ(expectedChildrenCount, node->GetChildrenCount());
}
}
@@ -542,37 +498,27 @@ static void CallCollectSample(const v8::FunctionCallbackInfo<v8::Value>& info) {
info.GetIsolate()->GetCpuProfiler()->CollectSample();
}
-static const char* cpu_profiler_test_source = "function loop(timeout) {\n"
-" this.mmm = 0;\n"
-" var start = Date.now();\n"
-" while (Date.now() - start < timeout) {\n"
-" var n = 100*1000;\n"
-" while(n > 1) {\n"
-" n--;\n"
-" this.mmm += n * n * n;\n"
-" }\n"
-" }\n"
-"}\n"
-"function delay() { try { loop(10); } catch(e) { } }\n"
-"function bar() { delay(); }\n"
-"function baz() { delay(); }\n"
-"function foo() {\n"
-" try {\n"
-" delay();\n"
-" bar();\n"
-" delay();\n"
-" baz();\n"
-" } catch (e) { }\n"
-"}\n"
-"function start(timeout) {\n"
-" var start = Date.now();\n"
-" do {\n"
-" foo();\n"
-" var duration = Date.now() - start;\n"
-" } while (duration < timeout);\n"
-" return duration;\n"
-"}\n";
-
+static const char* cpu_profiler_test_source =
+ "function loop(timeout) {\n"
+ " var start = Date.now();\n"
+ " while (Date.now() - start < timeout) {\n"
+ " collectSample();\n"
+ " }\n"
+ "}\n"
+ "function delay() { try { loop(10); } catch(e) { } }\n"
+ "function bar() { delay(); }\n"
+ "function baz() { delay(); }\n"
+ "function foo() {\n"
+ " try {\n"
+ " delay();\n"
+ " bar();\n"
+ " delay();\n"
+ " baz();\n"
+ " } catch (e) { }\n"
+ "}\n"
+ "function start() {\n"
+ " try { foo(); } catch (e) { }\n"
+ "}\n";
// Check that the profile tree for the script above will look like the
// following:
@@ -592,59 +538,44 @@ static const char* cpu_profiler_test_source = "function loop(timeout) {\n"
// 2 2 (program) [-1]
// 6 6 (garbage collector) [-1]
TEST(CollectCpuProfile) {
- LocalContext env;
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
+ v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
+ v8::Context::Scope context_scope(env);
CompileRun(cpu_profiler_test_source);
- v8::Local<v8::Function> function = GetFunction(env.local(), "start");
+ v8::Local<v8::Function> function = GetFunction(env, "start");
- int32_t profiling_interval_ms = 200;
- v8::Local<v8::Value> args[] = {
- v8::Integer::New(env->GetIsolate(), profiling_interval_ms)};
- v8::CpuProfile* profile =
- RunProfiler(env.local(), function, args, arraysize(args), 200);
- function->Call(env.local(), env->Global(), arraysize(args), args)
- .ToLocalChecked();
+ v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
- ScopedVector<v8::Local<v8::String> > names(3);
- names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
- names[1] = v8_str(ProfileGenerator::kProgramEntryName);
- names[2] = v8_str("start");
- CheckChildrenNames(env.local(), root, names);
-
- const v8::CpuProfileNode* startNode = GetChild(env.local(), root, "start");
- CHECK_EQ(1, startNode->GetChildrenCount());
-
- const v8::CpuProfileNode* fooNode = GetChild(env.local(), startNode, "foo");
- CHECK_EQ(3, fooNode->GetChildrenCount());
+ const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
+ const v8::CpuProfileNode* fooNode = GetChild(env, startNode, "foo");
const char* barBranch[] = { "bar", "delay", "loop" };
- CheckSimpleBranch(env.local(), fooNode, barBranch, arraysize(barBranch));
+ CheckSimpleBranch(env, fooNode, barBranch, arraysize(barBranch));
const char* bazBranch[] = { "baz", "delay", "loop" };
- CheckSimpleBranch(env.local(), fooNode, bazBranch, arraysize(bazBranch));
+ CheckSimpleBranch(env, fooNode, bazBranch, arraysize(bazBranch));
const char* delayBranch[] = { "delay", "loop" };
- CheckSimpleBranch(env.local(), fooNode, delayBranch, arraysize(delayBranch));
+ CheckSimpleBranch(env, fooNode, delayBranch, arraysize(delayBranch));
profile->Delete();
}
-
static const char* hot_deopt_no_frame_entry_test_source =
-"function foo(a, b) {\n"
-" try {\n"
-" return a + b;\n"
-" } catch (e) { }\n"
-"}\n"
-"function start(timeout) {\n"
-" var start = Date.now();\n"
-" do {\n"
-" for (var i = 1; i < 1000; ++i) foo(1, i);\n"
-" var duration = Date.now() - start;\n"
-" } while (duration < timeout);\n"
-" return duration;\n"
-"}\n";
+ "function foo(a, b) {\n"
+ " try {\n"
+ " return a + b;\n"
+ " } catch (e) { }\n"
+ "}\n"
+ "function start(timeout) {\n"
+ " var start = Date.now();\n"
+ " do {\n"
+ " for (var i = 1; i < 1000; ++i) foo(1, i);\n"
+ " var duration = Date.now() - start;\n"
+ " } while (duration < timeout);\n"
+ " return duration;\n"
+ "}\n";
// Check that the profile tree for the script above will look like the
// following:
@@ -670,22 +601,14 @@ TEST(HotDeoptNoFrameEntry) {
v8::Local<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), profiling_interval_ms)};
v8::CpuProfile* profile =
- RunProfiler(env.local(), function, args, arraysize(args), 200);
+ RunProfiler(env.local(), function, args, arraysize(args), 2000);
function->Call(env.local(), env->Global(), arraysize(args), args)
.ToLocalChecked();
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
-
- ScopedVector<v8::Local<v8::String> > names(3);
- names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
- names[1] = v8_str(ProfileGenerator::kProgramEntryName);
- names[2] = v8_str("start");
- CheckChildrenNames(env.local(), root, names);
-
const v8::CpuProfileNode* startNode = GetChild(env.local(), root, "start");
- CHECK_EQ(1, startNode->GetChildrenCount());
-
GetChild(env.local(), startNode, "foo");
+ CHECK(!FindChild(env.local(), root, "foo"));
profile->Delete();
}
@@ -719,7 +642,6 @@ TEST(CollectCpuProfileSamples) {
profile->Delete();
}
-
static const char* cpu_profiler_test_source2 = "function loop() {}\n"
"function delay() { loop(); }\n"
"function start(count) {\n"
@@ -758,22 +680,13 @@ TEST(SampleWhenFrameIsNotSetup) {
RunProfiler(env.local(), function, args, arraysize(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
-
- ScopedVector<v8::Local<v8::String> > names(3);
- names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
- names[1] = v8_str(ProfileGenerator::kProgramEntryName);
- names[2] = v8_str("start");
- CheckChildrenNames(env.local(), root, names);
-
const v8::CpuProfileNode* startNode = FindChild(env.local(), root, "start");
// On slow machines there may be no meaningfull samples at all, skip the
// check there.
if (startNode && startNode->GetChildrenCount() > 0) {
- CHECK_EQ(1, startNode->GetChildrenCount());
const v8::CpuProfileNode* delayNode =
GetChild(env.local(), startNode, "delay");
if (delayNode->GetChildrenCount() > 0) {
- CHECK_EQ(1, delayNode->GetChildrenCount());
GetChild(env.local(), delayNode, "loop");
}
}
@@ -781,7 +694,6 @@ TEST(SampleWhenFrameIsNotSetup) {
profile->Delete();
}
-
static const char* native_accessor_test_source = "function start(count) {\n"
" for (var i = 0; i < count; i++) {\n"
" var o = instance.foo;\n"
@@ -1059,12 +971,6 @@ TEST(BoundFunctionCall) {
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
- ScopedVector<v8::Local<v8::String> > names(3);
- names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
- names[1] = v8_str(ProfileGenerator::kProgramEntryName);
- names[2] = v8_str("start");
- // Don't allow |foo| node to be at the top level.
- CheckChildrenNames(env, root, names);
const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
GetChild(env, startNode, "foo");
@@ -1170,18 +1076,15 @@ TEST(TickLines) {
CHECK_EQ(hit_count, value);
}
-
-static const char* call_function_test_source = "function bar(iterations) {\n"
-"}\n"
-"function start(duration) {\n"
-" var start = Date.now();\n"
-" while (Date.now() - start < duration) {\n"
-" try {\n"
-" bar.call(this, 10 * 1000);\n"
-" } catch(e) {}\n"
-" }\n"
-"}";
-
+static const char* call_function_test_source =
+ "function bar() {\n"
+ " collectSample();\n"
+ "}\n"
+ "function start() {\n"
+ " try {\n"
+ " bar.call(this, 10 * 1000);\n"
+ " } catch(e) {}\n"
+ "}";
// Test that if we sampled thread when it was inside FunctionCall buitin then
// its caller frame will be '(unresolved function)' as we have no reliable way
@@ -1190,160 +1093,76 @@ static const char* call_function_test_source = "function bar(iterations) {\n"
// [Top down]:
// 96 0 (root) [-1] #1
// 1 1 (garbage collector) [-1] #4
-// 5 0 (unresolved function) [-1] #5
-// 5 5 call [-1] #6
// 71 70 start [-1] #3
// 1 1 bar [-1] #7
// 19 19 (program) [-1] #2
TEST(FunctionCallSample) {
yurys 2016/02/05 17:33:04 This test doesn't check that Function.call gets in
alph 2016/02/05 17:52:26 Does it have to be visible in the user callstack?
yurys 2016/02/05 18:07:33 According to the table above it should be visible
- LocalContext env;
- v8::HandleScope scope(env->GetIsolate());
-
- // Collect garbage that might have be generated while installing
- // extensions.
- CcTest::heap()->CollectAllGarbage();
+ v8::HandleScope scope(CcTest::isolate());
+ v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
+ v8::Context::Scope context_scope(env);
CompileRun(call_function_test_source);
- v8::Local<v8::Function> function = GetFunction(env.local(), "start");
-
- int32_t duration_ms = 100;
- v8::Local<v8::Value> args[] = {
- v8::Integer::New(env->GetIsolate(), duration_ms)};
- v8::CpuProfile* profile =
- RunProfiler(env.local(), function, args, arraysize(args), 100);
+ v8::Local<v8::Function> function = GetFunction(env, "start");
+ v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
- {
- ScopedVector<v8::Local<v8::String> > names(4);
- names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
- names[1] = v8_str(ProfileGenerator::kProgramEntryName);
- names[2] = v8_str("start");
- names[3] = v8_str(i::ProfileGenerator::kUnresolvedFunctionName);
- // Don't allow |bar| and |call| nodes to be at the top level.
- CheckChildrenNames(env.local(), root, names);
- }
-
- // In case of GC stress tests all samples may be in GC phase and there
- // won't be |start| node in the profiles.
- bool is_gc_stress_testing =
- (i::FLAG_gc_interval != -1) || i::FLAG_stress_compaction;
- const v8::CpuProfileNode* startNode = FindChild(env.local(), root, "start");
- CHECK(is_gc_stress_testing || startNode);
- if (startNode) {
- ScopedVector<v8::Local<v8::String> > names(2);
- names[0] = v8_str("bar");
- names[1] = v8_str("call");
- CheckChildrenNames(env.local(), startNode, names);
- }
-
- const v8::CpuProfileNode* unresolvedNode = FindChild(
- env.local(), root, i::ProfileGenerator::kUnresolvedFunctionName);
- if (unresolvedNode) {
- ScopedVector<v8::Local<v8::String> > names(1);
- names[0] = v8_str("call");
- CheckChildrenNames(env.local(), unresolvedNode, names);
- }
+ const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
+ GetChild(env, startNode, "bar");
profile->Delete();
}
-
static const char* function_apply_test_source =
- "function bar(iterations) {\n"
+ "function bar() {\n"
+ " collectSample();\n"
"}\n"
"function test() {\n"
- " bar.apply(this, [10 * 1000]);\n"
+ " bar.apply(this, []);\n"
"}\n"
- "function start(duration) {\n"
- " var start = Date.now();\n"
- " while (Date.now() - start < duration) {\n"
- " try {\n"
- " test();\n"
- " } catch(e) {}\n"
- " }\n"
+ "function start() {\n"
+ " try {\n"
+ " test();\n"
+ " } catch(e) {}\n"
"}";
-
// [Top down]:
// 94 0 (root) [-1] #0 1
// 2 2 (garbage collector) [-1] #0 7
// 82 49 start [-1] #16 3
-// 1 0 (unresolved function) [-1] #0 8
-// 1 1 apply [-1] #0 9
// 32 21 test [-1] #16 4
// 2 2 bar [-1] #16 6
-// 9 9 apply [-1] #0 5
// 10 10 (program) [-1] #0 2
TEST(FunctionApplySample) {
yurys 2016/02/05 17:33:04 This test as its name implies should check that th
alph 2016/02/05 17:52:26 It just checks that functions called through apply
yurys 2016/02/05 18:07:33 See my reply above.
- LocalContext env;
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(CcTest::isolate());
+ v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
+ v8::Context::Scope context_scope(env);
CompileRun(function_apply_test_source);
- v8::Local<v8::Function> function = GetFunction(env.local(), "start");
-
- int32_t duration_ms = 100;
- v8::Local<v8::Value> args[] = {
- v8::Integer::New(env->GetIsolate(), duration_ms)};
-
- v8::CpuProfile* profile =
- RunProfiler(env.local(), function, args, arraysize(args), 100);
+ v8::Local<v8::Function> function = GetFunction(env, "start");
+ v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
- {
- ScopedVector<v8::Local<v8::String> > names(3);
- names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
- names[1] = v8_str(ProfileGenerator::kProgramEntryName);
- names[2] = v8_str("start");
- // Don't allow |test|, |bar| and |apply| nodes to be at the top level.
- CheckChildrenNames(env.local(), root, names);
- }
-
- const v8::CpuProfileNode* startNode = FindChild(env.local(), root, "start");
- if (startNode) {
- {
- ScopedVector<v8::Local<v8::String> > names(2);
- names[0] = v8_str("test");
- names[1] = v8_str(ProfileGenerator::kUnresolvedFunctionName);
- CheckChildrenNames(env.local(), startNode, names);
- }
-
- const v8::CpuProfileNode* testNode =
- FindChild(env.local(), startNode, "test");
- if (testNode) {
- ScopedVector<v8::Local<v8::String> > names(3);
- names[0] = v8_str("bar");
- names[1] = v8_str("apply");
- // apply calls "get length" before invoking the function itself
- // and we may get hit into it.
- names[2] = v8_str("get length");
- CheckChildrenNames(env.local(), testNode, names);
- }
-
- if (const v8::CpuProfileNode* unresolvedNode =
- FindChild(env.local(), startNode,
- ProfileGenerator::kUnresolvedFunctionName)) {
- ScopedVector<v8::Local<v8::String> > names(1);
- names[0] = v8_str("apply");
- CheckChildrenNames(env.local(), unresolvedNode, names);
- GetChild(env.local(), unresolvedNode, "apply");
- }
- }
+ const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
+ const v8::CpuProfileNode* testNode = GetChild(env, startNode, "test");
+ GetChild(env, testNode, "bar");
profile->Delete();
}
-
static const char* cpu_profiler_deep_stack_test_source =
-"function foo(n) {\n"
-" if (n)\n"
-" foo(n - 1);\n"
-" else\n"
-" startProfiling('my_profile');\n"
-"}\n"
-"function start() {\n"
-" foo(250);\n"
-"}\n";
-
+ "function foo(n) {\n"
+ " try {\n"
+ " if (n)\n"
+ " foo(n - 1);\n"
+ " else\n"
+ " collectSample();\n"
+ " } catch (e) {}\n"
+ "}\n"
+ "function start() {\n"
+ " try {\n"
+ " foo(250);\n"
+ " } catch (e) {}\n"
+ "}\n";
// Check a deep stack
//
@@ -1355,7 +1174,7 @@ static const char* cpu_profiler_deep_stack_test_source =
// 0 foo 21 #5 no reason
// ....
// 0 foo 21 #253 no reason
-// 1 startProfiling 0 #254
+// 1 collectSample 0 #254
TEST(CpuProfileDeepStack) {
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
@@ -1363,39 +1182,22 @@ TEST(CpuProfileDeepStack) {
CompileRun(cpu_profiler_deep_stack_test_source);
v8::Local<v8::Function> function = GetFunction(env, "start");
-
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- v8::Local<v8::String> profile_name = v8_str("my_profile");
- function->Call(env, env->Global(), 0, NULL).ToLocalChecked();
- v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
- CHECK(profile);
- // Dump collected profile to have a better diagnostic in case of failure.
- reinterpret_cast<i::CpuProfile*>(profile)->Print();
+ v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
- {
- ScopedVector<v8::Local<v8::String> > names(3);
- names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
- names[1] = v8_str(ProfileGenerator::kProgramEntryName);
- names[2] = v8_str("start");
- CheckChildrenNames(env, root, names);
- }
-
const v8::CpuProfileNode* node = GetChild(env, root, "start");
- for (int i = 0; i < 250; ++i) {
+ for (int i = 0; i <= 250; ++i) {
node = GetChild(env, node, "foo");
}
- // TODO(alph):
- // In theory there must be one more 'foo' and a 'startProfiling' nodes,
- // but due to unstable top frame extraction these might be missing.
+ GetChild(env, node, "collectSample");
+ CHECK(!FindChild(env, node, "foo"));
profile->Delete();
}
-
static const char* js_native_js_test_source =
"function foo() {\n"
- " startProfiling('my_profile');\n"
+ " collectSample();\n"
"}\n"
"function bar() {\n"
" try { foo(); } catch(e) {}\n"
@@ -1414,7 +1216,6 @@ static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) {
.ToLocalChecked();
}
-
// [Top down]:
// 58 0 (root) #0 1
// 2 2 (program) #0 2
@@ -1436,36 +1237,22 @@ TEST(JsNativeJsSample) {
CompileRun(js_native_js_test_source);
v8::Local<v8::Function> function = GetFunction(env, "start");
-
- v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
+ v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
- {
- ScopedVector<v8::Local<v8::String> > names(3);
- names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
- names[1] = v8_str(ProfileGenerator::kProgramEntryName);
- names[2] = v8_str("start");
- CheckChildrenNames(env, root, names);
- }
const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
- CHECK_EQ(1, startNode->GetChildrenCount());
const v8::CpuProfileNode* nativeFunctionNode =
GetChild(env, startNode, "CallJsFunction");
-
- CHECK_EQ(1, nativeFunctionNode->GetChildrenCount());
const v8::CpuProfileNode* barNode = GetChild(env, nativeFunctionNode, "bar");
-
- CHECK_EQ(1, barNode->GetChildrenCount());
GetChild(env, barNode, "foo");
profile->Delete();
}
-
static const char* js_native_js_runtime_js_test_source =
"function foo() {\n"
- " startProfiling('my_profile');\n"
+ " collectSample();\n"
"}\n"
"var bound = foo.bind(this);\n"
"function bar() {\n"
@@ -1477,7 +1264,6 @@ static const char* js_native_js_runtime_js_test_source =
" } catch(e) {}\n"
"}";
-
// [Top down]:
// 57 0 (root) #0 1
// 55 1 start #16 3
@@ -1499,29 +1285,13 @@ TEST(JsNativeJsRuntimeJsSample) {
CompileRun(js_native_js_runtime_js_test_source);
v8::Local<v8::Function> function = GetFunction(env, "start");
-
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
- ScopedVector<v8::Local<v8::String> > names(3);
- names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
- names[1] = v8_str(ProfileGenerator::kProgramEntryName);
- names[2] = v8_str("start");
- CheckChildrenNames(env, root, names);
-
const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
- CHECK_EQ(1, startNode->GetChildrenCount());
const v8::CpuProfileNode* nativeFunctionNode =
GetChild(env, startNode, "CallJsFunction");
-
- CHECK_EQ(1, nativeFunctionNode->GetChildrenCount());
const v8::CpuProfileNode* barNode = GetChild(env, nativeFunctionNode, "bar");
-
- // The child is in fact a bound foo.
- // A bound function has a wrapper that may make calls to
- // other functions e.g. "get length".
- CHECK_LE(1, barNode->GetChildrenCount());
- CHECK_GE(2, barNode->GetChildrenCount());
GetChild(env, barNode, "foo");
profile->Delete();
@@ -1533,11 +1303,10 @@ static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) {
CallJsFunction(info);
}
-
static const char* js_native1_js_native2_js_test_source =
"function foo() {\n"
" try {\n"
- " startProfiling('my_profile');\n"
+ " collectSample();\n"
" } catch(e) {}\n"
"}\n"
"function bar() {\n"
@@ -1549,7 +1318,6 @@ static const char* js_native1_js_native2_js_test_source =
" } catch(e) {}\n"
"}";
-
// [Top down]:
// 57 0 (root) #0 1
// 55 1 start #16 3
@@ -1563,10 +1331,10 @@ TEST(JsNative1JsNative2JsSample) {
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
v8::Context::Scope context_scope(env);
- v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
- env->GetIsolate(), CallJsFunction);
v8::Local<v8::Function> func1 =
- func_template->GetFunction(env).ToLocalChecked();
+ v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction)
+ ->GetFunction(env)
+ .ToLocalChecked();
func1->SetName(v8_str("CallJsFunction1"));
env->Global()->Set(env, v8_str("CallJsFunction1"), func1).FromJust();
@@ -1583,25 +1351,12 @@ TEST(JsNative1JsNative2JsSample) {
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
- ScopedVector<v8::Local<v8::String> > names(3);
- names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
- names[1] = v8_str(ProfileGenerator::kProgramEntryName);
- names[2] = v8_str("start");
- CheckChildrenNames(env, root, names);
-
const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
- CHECK_EQ(1, startNode->GetChildrenCount());
const v8::CpuProfileNode* nativeNode1 =
GetChild(env, startNode, "CallJsFunction1");
-
- CHECK_EQ(1, nativeNode1->GetChildrenCount());
const v8::CpuProfileNode* barNode = GetChild(env, nativeNode1, "bar");
-
- CHECK_EQ(1, barNode->GetChildrenCount());
const v8::CpuProfileNode* nativeNode2 =
GetChild(env, barNode, "CallJsFunction2");
-
- CHECK_EQ(1, nativeNode2->GetChildrenCount());
GetChild(env, nativeNode2, "foo");
profile->Delete();
@@ -1626,7 +1381,6 @@ TEST(CollectSampleAPI) {
CompileRun(js_force_collect_sample_source);
v8::Local<v8::Function> function = GetFunction(env, "start");
-
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
@@ -1715,28 +1469,18 @@ TEST(IdleTime) {
i::Isolate* isolate = CcTest::i_isolate();
i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor();
- processor->AddCurrentStack(isolate, true);
+ processor->AddCurrentStack(isolate, true);
cpu_profiler->SetIdle(true);
-
for (int i = 0; i < 3; i++) {
processor->AddCurrentStack(isolate, true);
}
-
cpu_profiler->SetIdle(false);
processor->AddCurrentStack(isolate, true);
v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
- CHECK(profile);
- // Dump collected profile to have a better diagnostic in case of failure.
- reinterpret_cast<i::CpuProfile*>(profile)->Print();
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
- ScopedVector<v8::Local<v8::String> > names(3);
- names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
- names[1] = v8_str(ProfileGenerator::kProgramEntryName);
- names[2] = v8_str(ProfileGenerator::kIdleEntryName);
- CheckChildrenNames(env.local(), root, names);
const v8::CpuProfileNode* programNode =
GetChild(env.local(), root, ProfileGenerator::kProgramEntryName);
« test/cctest/profiler-extension.cc ('K') | « test/cctest/profiler-extension.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698