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

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

Issue 1631043002: Add CollectSample API function to CpuProfiler (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix tests. Created 4 years, 11 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/profiler/sampler.cc ('k') | test/cctest/trace-extension.cc » ('j') | 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 29a24e62dfd72fdecbb46630a6e7172a019c088a..3af4dd220cdf43ee0146dba83bc6ab7c0ffac5e9 100644
--- a/test/cctest/test-cpu-profiler.cc
+++ b/test/cctest/test-cpu-profiler.cc
@@ -1603,11 +1603,52 @@ TEST(JsNative1JsNative2JsSample) {
profile->Delete();
}
+static const char* js_force_collect_sample_source =
+ "function start() {\n"
+ " CallCollectSample();\n"
+ "}";
+
+static void CallCollectSample(const v8::FunctionCallbackInfo<v8::Value>& info) {
+ info.GetIsolate()->GetCpuProfiler()->CollectSample();
+}
+
+TEST(CollectSampleAPI) {
+ v8::HandleScope scope(CcTest::isolate());
+ 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(), CallCollectSample);
+ v8::Local<v8::Function> func =
+ func_template->GetFunction(env).ToLocalChecked();
+ func->SetName(v8_str("CallCollectSample"));
+ env->Global()->Set(env, v8_str("CallCollectSample"), func).FromJust();
+
+ 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();
+ {
+ 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_LE(1, startNode->GetChildrenCount());
+ GetChild(env, startNode, "CallCollectSample");
+
+ profile->Delete();
+}
// [Top down]:
-// 6 0 (root) #0 1
-// 3 3 (program) #0 2
-// 3 3 (idle) #0 3
+// 0 (root) #0 1
+// 2 (program) #0 2
+// 3 (idle) #0 3
TEST(IdleTime) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
@@ -1618,17 +1659,16 @@ TEST(IdleTime) {
i::Isolate* isolate = CcTest::i_isolate();
i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor();
- processor->AddCurrentStack(isolate);
+ processor->AddCurrentStack(isolate, true);
cpu_profiler->SetIdle(true);
for (int i = 0; i < 3; i++) {
- processor->AddCurrentStack(isolate);
+ processor->AddCurrentStack(isolate, true);
}
cpu_profiler->SetIdle(false);
- processor->AddCurrentStack(isolate);
-
+ processor->AddCurrentStack(isolate, true);
v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
CHECK(profile);
@@ -1645,7 +1685,7 @@ TEST(IdleTime) {
const v8::CpuProfileNode* programNode =
GetChild(env.local(), root, ProfileGenerator::kProgramEntryName);
CHECK_EQ(0, programNode->GetChildrenCount());
- CHECK_GE(programNode->GetHitCount(), 3u);
+ CHECK_GE(programNode->GetHitCount(), 2u);
const v8::CpuProfileNode* idleNode =
GetChild(env.local(), root, ProfileGenerator::kIdleEntryName);
« no previous file with comments | « src/profiler/sampler.cc ('k') | test/cctest/trace-extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698