Reviewers: loislo, danno, Jakob,

Description:
Unflake cctest/test-cpu-profiler/JsNativeJsRuntimeJsSample on Win32 Debug

Profiler is now started from JavaScript. Since we always capture stack trace
when starting profiler there should always be at least one expected sample in
the profile.

Also changed ProfilerEventsProcessor::AddCurrentStack to make sure it call
TickSample::Init to instead of custom initialization code.

BUG=v8:2920

Please review this at https://codereview.chromium.org/25686011/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+48, -18 lines):
  M src/cpu-profiler.cc
  M test/cctest/test-cpu-profiler.cc


Index: src/cpu-profiler.cc
diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc
index 3d9dc6780b2aefac2f45ae619281ccbf5c036d3c..94677c10e260ca9d583962e6396b9390ed4b0c9a 100644
--- a/src/cpu-profiler.cc
+++ b/src/cpu-profiler.cc
@@ -64,14 +64,15 @@ void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) {

 void ProfilerEventsProcessor::AddCurrentStack(Isolate* isolate) {
   TickSampleEventRecord record(last_code_event_id_);
-  TickSample* sample = &record.sample;
-  sample->state = isolate->current_vm_state();
-  sample->pc = reinterpret_cast<Address>(sample);  // Not NULL.
-  for (StackTraceFrameIterator it(isolate);
-       !it.done() && sample->frames_count < TickSample::kMaxFramesCount;
-       it.Advance()) {
-    sample->stack[sample->frames_count++] = it.frame()->pc();
+  RegisterState regs;
+  StackFrameIterator it(isolate);
+  if (!it.done()) {
+    StackFrame* frame = it.frame();
+    regs.sp = frame->sp();
+    regs.fp = frame->fp();
+    regs.pc = frame->pc();
   }
+  record.sample.Init(isolate, regs);
   ticks_from_vm_buffer_.Enqueue(record);
 }

Index: test/cctest/test-cpu-profiler.cc
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc index 3fb5d3ae2cb636888b69e6acb52579ceafede81d..8ec96053381a6e211690d9f505bb11725a26dcd1 100644
--- a/test/cctest/test-cpu-profiler.cc
+++ b/test/cctest/test-cpu-profiler.cc
@@ -411,11 +411,13 @@ TEST(ProfileStartEndTime) {
 static const v8::CpuProfile* RunProfiler(
     LocalContext& env, v8::Handle<v8::Function> function,
     v8::Handle<v8::Value> argv[], int argc,
-    unsigned min_js_samples) {
+    unsigned min_js_samples, bool script_will_start_profiler = false) {
   v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
   v8::Local<v8::String> profile_name = v8::String::New("my_profile");

-  cpu_profiler->StartCpuProfiling(profile_name);
+  if (!script_will_start_profiler) {
+    cpu_profiler->StartCpuProfiling(profile_name);
+  }

   i::Sampler* sampler =
reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler(); @@ -475,7 +477,12 @@ static const v8::CpuProfileNode* FindChild(const v8::CpuProfileNode* node,
 static const v8::CpuProfileNode* GetChild(const v8::CpuProfileNode* node,
                                           const char* name) {
   const v8::CpuProfileNode* result = FindChild(node, name);
-  CHECK(result);
+  if (!result) {
+    char buffer[100];
+    i::OS::SNPrintF(Vector<char>(buffer, ARRAY_SIZE(buffer)),
+                    "Failed to GetChild: %s", name);
+    FATAL(buffer);
+  }
   return result;
 }

@@ -590,7 +597,7 @@ static const char* cpu_profiler_test_source2 = "function loop() {}\n"
 "  } while (++k < count*100*1000);\n"
 "}\n";

-// Check that the profile tree doesn't contain unexpecte traces:
+// Check that the profile tree doesn't contain unexpected traces:
 //  - 'loop' can be called only by 'delay'
 //  - 'delay' may be called only by 'start'
 // The profile will look like the following:
@@ -1081,7 +1088,13 @@ TEST(FunctionApplySample) {
 }


-static const char* js_native_js_test_source = "function foo(iterations) {\n"
+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"
@@ -1113,7 +1126,9 @@ static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) {
 //    55     1        bar #16 5
 //    54    54          foo #16 6
 TEST(JsNativeJsSample) {
-  LocalContext env;
+  const char* extensions[] = { "v8/profiler" };
+  v8::ExtensionConfiguration config(1, extensions);
+  LocalContext env(&config);
   v8::HandleScope scope(env->GetIsolate());

v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
@@ -1129,7 +1144,7 @@ TEST(JsNativeJsSample) {
   int32_t duration_ms = 20;
   v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
   const v8::CpuProfile* profile =
-      RunProfiler(env, function, args, ARRAY_SIZE(args), 50);
+      RunProfiler(env, function, args, ARRAY_SIZE(args), 10, true);

   const v8::CpuProfileNode* root = profile->GetTopDownRoot();
   {
@@ -1157,7 +1172,12 @@ 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"
@@ -1184,7 +1204,9 @@ static const char* js_native_js_runtime_js_test_source =
 //    51    51          foo #16 6
 //     2     2    (program) #0 2
 TEST(JsNativeJsRuntimeJsSample) {
-  LocalContext env;
+  const char* extensions[] = { "v8/profiler" };
+  v8::ExtensionConfiguration config(1, extensions);
+  LocalContext env(&config);
   v8::HandleScope scope(env->GetIsolate());

v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
@@ -1201,7 +1223,7 @@ TEST(JsNativeJsRuntimeJsSample) {
   int32_t duration_ms = 20;
   v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
   const v8::CpuProfile* profile =
-      RunProfiler(env, function, args, ARRAY_SIZE(args), 50);
+      RunProfiler(env, function, args, ARRAY_SIZE(args), 10, true);

   const v8::CpuProfileNode* root = profile->GetTopDownRoot();
   ScopedVector<v8::Handle<v8::String> > names(3);
@@ -1232,7 +1254,12 @@ 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"
+"    startProfiling('my_profile');\n"
+"  }\n"
 "  var r = 0;\n"
 "  for (var i = 0; i < iterations; i++) { r += i; }\n"
 "  return r;\n"
@@ -1259,7 +1286,9 @@ static const char* js_native1_js_native2_js_test_source =
 //    54    54            foo #16 7
 //     2     2    (program) #0 2
 TEST(JsNative1JsNative2JsSample) {
-  LocalContext env;
+  const char* extensions[] = { "v8/profiler" };
+  v8::ExtensionConfiguration config(1, extensions);
+  LocalContext env(&config);
   v8::HandleScope scope(env->GetIsolate());

v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
@@ -1281,7 +1310,7 @@ TEST(JsNative1JsNative2JsSample) {
   int32_t duration_ms = 20;
   v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) };
   const v8::CpuProfile* profile =
-      RunProfiler(env, function, args, ARRAY_SIZE(args), 50);
+      RunProfiler(env, function, args, ARRAY_SIZE(args), 10, true);

   const v8::CpuProfileNode* root = profile->GetTopDownRoot();
   ScopedVector<v8::Handle<v8::String> > names(3);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to