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..513b106d32b6204c0ee0f2fabba57799d2219ee0 100644 |
--- a/test/cctest/test-cpu-profiler.cc |
+++ b/test/cctest/test-cpu-profiler.cc |
@@ -446,47 +446,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 +481,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 +499,39 @@ 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 = |
+ "%NeverOptimizeFunction(loop);\n" |
+ "%NeverOptimizeFunction(delay);\n" |
+ "%NeverOptimizeFunction(bar);\n" |
+ "%NeverOptimizeFunction(baz);\n" |
+ "%NeverOptimizeFunction(foo);\n" |
+ "%NeverOptimizeFunction(start);\n" |
+ "function loop(timeout) {\n" |
+ " this.mmm = 0;\n" |
+ " var start = Date.now();\n" |
+ " do {\n" |
+ " var n = 1000;\n" |
+ " while(n > 1) {\n" |
+ " n--;\n" |
+ " this.mmm += n * n * n;\n" |
+ " }\n" |
+ " } while (Date.now() - start < timeout);\n" |
+ "}\n" |
+ "function delay() { loop(10); }\n" |
+ "function bar() { delay(); }\n" |
+ "function baz() { delay(); }\n" |
+ "function foo() {\n" |
+ " delay();\n" |
+ " bar();\n" |
+ " delay();\n" |
+ " baz();\n" |
+ "}\n" |
+ "function start(duration) {\n" |
+ " var start = Date.now();\n" |
+ " do {\n" |
+ " foo();\n" |
+ " } while (Date.now() - start < duration);\n" |
+ "}\n"; |
// Check that the profile tree for the script above will look like the |
// following: |
@@ -592,6 +551,7 @@ static const char* cpu_profiler_test_source = "function loop(timeout) {\n" |
// 2 2 (program) [-1] |
// 6 6 (garbage collector) [-1] |
TEST(CollectCpuProfile) { |
+ i::FLAG_allow_natives_syntax = true; |
LocalContext env; |
v8::HandleScope scope(env->GetIsolate()); |
@@ -602,23 +562,11 @@ TEST(CollectCpuProfile) { |
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(); |
+ RunProfiler(env.local(), function, args, arraysize(args), 1000); |
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 char* barBranch[] = { "bar", "delay", "loop" }; |
CheckSimpleBranch(env.local(), fooNode, barBranch, arraysize(barBranch)); |
@@ -630,21 +578,20 @@ TEST(CollectCpuProfile) { |
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" |
yurys
2016/02/05 22:54:11
Can you also replace try/catch with %NeverOptimize
alph
2016/02/05 23:32:09
Done.
|
+ " 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,28 +617,19 @@ 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), 1000); |
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"); |
profile->Delete(); |
} |
- |
TEST(CollectCpuProfileSamples) { |
+ i::FLAG_allow_natives_syntax = true; |
LocalContext env; |
v8::HandleScope scope(env->GetIsolate()); |
@@ -702,7 +640,7 @@ TEST(CollectCpuProfileSamples) { |
v8::Local<v8::Value> args[] = { |
v8::Integer::New(env->GetIsolate(), profiling_interval_ms)}; |
v8::CpuProfile* profile = |
- RunProfiler(env.local(), function, args, arraysize(args), 200, true); |
+ RunProfiler(env.local(), function, args, arraysize(args), 1000, true); |
CHECK_LE(200, profile->GetSamplesCount()); |
uint64_t end_time = profile->GetEndTime(); |
@@ -719,15 +657,17 @@ TEST(CollectCpuProfileSamples) { |
profile->Delete(); |
} |
- |
-static const char* cpu_profiler_test_source2 = "function loop() {}\n" |
-"function delay() { loop(); }\n" |
-"function start(count) {\n" |
-" var k = 0;\n" |
-" do {\n" |
-" delay();\n" |
-" } while (++k < count*100*1000);\n" |
-"}\n"; |
+static const char* cpu_profiler_test_source2 = |
+ "function loop() {}\n" |
+ "function delay() { try { loop(); } catch (e) {} }\n" |
+ "function start(duration) {\n" |
+ " var start = Date.now();\n" |
+ " try {\n" |
+ " do {\n" |
+ " for (var i = 0; i < 10000; ++i) delay();\n" |
+ " } while (Date.now() - start < duration);\n" |
+ " } catch (e) {}\n" |
+ "}"; |
// Check that the profile tree doesn't contain unexpected traces: |
// - 'loop' can be called only by 'delay' |
@@ -747,41 +687,21 @@ TEST(SampleWhenFrameIsNotSetup) { |
CompileRun(cpu_profiler_test_source2); |
v8::Local<v8::Function> function = GetFunction(env.local(), "start"); |
- int32_t repeat_count = 100; |
-#if defined(USE_SIMULATOR) |
- // Simulators are much slower. |
- repeat_count = 1; |
-#endif |
+ int32_t duration_ms = 100; |
v8::Local<v8::Value> args[] = { |
- v8::Integer::New(env->GetIsolate(), repeat_count)}; |
+ v8::Integer::New(env->GetIsolate(), duration_ms)}; |
v8::CpuProfile* profile = |
- RunProfiler(env.local(), function, args, arraysize(args), 100); |
+ RunProfiler(env.local(), function, args, arraysize(args), 1000); |
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"); |
- } |
- } |
+ const v8::CpuProfileNode* startNode = GetChild(env.local(), root, "start"); |
+ const v8::CpuProfileNode* delayNode = |
+ GetChild(env.local(), startNode, "delay"); |
+ GetChild(env.local(), delayNode, "loop"); |
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" |
@@ -789,7 +709,6 @@ static const char* native_accessor_test_source = "function start(count) {\n" |
" }\n" |
"}\n"; |
- |
class TestApiCallbacks { |
public: |
explicit TestApiCallbacks(int min_duration_ms) |
@@ -1059,12 +978,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 +1083,17 @@ 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 = |
+ "%NeverOptimizeFunction(bar);\n" |
+ "%NeverOptimizeFunction(start);\n" |
+ "function bar(iterations) { }\n" |
+ "function start(duration) {\n" |
+ " var start = Date.now();\n" |
+ " do {\n" |
+ " for (var i = 0; i < 100; ++i)\n" |
+ " bar.call(this, 10 * 1000);\n" |
+ " } while (Date.now() - start < duration);\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 |
@@ -1196,6 +1108,7 @@ static const char* call_function_test_source = "function bar(iterations) {\n" |
// 1 1 bar [-1] #7 |
// 19 19 (program) [-1] #2 |
TEST(FunctionCallSample) { |
+ i::FLAG_allow_natives_syntax = true; |
LocalContext env; |
v8::HandleScope scope(env->GetIsolate()); |
@@ -1211,59 +1124,35 @@ TEST(FunctionCallSample) { |
v8::Integer::New(env->GetIsolate(), duration_ms)}; |
v8::CpuProfile* profile = |
RunProfiler(env.local(), function, args, arraysize(args), 100); |
+ // Dump collected profile to have a better diagnostic in case of failure. |
+ reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
yurys
2016/02/05 22:54:11
RunProfiler already does this. Please remove.
alph
2016/02/05 23:32:09
Done.
|
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* startNode = GetChild(env.local(), root, "start"); |
+ GetChild(env.local(), startNode, "bar"); |
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); |
- } |
+ CHECK(!unresolvedNode || GetChild(env.local(), unresolvedNode, "call")); |
profile->Delete(); |
} |
- |
static const char* function_apply_test_source = |
- "function bar(iterations) {\n" |
- "}\n" |
+ "%NeverOptimizeFunction(bar);\n" |
+ "%NeverOptimizeFunction(test);\n" |
+ "%NeverOptimizeFunction(start);\n" |
+ "function bar(iterations) { }\n" |
"function test() {\n" |
" bar.apply(this, [10 * 1000]);\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" |
+ " do {\n" |
+ " for (var i = 0; i < 100; ++i) test();\n" |
+ " } while (Date.now() - start < duration);\n" |
"}"; |
- |
// [Top down]: |
// 94 0 (root) [-1] #0 1 |
// 2 2 (garbage collector) [-1] #0 7 |
@@ -1272,9 +1161,9 @@ static const char* function_apply_test_source = |
// 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) { |
+ i::FLAG_allow_natives_syntax = true; |
LocalContext env; |
v8::HandleScope scope(env->GetIsolate()); |
@@ -1286,64 +1175,33 @@ TEST(FunctionApplySample) { |
v8::Integer::New(env->GetIsolate(), duration_ms)}; |
v8::CpuProfile* profile = |
- RunProfiler(env.local(), function, args, arraysize(args), 100); |
+ RunProfiler(env.local(), function, args, arraysize(args), 1000); |
+ // Dump collected profile to have a better diagnostic in case of failure. |
+ reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
yurys
2016/02/05 22:54:11
Ditto.
alph
2016/02/05 23:32:09
Done.
|
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); |
- } |
+ const v8::CpuProfileNode* startNode = GetChild(env.local(), root, "start"); |
yurys
2016/02/05 22:54:11
style nit: here and in other places start_node ins
alph
2016/02/05 23:32:09
Done.
|
+ const v8::CpuProfileNode* testNode = GetChild(env.local(), startNode, "test"); |
+ GetChild(env.local(), testNode, "bar"); |
- 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* unresolvedNode = FindChild( |
+ env.local(), startNode, ProfileGenerator::kUnresolvedFunctionName); |
+ CHECK(!unresolvedNode || GetChild(env.local(), unresolvedNode, "apply")); |
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" |
+ " if (n)\n" |
+ " foo(n - 1);\n" |
+ " else\n" |
+ " collectSample();\n" |
+ "}\n" |
+ "function start() {\n" |
+ " startProfiling('my_profile');\n" |
+ " foo(250);\n" |
+ "}\n"; |
// Check a deep stack |
// |
@@ -1354,8 +1212,7 @@ static const char* cpu_profiler_deep_stack_test_source = |
// 0 foo 21 #4 no reason |
// 0 foo 21 #5 no reason |
// .... |
-// 0 foo 21 #253 no reason |
-// 1 startProfiling 0 #254 |
+// 0 foo 21 #254 no reason |
TEST(CpuProfileDeepStack) { |
v8::HandleScope scope(CcTest::isolate()); |
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
@@ -1373,21 +1230,11 @@ TEST(CpuProfileDeepStack) { |
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("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. |
+ CHECK(!FindChild(env, node, "foo")); |
profile->Delete(); |
} |
@@ -1414,7 +1261,6 @@ static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) { |
.ToLocalChecked(); |
} |
- |
// [Top down]: |
// 58 0 (root) #0 1 |
// 2 2 (program) #0 2 |
@@ -1440,29 +1286,15 @@ TEST(JsNativeJsSample) { |
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"); |
- |
- 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" |
@@ -1477,7 +1309,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,45 +1330,27 @@ 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(); |
} |
- |
static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { |
v8::base::OS::Print("In CallJsFunction2\n"); |
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 +1362,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 +1375,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(); |
yurys
2016/02/05 22:54:11
Place on the previous line?
alph
2016/02/05 23:32:09
I can't. It's git cl format.
|
func1->SetName(v8_str("CallJsFunction1")); |
env->Global()->Set(env, v8_str("CallJsFunction1"), func1).FromJust(); |
@@ -1580,28 +1392,15 @@ TEST(JsNative1JsNative2JsSample) { |
CompileRun(js_native1_js_native2_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, 1000); |
yurys
2016/02/05 22:54:11
Why is it not enough to have a single sample here?
alph
2016/02/05 23:32:09
Because as you said it won't be a JS sample on top
|
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 +1425,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(); |
@@ -1639,7 +1437,6 @@ TEST(CollectSampleAPI) { |
static const char* js_native_js_runtime_multiple_test_source = |
"function foo() {\n" |
- " CallCollectSample();" |
" return Math.sin(Math.random());\n" |
"}\n" |
"var bound = foo.bind(this);\n" |
@@ -1664,7 +1461,6 @@ static const char* js_native_js_runtime_multiple_test_source = |
// CallJsFunction #0 4 |
// bar #16 5 |
// foo #16 6 |
-// CallCollectSample |
// (program) #0 2 |
TEST(JsNativeJsRuntimeJsSampleMultiple) { |
v8::HandleScope scope(CcTest::isolate()); |
@@ -1678,25 +1474,20 @@ TEST(JsNativeJsRuntimeJsSampleMultiple) { |
func->SetName(v8_str("CallJsFunction")); |
env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust(); |
- func_template = |
- v8::FunctionTemplate::New(env->GetIsolate(), CallCollectSample); |
- func = func_template->GetFunction(env).ToLocalChecked(); |
- func->SetName(v8_str("CallCollectSample")); |
- env->Global()->Set(env, v8_str("CallCollectSample"), func).FromJust(); |
- |
CompileRun(js_native_js_runtime_multiple_test_source); |
v8::Local<v8::Function> function = GetFunction(env, "start"); |
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000); |
+ CHECK(profile); |
+ // Dump collected profile to have a better diagnostic in case of failure. |
+ reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
yurys
2016/02/05 22:54:11
Please remove.
alph
2016/02/05 23:32:09
Done.
|
const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
const v8::CpuProfileNode* startNode = GetChild(env, root, "start"); |
const v8::CpuProfileNode* nativeFunctionNode = |
GetChild(env, startNode, "CallJsFunction"); |
- |
const v8::CpuProfileNode* barNode = GetChild(env, nativeFunctionNode, "bar"); |
- const v8::CpuProfileNode* fooNode = GetChild(env, barNode, "foo"); |
- GetChild(env, fooNode, "CallCollectSample"); |
+ GetChild(env, barNode, "foo"); |
profile->Delete(); |
} |
@@ -1715,14 +1506,12 @@ 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); |
@@ -1732,12 +1521,6 @@ TEST(IdleTime) { |
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); |
CHECK_EQ(0, programNode->GetChildrenCount()); |
@@ -1751,7 +1534,6 @@ TEST(IdleTime) { |
profile->Delete(); |
} |
- |
static void CheckFunctionDetails(v8::Isolate* isolate, |
const v8::CpuProfileNode* node, |
const char* name, const char* script_name, |