Fix bug with long stack traces truncation in DevTools CPU profiler.
authormikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 19 May 2011 08:25:38 +0000 (08:25 +0000)
committermikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 19 May 2011 08:25:38 +0000 (08:25 +0000)
R=sgjesse@chromium.org,vitalyr@chromium.org
BUG=1398
TEST=cctest/test-cpu-profiler/Issue1398

Review URL: http://codereview.chromium.org/7046001

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7949 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/cpu-profiler.cc
test/cctest/test-cpu-profiler.cc

index 8d11e7a00b7e60a6da6cac1c1a1a57e4b7b97740..f54e3e882e18ce31aeacda24c9297541e215e037 100644 (file)
@@ -244,7 +244,7 @@ bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) {
       // A paranoid check to make sure that we don't get a memory overrun
       // in case of frames_count having a wild value.
       if (record.sample.frames_count < 0
-          || record.sample.frames_count >= TickSample::kMaxFramesCount)
+          || record.sample.frames_count > TickSample::kMaxFramesCount)
         record.sample.frames_count = 0;
       generator_->RecordTickSample(record.sample);
       ticks_buffer_.FinishDequeue();
index 749ac154340bda2e4ec91e86158e5cb212614d90..17611acbf91409a796146dca528c85cf23d53da2 100644 (file)
@@ -238,6 +238,49 @@ TEST(CrashIfStoppingLastNonExistentProfile) {
 }
 
 
+// http://code.google.com/p/v8/issues/detail?id=1398
+// Long stacks (exceeding max frames limit) must not be erased.
+TEST(Issue1398) {
+  TestSetup test_setup;
+  CpuProfilesCollection profiles;
+  profiles.StartProfiling("", 1);
+  ProfileGenerator generator(&profiles);
+  ProfilerEventsProcessor processor(i::Isolate::Current(), &generator);
+  processor.Start();
+  while (!processor.running()) {
+    i::Thread::YieldCPU();
+  }
+
+  processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
+                            "bbb",
+                            ToAddress(0x1200),
+                            0x80);
+
+  i::TickSample* sample = processor.TickSampleEvent();
+  sample->pc = ToAddress(0x1200);
+  sample->tos = 0;
+  sample->frames_count = i::TickSample::kMaxFramesCount;
+  for (int i = 0; i < sample->frames_count; ++i) {
+    sample->stack[i] = ToAddress(0x1200);
+  }
+
+  processor.Stop();
+  processor.Join();
+  CpuProfile* profile =
+      profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
+  CHECK_NE(NULL, profile);
+
+  int actual_depth = 0;
+  const ProfileNode* node = profile->top_down()->root();
+  while (node->children()->length() > 0) {
+    node = node->children()->last();
+    ++actual_depth;
+  }
+
+  CHECK_EQ(1 + i::TickSample::kMaxFramesCount, actual_depth);  // +1 for PC.
+}
+
+
 TEST(DeleteAllCpuProfiles) {
   InitializeVM();
   TestSetup test_setup;