Index: test/cctest/test-cpu-profiler.cc |
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc |
index ce422b5b6ba179f257743a2d169ee5b81c1ee97e..50ba8bc55495b0c2bb452142d0a70b9880443357 100644 |
--- a/test/cctest/test-cpu-profiler.cc |
+++ b/test/cctest/test-cpu-profiler.cc |
@@ -401,12 +401,15 @@ TEST(ProfileStartEndTime) { |
static v8::CpuProfile* RunProfiler( |
v8::Handle<v8::Context> env, v8::Handle<v8::Function> function, |
v8::Handle<v8::Value> argv[], int argc, |
- unsigned min_js_samples, bool collect_samples = false) { |
+ unsigned min_js_samples, bool start_profile = true, |
yurys
2014/05/27 14:38:19
You can return true from CpuProfilesCollection::St
alph
2014/05/27 14:46:55
Done.
|
+ bool collect_samples = false) { |
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
v8::Local<v8::String> profile_name = |
v8::String::NewFromUtf8(env->GetIsolate(), "my_profile"); |
- cpu_profiler->StartProfiling(profile_name, collect_samples); |
+ if (start_profile) { |
+ cpu_profiler->StartProfiling(profile_name, collect_samples); |
+ } |
i::Sampler* sampler = |
reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler(); |
@@ -666,8 +669,8 @@ TEST(CollectCpuProfileSamples) { |
v8::Handle<v8::Value> args[] = { |
v8::Integer::New(env->GetIsolate(), profiling_interval_ms) |
}; |
- v8::CpuProfile* profile = |
- RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200, true); |
+ v8::CpuProfile* profile = RunProfiler( |
+ env.local(), function, args, ARRAY_SIZE(args), 200, true, true); |
CHECK_LE(200, profile->GetSamplesCount()); |
uint64_t end_time = profile->GetEndTime(); |
@@ -1023,23 +1026,20 @@ TEST(NativeMethodMonomorphicIC) { |
} |
-static const char* bound_function_test_source = "function foo(iterations) {\n" |
-" var r = 0;\n" |
-" for (var i = 0; i < iterations; i++) { r += i; }\n" |
-" return r;\n" |
+static const char* bound_function_test_source = |
+"function foo() {\n" |
+" startProfiling('my_profile');\n" |
"}\n" |
-"function start(duration) {\n" |
+"function start() {\n" |
" var callback = foo.bind(this);\n" |
-" var start = Date.now();\n" |
-" while (Date.now() - start < duration) {\n" |
-" callback(10 * 1000);\n" |
-" }\n" |
+" callback();\n" |
"}"; |
TEST(BoundFunctionCall) { |
- 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); |
v8::Script::Compile( |
v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source)) |
@@ -1047,12 +1047,7 @@ TEST(BoundFunctionCall) { |
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
- int32_t duration_ms = 100; |
- v8::Handle<v8::Value> args[] = { |
- v8::Integer::New(env->GetIsolate(), duration_ms) |
- }; |
- v8::CpuProfile* profile = |
- RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); |
+ v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0, false); |
const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
ScopedVector<v8::Handle<v8::String> > names(3); |
@@ -1248,26 +1243,16 @@ TEST(FunctionApplySample) { |
static const char* js_native_js_test_source = |
-"var is_profiling = false;\n" |
-"function foo(iterations) {\n" |
-" if (!is_profiling) {\n" |
-" is_profiling = true;\n" |
-" startProfiling('my_profile');\n" |
-" }\n" |
-" var r = 0;\n" |
-" for (var i = 0; i < iterations; i++) { r += i; }\n" |
-" return r;\n" |
+"function foo() {\n" |
+" startProfiling('my_profile');\n" |
"}\n" |
-"function bar(iterations) {\n" |
-" try { foo(iterations); } catch(e) {}\n" |
+"function bar() {\n" |
+" try { foo(); } 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" |
+"function start() {\n" |
+" try {\n" |
+" CallJsFunction(bar);\n" |
+" } catch(e) {}\n" |
"}"; |
static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) { |
@@ -1301,12 +1286,7 @@ TEST(JsNativeJsSample) { |
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
- int32_t duration_ms = 20; |
- v8::Handle<v8::Value> args[] = { |
- v8::Integer::New(env->GetIsolate(), duration_ms) |
- }; |
- v8::CpuProfile* profile = |
- RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
+ v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0, false); |
const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
{ |
@@ -1337,27 +1317,17 @@ TEST(JsNativeJsSample) { |
static const char* js_native_js_runtime_js_test_source = |
-"var is_profiling = false;\n" |
-"function foo(iterations) {\n" |
-" if (!is_profiling) {\n" |
-" is_profiling = true;\n" |
-" startProfiling('my_profile');\n" |
-" }\n" |
-" var r = 0;\n" |
-" for (var i = 0; i < iterations; i++) { r += i; }\n" |
-" return r;\n" |
+"function foo() {\n" |
+" startProfiling('my_profile');\n" |
"}\n" |
"var bound = foo.bind(this);\n" |
-"function bar(iterations) {\n" |
-" try { bound(iterations); } catch(e) {}\n" |
+"function bar() {\n" |
+" try { bound(); } 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" |
+"function start() {\n" |
+" try {\n" |
+" CallJsFunction(bar);\n" |
+" } catch(e) {}\n" |
"}"; |
@@ -1386,12 +1356,7 @@ TEST(JsNativeJsRuntimeJsSample) { |
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
- int32_t duration_ms = 20; |
- v8::Handle<v8::Value> args[] = { |
- v8::Integer::New(env->GetIsolate(), duration_ms) |
- }; |
- v8::CpuProfile* profile = |
- RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
+ v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0, false); |
const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
ScopedVector<v8::Handle<v8::String> > names(3); |
@@ -1429,26 +1394,18 @@ static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { |
static const char* js_native1_js_native2_js_test_source = |
-"var is_profiling = false;\n" |
-"function foo(iterations) {\n" |
-" if (!is_profiling) {\n" |
-" is_profiling = true;\n" |
+"function foo() {\n" |
+" try {\n" |
" startProfiling('my_profile');\n" |
-" }\n" |
-" var r = 0;\n" |
-" for (var i = 0; i < iterations; i++) { r += i; }\n" |
-" return r;\n" |
+" } catch(e) {}\n" |
"}\n" |
-"function bar(iterations) {\n" |
-" CallJsFunction2(foo, iterations);\n" |
+"function bar() {\n" |
+" CallJsFunction2(foo);\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" |
+"function start() {\n" |
+" try {\n" |
+" CallJsFunction1(bar);\n" |
+" } catch(e) {}\n" |
"}"; |
@@ -1484,12 +1441,7 @@ TEST(JsNative1JsNative2JsSample) { |
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
- int32_t duration_ms = 20; |
- v8::Handle<v8::Value> args[] = { |
- v8::Integer::New(env->GetIsolate(), duration_ms) |
- }; |
- v8::CpuProfile* profile = |
- RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
+ v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0, false); |
const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
ScopedVector<v8::Handle<v8::String> > names(3); |