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

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

Issue 18418004: Improve test-cpu-profiler.cc tests stability (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 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
« no previous file with comments | « src/sampler.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 a99389f5abdcd4eea33665bbe87fa92c27069afb..c61a02482fd748d9d7ca539869c5cd8e8ee98248 100644
--- a/test/cctest/test-cpu-profiler.cc
+++ b/test/cctest/test-cpu-profiler.cc
@@ -472,6 +472,33 @@ TEST(GetProfilerWhenIsolateIsNotInitialized) {
}
+static const v8::CpuProfile* RunProfiler(
+ LocalContext& env, v8::Handle<v8::Function> function,
+ v8::Handle<v8::Value> argv[], int argc,
+ unsigned min_js_samples) {
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
+ v8::Local<v8::String> profile_name = v8::String::New("my_profile");
+
+ cpu_profiler->StartCpuProfiling(profile_name);
+
+ i::Sampler* sampler =
+ reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler();
+ sampler->StartCountingSamples();
+ do {
+ function->Call(env->Global(), argc, argv);
+ } while (sampler->js_and_external_sample_count() < min_js_samples);
+
+ const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
+
+ CHECK_NE(NULL, profile);
+ // Dump collected profile to have a better diagnostic in case of failure.
+ reinterpret_cast<i::CpuProfile*>(
+ const_cast<v8::CpuProfile*>(profile))->Print();
+
+ return profile;
+}
+
+
static bool ContainsString(v8::Handle<v8::String> string,
const Vector<v8::Handle<v8::String> >& vector) {
for (int i = 0; i < vector.length(); i++) {
@@ -585,24 +612,11 @@ TEST(CollectCpuProfile) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::New("start")));
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- v8::Local<v8::String> profile_name = v8::String::New("my_profile");
-
- cpu_profiler->StartCpuProfiling(profile_name);
int32_t profiling_interval_ms = 200;
-#if defined(_WIN32) || defined(_WIN64)
- // 200ms is not enough on Windows. See
- // https://code.google.com/p/v8/issues/detail?id=2628
- profiling_interval_ms = 500;
-#endif
v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) };
+ const v8::CpuProfile* profile =
+ RunProfiler(env, function, args, ARRAY_SIZE(args), 200);
function->Call(env->Global(), ARRAY_SIZE(args), args);
- const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
-
- CHECK_NE(NULL, profile);
- // Dump collected profile to have a better diagnostic in case of failure.
- reinterpret_cast<i::CpuProfile*>(
- const_cast<v8::CpuProfile*>(profile))->Print();
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
@@ -625,6 +639,7 @@ TEST(CollectCpuProfile) {
const char* delayBranch[] = { "delay", "loop" };
CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch));
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
cpu_profiler->DeleteAllCpuProfiles();
}
@@ -658,23 +673,14 @@ TEST(SampleWhenFrameIsNotSetup) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::New("start")));
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- v8::Local<v8::String> profile_name = v8::String::New("my_profile");
-
- cpu_profiler->StartCpuProfiling(profile_name);
int32_t repeat_count = 100;
#if defined(USE_SIMULATOR)
// Simulators are much slower.
repeat_count = 1;
#endif
v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
- function->Call(env->Global(), ARRAY_SIZE(args), args);
- const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
-
- CHECK_NE(NULL, profile);
- // Dump collected profile to have a better diagnostic in case of failure.
- reinterpret_cast<i::CpuProfile*>(
- const_cast<v8::CpuProfile*>(profile))->Print();
+ const v8::CpuProfile* profile =
+ RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
@@ -696,6 +702,7 @@ TEST(SampleWhenFrameIsNotSetup) {
}
}
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
cpu_profiler->DeleteAllCpuProfiles();
}
@@ -788,25 +795,17 @@ TEST(NativeAccessorUninitializedIC) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::New("start")));
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- v8::Local<v8::String> profile_name = v8::String::New("my_profile");
-
- cpu_profiler->StartCpuProfiling(profile_name);
int32_t repeat_count = 1;
v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
- function->Call(env->Global(), ARRAY_SIZE(args), args);
- const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
-
- CHECK_NE(NULL, profile);
- // Dump collected profile to have a better diagnostic in case of failure.
- reinterpret_cast<i::CpuProfile*>(
- const_cast<v8::CpuProfile*>(profile))->Print();
+ const v8::CpuProfile* profile =
+ RunProfiler(env, function, args, ARRAY_SIZE(args), 180);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
const v8::CpuProfileNode* startNode = GetChild(root, "start");
GetChild(startNode, "get foo");
GetChild(startNode, "set foo");
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
cpu_profiler->DeleteAllCpuProfiles();
}
@@ -846,25 +845,17 @@ TEST(NativeAccessorMonomorphicIC) {
accessors.set_warming_up(false);
}
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- v8::Local<v8::String> profile_name = v8::String::New("my_profile");
-
- cpu_profiler->StartCpuProfiling(profile_name);
int32_t repeat_count = 100;
v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
- function->Call(env->Global(), ARRAY_SIZE(args), args);
- const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
-
- CHECK_NE(NULL, profile);
- // Dump collected profile to have a better diagnostic in case of failure.
- reinterpret_cast<i::CpuProfile*>(
- const_cast<v8::CpuProfile*>(profile))->Print();
+ const v8::CpuProfile* profile =
+ RunProfiler(env, function, args, ARRAY_SIZE(args), 200);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
const v8::CpuProfileNode* startNode = GetChild(root, "start");
GetChild(startNode, "get foo");
GetChild(startNode, "set foo");
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
cpu_profiler->DeleteAllCpuProfiles();
}
@@ -899,24 +890,16 @@ TEST(NativeMethodUninitializedIC) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::New("start")));
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- v8::Local<v8::String> profile_name = v8::String::New("my_profile");
-
- cpu_profiler->StartCpuProfiling(profile_name);
int32_t repeat_count = 1;
v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
- function->Call(env->Global(), ARRAY_SIZE(args), args);
- const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
-
- CHECK_NE(NULL, profile);
- // Dump collected profile to have a better diagnostic in case of failure.
- reinterpret_cast<i::CpuProfile*>(
- const_cast<v8::CpuProfile*>(profile))->Print();
+ const v8::CpuProfile* profile =
+ RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
const v8::CpuProfileNode* startNode = GetChild(root, "start");
GetChild(startNode, "fooMethod");
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
cpu_profiler->DeleteAllCpuProfiles();
}
@@ -953,25 +936,17 @@ TEST(NativeMethodMonomorphicIC) {
callbacks.set_warming_up(false);
}
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- v8::Local<v8::String> profile_name = v8::String::New("my_profile");
-
- cpu_profiler->StartCpuProfiling(profile_name);
int32_t repeat_count = 100;
v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
- function->Call(env->Global(), ARRAY_SIZE(args), args);
- const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
-
- CHECK_NE(NULL, profile);
- // Dump collected profile to have a better diagnostic in case of failure.
- reinterpret_cast<i::CpuProfile*>(
- const_cast<v8::CpuProfile*>(profile))->Print();
+ const v8::CpuProfile* profile =
+ RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
GetChild(root, "start");
const v8::CpuProfileNode* startNode = GetChild(root, "start");
GetChild(startNode, "fooMethod");
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
cpu_profiler->DeleteAllCpuProfiles();
}
@@ -998,19 +973,10 @@ TEST(BoundFunctionCall) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::New("start")));
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- v8::Local<v8::String> profile_name = v8::String::New("my_profile");
-
- cpu_profiler->StartCpuProfiling(profile_name);
int32_t duration_ms = 100;
v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
- function->Call(env->Global(), ARRAY_SIZE(args), args);
- const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
-
- CHECK_NE(NULL, profile);
- // Dump collected profile to have a better diagnostic in case of failure.
- reinterpret_cast<i::CpuProfile*>(
- const_cast<v8::CpuProfile*>(profile))->Print();
+ const v8::CpuProfile* profile =
+ RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3);
@@ -1023,6 +989,7 @@ TEST(BoundFunctionCall) {
const v8::CpuProfileNode* startNode = GetChild(root, "start");
GetChild(startNode, "foo");
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
cpu_profiler->DeleteAllCpuProfiles();
}
@@ -1059,24 +1026,11 @@ TEST(FunctionCallSample) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::New("start")));
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- v8::Local<v8::String> profile_name = v8::String::New("my_profile");
-
- cpu_profiler->StartCpuProfiling(profile_name);
int32_t duration_ms = 100;
-#if defined(_WIN32) || defined(_WIN64)
- // 100ms is not enough on Windows. See
- // https://code.google.com/p/v8/issues/detail?id=2628
- duration_ms = 400;
-#endif
v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
- function->Call(env->Global(), ARRAY_SIZE(args), args);
- const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
- CHECK_NE(NULL, profile);
- // Dump collected profile to have a better diagnostic in case of failure.
- reinterpret_cast<i::CpuProfile*>(
- const_cast<v8::CpuProfile*>(profile))->Print();
+ const v8::CpuProfile* profile =
+ RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
{
@@ -1110,6 +1064,7 @@ TEST(FunctionCallSample) {
CheckChildrenNames(unresolvedNode, names);
}
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
cpu_profiler->DeleteAllCpuProfiles();
}
@@ -1147,24 +1102,10 @@ TEST(FunctionApplySample) {
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::New("start")));
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- v8::Local<v8::String> profile_name = v8::String::New("my_profile");
-
- cpu_profiler->StartCpuProfiling(profile_name);
int32_t duration_ms = 100;
-#if defined(_WIN32) || defined(_WIN64)
- // 100ms is not enough on Windows. See
- // https://code.google.com/p/v8/issues/detail?id=2628
- duration_ms = 400;
-#endif
v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
- function->Call(env->Global(), ARRAY_SIZE(args), args);
- const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
-
- CHECK_NE(NULL, profile);
- // Dump collected profile to have a better diagnostic in case of failure.
- reinterpret_cast<i::CpuProfile*>(
- const_cast<v8::CpuProfile*>(profile))->Print();
+ const v8::CpuProfile* profile =
+ RunProfiler(env, function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
{
@@ -1202,5 +1143,6 @@ TEST(FunctionApplySample) {
}
}
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
cpu_profiler->DeleteAllCpuProfiles();
}
« no previous file with comments | « src/sampler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698