Commit e64230c1 authored by alph@chromium.org's avatar alph@chromium.org

Unflake and speedup JsNative*Sample cpu profile tests

Instead of running cpu profiler for a hundred milliseconds,
collecting samples distributed in a non-deterministic way all along
the code, make the tests rely on a single sample we collect on
the profiler start.

R=bmeurer@chromium.org, yurys@chromium.org

Review URL: https://codereview.chromium.org/301603005

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22345 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 4468f441
...@@ -469,9 +469,10 @@ bool CpuProfilesCollection::StartProfiling(const char* title, ...@@ -469,9 +469,10 @@ bool CpuProfilesCollection::StartProfiling(const char* title,
} }
for (int i = 0; i < current_profiles_.length(); ++i) { for (int i = 0; i < current_profiles_.length(); ++i) {
if (strcmp(current_profiles_[i]->title(), title) == 0) { if (strcmp(current_profiles_[i]->title(), title) == 0) {
// Ignore attempts to start profile with the same title. // Ignore attempts to start profile with the same title...
current_profiles_semaphore_.Signal(); current_profiles_semaphore_.Signal();
return false; // ... though return true to force it collect a sample.
return true;
} }
} }
current_profiles_.Add(new CpuProfile(title, record_samples)); current_profiles_.Add(new CpuProfile(title, record_samples));
......
...@@ -70,11 +70,6 @@ ...@@ -70,11 +70,6 @@
'test-hydrogen-types/*': [PASS, NO_VARIANTS], 'test-hydrogen-types/*': [PASS, NO_VARIANTS],
'test-types/*': [PASS, NO_VARIANTS], 'test-types/*': [PASS, NO_VARIANTS],
# The cpu profiler tests are notoriously flaky.
# BUG(2999). (test/cpu-profiler/CollectCpuProfile)
# BUG(3287). (test-cpu-profiler/SampleWhenFrameIsNotSetup)
'test-cpu-profiler/*': [PASS, FLAKY],
############################################################################ ############################################################################
# Slow tests. # Slow tests.
'test-api/Threading1': [PASS, ['mode == debug', SLOW]], 'test-api/Threading1': [PASS, ['mode == debug', SLOW]],
......
...@@ -1023,23 +1023,20 @@ TEST(NativeMethodMonomorphicIC) { ...@@ -1023,23 +1023,20 @@ TEST(NativeMethodMonomorphicIC) {
} }
static const char* bound_function_test_source = "function foo(iterations) {\n" static const char* bound_function_test_source =
" var r = 0;\n" "function foo() {\n"
" for (var i = 0; i < iterations; i++) { r += i; }\n" " startProfiling('my_profile');\n"
" return r;\n" "}\n"
"}\n" "function start() {\n"
"function start(duration) {\n" " var callback = foo.bind(this);\n"
" var callback = foo.bind(this);\n" " callback();\n"
" var start = Date.now();\n" "}";
" while (Date.now() - start < duration) {\n"
" callback(10 * 1000);\n"
" }\n"
"}";
TEST(BoundFunctionCall) { TEST(BoundFunctionCall) {
LocalContext env; v8::HandleScope scope(CcTest::isolate());
v8::HandleScope scope(env->GetIsolate()); v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
v8::Context::Scope context_scope(env);
v8::Script::Compile( v8::Script::Compile(
v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source)) v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source))
...@@ -1047,12 +1044,7 @@ TEST(BoundFunctionCall) { ...@@ -1047,12 +1044,7 @@ TEST(BoundFunctionCall) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
int32_t duration_ms = 100; v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
v8::Handle<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), duration_ms)
};
v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot(); const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3); ScopedVector<v8::Handle<v8::String> > names(3);
...@@ -1314,27 +1306,17 @@ TEST(CpuProfileDeepStack) { ...@@ -1314,27 +1306,17 @@ TEST(CpuProfileDeepStack) {
static const char* js_native_js_test_source = static const char* js_native_js_test_source =
"var is_profiling = false;\n" "function foo() {\n"
"function foo(iterations) {\n" " startProfiling('my_profile');\n"
" if (!is_profiling) {\n" "}\n"
" is_profiling = true;\n" "function bar() {\n"
" startProfiling('my_profile');\n" " try { foo(); } catch(e) {}\n"
" }\n" "}\n"
" var r = 0;\n" "function start() {\n"
" for (var i = 0; i < iterations; i++) { r += i; }\n" " try {\n"
" return r;\n" " CallJsFunction(bar);\n"
"}\n" " } catch(e) {}\n"
"function bar(iterations) {\n" "}";
" try { foo(iterations); } catch(e) {}\n"
"}\n"
"function start(duration) {\n"
" var start = Date.now();\n"
" while (Date.now() - start < duration) {\n"
" try {\n"
" CallJsFunction(bar, 10 * 1000);\n"
" } catch(e) {}\n"
" }\n"
"}";
static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) { static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Handle<v8::Function> function = info[0].As<v8::Function>(); v8::Handle<v8::Function> function = info[0].As<v8::Function>();
...@@ -1367,12 +1349,7 @@ TEST(JsNativeJsSample) { ...@@ -1367,12 +1349,7 @@ TEST(JsNativeJsSample) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
int32_t duration_ms = 20; v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
v8::Handle<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), duration_ms)
};
v8::CpuProfile* profile =
RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
const v8::CpuProfileNode* root = profile->GetTopDownRoot(); const v8::CpuProfileNode* root = profile->GetTopDownRoot();
{ {
...@@ -1403,28 +1380,18 @@ TEST(JsNativeJsSample) { ...@@ -1403,28 +1380,18 @@ TEST(JsNativeJsSample) {
static const char* js_native_js_runtime_js_test_source = static const char* js_native_js_runtime_js_test_source =
"var is_profiling = false;\n" "function foo() {\n"
"function foo(iterations) {\n" " startProfiling('my_profile');\n"
" if (!is_profiling) {\n" "}\n"
" is_profiling = true;\n" "var bound = foo.bind(this);\n"
" startProfiling('my_profile');\n" "function bar() {\n"
" }\n" " try { bound(); } catch(e) {}\n"
" var r = 0;\n" "}\n"
" for (var i = 0; i < iterations; i++) { r += i; }\n" "function start() {\n"
" return r;\n" " try {\n"
"}\n" " CallJsFunction(bar);\n"
"var bound = foo.bind(this);\n" " } catch(e) {}\n"
"function bar(iterations) {\n" "}";
" try { bound(iterations); } catch(e) {}\n"
"}\n"
"function start(duration) {\n"
" var start = Date.now();\n"
" while (Date.now() - start < duration) {\n"
" try {\n"
" CallJsFunction(bar, 10 * 1000);\n"
" } catch(e) {}\n"
" }\n"
"}";
// [Top down]: // [Top down]:
...@@ -1452,12 +1419,7 @@ TEST(JsNativeJsRuntimeJsSample) { ...@@ -1452,12 +1419,7 @@ TEST(JsNativeJsRuntimeJsSample) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
int32_t duration_ms = 20; v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
v8::Handle<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), duration_ms)
};
v8::CpuProfile* profile =
RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
const v8::CpuProfileNode* root = profile->GetTopDownRoot(); const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3); ScopedVector<v8::Handle<v8::String> > names(3);
...@@ -1496,27 +1458,19 @@ static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { ...@@ -1496,27 +1458,19 @@ static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) {
static const char* js_native1_js_native2_js_test_source = static const char* js_native1_js_native2_js_test_source =
"var is_profiling = false;\n" "function foo() {\n"
"function foo(iterations) {\n" " try {\n"
" if (!is_profiling) {\n" " startProfiling('my_profile');\n"
" is_profiling = true;\n" " } catch(e) {}\n"
" startProfiling('my_profile');\n" "}\n"
" }\n" "function bar() {\n"
" var r = 0;\n" " CallJsFunction2(foo);\n"
" for (var i = 0; i < iterations; i++) { r += i; }\n" "}\n"
" return r;\n" "function start() {\n"
"}\n" " try {\n"
"function bar(iterations) {\n" " CallJsFunction1(bar);\n"
" CallJsFunction2(foo, iterations);\n" " } catch(e) {}\n"
"}\n" "}";
"function start(duration) {\n"
" var start = Date.now();\n"
" while (Date.now() - start < duration) {\n"
" try {\n"
" CallJsFunction1(bar, 10 * 1000);\n"
" } catch(e) {}\n"
" }\n"
"}";
// [Top down]: // [Top down]:
...@@ -1551,12 +1505,7 @@ TEST(JsNative1JsNative2JsSample) { ...@@ -1551,12 +1505,7 @@ TEST(JsNative1JsNative2JsSample) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
int32_t duration_ms = 20; v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
v8::Handle<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), duration_ms)
};
v8::CpuProfile* profile =
RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
const v8::CpuProfileNode* root = profile->GetTopDownRoot(); const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3); ScopedVector<v8::Handle<v8::String> > names(3);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment