// Enqueue code creation events.
const char* aaa_str = "aaa";
- i::Handle<i::String> aaa_name = factory->NewStringFromAscii(
- i::Vector<const char>(aaa_str, i::StrLength(aaa_str)));
+ i::Handle<i::String> aaa_name = factory->NewStringFromAsciiChecked(aaa_str);
profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name);
profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment");
profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5);
CHECK_EQ(0, iprofiler->GetProfilesCount());
v8::Local<v8::String> name1 = v8::String::NewFromUtf8(env->GetIsolate(), "1");
- cpu_profiler->StartCpuProfiling(name1);
- const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1);
+ cpu_profiler->StartProfiling(name1);
+ v8::CpuProfile* p1 = cpu_profiler->StopProfiling(name1);
CHECK_NE(NULL, p1);
CHECK_EQ(1, iprofiler->GetProfilesCount());
CHECK(FindCpuProfile(cpu_profiler, p1));
- const_cast<v8::CpuProfile*>(p1)->Delete();
+ p1->Delete();
CHECK_EQ(0, iprofiler->GetProfilesCount());
v8::Local<v8::String> name2 = v8::String::NewFromUtf8(env->GetIsolate(), "2");
- cpu_profiler->StartCpuProfiling(name2);
- const v8::CpuProfile* p2 = cpu_profiler->StopCpuProfiling(name2);
+ cpu_profiler->StartProfiling(name2);
+ v8::CpuProfile* p2 = cpu_profiler->StopProfiling(name2);
CHECK_NE(NULL, p2);
CHECK_EQ(1, iprofiler->GetProfilesCount());
CHECK(FindCpuProfile(cpu_profiler, p2));
v8::Local<v8::String> name3 = v8::String::NewFromUtf8(env->GetIsolate(), "3");
- cpu_profiler->StartCpuProfiling(name3);
- const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3);
+ cpu_profiler->StartProfiling(name3);
+ v8::CpuProfile* p3 = cpu_profiler->StopProfiling(name3);
CHECK_NE(NULL, p3);
CHECK_EQ(2, iprofiler->GetProfilesCount());
CHECK_NE(p2, p3);
CHECK(FindCpuProfile(cpu_profiler, p3));
CHECK(FindCpuProfile(cpu_profiler, p2));
- const_cast<v8::CpuProfile*>(p2)->Delete();
+ p2->Delete();
CHECK_EQ(1, iprofiler->GetProfilesCount());
CHECK(!FindCpuProfile(cpu_profiler, p2));
CHECK(FindCpuProfile(cpu_profiler, p3));
- const_cast<v8::CpuProfile*>(p3)->Delete();
+ p3->Delete();
CHECK_EQ(0, iprofiler->GetProfilesCount());
}
v8::Local<v8::String> profile_name =
v8::String::NewFromUtf8(env->GetIsolate(), "test");
- cpu_profiler->StartCpuProfiling(profile_name);
- const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
+ cpu_profiler->StartProfiling(profile_name);
+ const v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
CHECK(profile->GetStartTime() <= profile->GetEndTime());
}
-static const v8::CpuProfile* RunProfiler(
+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) {
+ unsigned min_js_samples, 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->StartCpuProfiling(profile_name);
+ cpu_profiler->StartProfiling(profile_name, collect_samples);
i::Sampler* sampler =
reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler();
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);
+ v8::CpuProfile* profile = cpu_profiler->StopProfiling(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();
+ reinterpret_cast<i::CpuProfile*>(profile)->Print();
return profile;
}
v8::Handle<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), profiling_interval_ms)
};
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200);
function->Call(env->Global(), ARRAY_SIZE(args), args);
CheckSimpleBranch(env->GetIsolate(), fooNode, delayBranch,
ARRAY_SIZE(delayBranch));
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
+TEST(CollectCpuProfileSamples) {
+ LocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+
+ v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
+ cpu_profiler_test_source))->Run();
+ v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
+
+ int32_t profiling_interval_ms = 200;
+ 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);
+
+ CHECK_LE(200, profile->GetSamplesCount());
+ uint64_t end_time = profile->GetEndTime();
+ uint64_t current_time = profile->GetStartTime();
+ CHECK_LE(current_time, end_time);
+ for (int i = 0; i < profile->GetSamplesCount(); i++) {
+ CHECK_NE(NULL, profile->GetSample(i));
+ uint64_t timestamp = profile->GetSampleTimestamp(i);
+ CHECK_LE(current_time, timestamp);
+ CHECK_LE(timestamp, end_time);
+ current_time = timestamp;
+ }
+
+ profile->Delete();
+}
+
static const char* cpu_profiler_test_source2 = "function loop() {}\n"
"function delay() { loop(); }\n"
v8::Handle<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), repeat_count)
};
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
}
}
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
int32_t repeat_count = 1;
v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) };
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 180);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
GetChild(isolate, startNode, "get foo");
GetChild(isolate, startNode, "set foo");
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
int32_t repeat_count = 100;
v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) };
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
GetChild(isolate, startNode, "get foo");
GetChild(isolate, startNode, "set foo");
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
int32_t repeat_count = 1;
v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) };
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
GetChild(isolate, root, "start");
GetChild(isolate, startNode, "fooMethod");
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
int32_t repeat_count = 100;
v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) };
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
GetChild(isolate, root, "start");
GetChild(isolate, startNode, "fooMethod");
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
v8::Handle<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), duration_ms)
};
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
GetChild(env->GetIsolate(), root, "start");
GetChild(env->GetIsolate(), startNode, "foo");
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
v8::Handle<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), duration_ms)
};
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
CheckChildrenNames(unresolvedNode, names);
}
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
v8::Integer::New(env->GetIsolate(), duration_ms)
};
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
}
}
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
v8::Handle<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), duration_ms)
};
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
CHECK_EQ(1, barNode->GetChildrenCount());
GetChild(env->GetIsolate(), barNode, "foo");
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
v8::Handle<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), duration_ms)
};
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
CHECK_EQ(1, barNode->GetChildrenCount());
GetChild(env->GetIsolate(), barNode, "foo");
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
v8::Handle<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), duration_ms)
};
- const v8::CpuProfile* profile =
+ v8::CpuProfile* profile =
RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
CHECK_EQ(1, nativeNode2->GetChildrenCount());
GetChild(env->GetIsolate(), nativeNode2, "foo");
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
v8::Local<v8::String> profile_name =
v8::String::NewFromUtf8(env->GetIsolate(), "my_profile");
- cpu_profiler->StartCpuProfiling(profile_name);
+ cpu_profiler->StartProfiling(profile_name);
i::Isolate* isolate = CcTest::i_isolate();
i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor();
processor->AddCurrentStack(isolate);
- const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
+ v8::CpuProfile* profile = cpu_profiler->StopProfiling(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();
+ reinterpret_cast<i::CpuProfile*>(profile)->Print();
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3);
CHECK_EQ(0, idleNode->GetChildrenCount());
CHECK_GE(idleNode->GetHitCount(), 3);
- const_cast<v8::CpuProfile*>(profile)->Delete();
+ profile->Delete();
}
CHECK_EQ(0, iprofiler->GetProfilesCount());
v8::Handle<v8::String> outer = v8::String::NewFromUtf8(isolate, "outer");
- profiler->StartCpuProfiling(outer);
+ profiler->StartProfiling(outer);
CHECK_EQ(0, iprofiler->GetProfilesCount());
v8::Handle<v8::String> inner = v8::String::NewFromUtf8(isolate, "inner");
- profiler->StartCpuProfiling(inner);
+ profiler->StartProfiling(inner);
CHECK_EQ(0, iprofiler->GetProfilesCount());
- const v8::CpuProfile* inner_profile = profiler->StopCpuProfiling(inner);
+ v8::CpuProfile* inner_profile = profiler->StopProfiling(inner);
CHECK(inner_profile);
CHECK_EQ(1, iprofiler->GetProfilesCount());
- const_cast<v8::CpuProfile*>(inner_profile)->Delete();
+ inner_profile->Delete();
inner_profile = NULL;
CHECK_EQ(0, iprofiler->GetProfilesCount());
- const v8::CpuProfile* outer_profile = profiler->StopCpuProfiling(outer);
+ v8::CpuProfile* outer_profile = profiler->StopProfiling(outer);
CHECK(outer_profile);
CHECK_EQ(1, iprofiler->GetProfilesCount());
- const_cast<v8::CpuProfile*>(outer_profile)->Delete();
+ outer_profile->Delete();
outer_profile = NULL;
CHECK_EQ(0, iprofiler->GetProfilesCount());
}