Commit c1f653be authored by alph's avatar alph Committed by Commit bot

Do not record CPU profile samples when stack collection is failed.

BUG=559304
LOG=N

Review URL: https://codereview.chromium.org/1709873002

Cr-Commit-Position: refs/heads/master@{#34168}
parent 0e9ea48c
...@@ -360,7 +360,7 @@ void CpuProfile::AddPath(base::TimeTicks timestamp, ...@@ -360,7 +360,7 @@ void CpuProfile::AddPath(base::TimeTicks timestamp,
bool update_stats) { bool update_stats) {
ProfileNode* top_frame_node = ProfileNode* top_frame_node =
top_down_.AddPathFromEnd(path, src_line, update_stats); top_down_.AddPathFromEnd(path, src_line, update_stats);
if (record_samples_) { if (record_samples_ && !timestamp.IsNull()) {
timestamps_.Add(timestamp); timestamps_.Add(timestamp);
samples_.Add(top_frame_node); samples_.Add(top_frame_node);
} }
...@@ -636,10 +636,9 @@ void ProfileGenerator::RecordTickSample(const TickSample& sample) { ...@@ -636,10 +636,9 @@ void ProfileGenerator::RecordTickSample(const TickSample& sample) {
} }
} }
for (const Address* stack_pos = sample.stack, for (const Address *stack_pos = sample.stack,
*stack_end = stack_pos + sample.frames_count; *stack_end = stack_pos + sample.frames_count;
stack_pos != stack_end; stack_pos != stack_end; ++stack_pos) {
++stack_pos) {
*entry = code_map_.FindEntry(*stack_pos); *entry = code_map_.FindEntry(*stack_pos);
// Skip unresolved frames (e.g. internal frame) and get source line of // Skip unresolved frames (e.g. internal frame) and get source line of
......
...@@ -671,6 +671,8 @@ DISABLE_ASAN void TickSample::Init(Isolate* isolate, ...@@ -671,6 +671,8 @@ DISABLE_ASAN void TickSample::Init(Isolate* isolate,
if (js_entry_sp == 0) return; // Not executing JS now. if (js_entry_sp == 0) return; // Not executing JS now.
if (pc && IsNoFrameRegion(pc)) { if (pc && IsNoFrameRegion(pc)) {
// Can't collect stack. Mark the sample as spoiled.
timestamp = base::TimeTicks();
pc = 0; pc = 0;
return; return;
} }
...@@ -701,6 +703,12 @@ DISABLE_ASAN void TickSample::Init(Isolate* isolate, ...@@ -701,6 +703,12 @@ DISABLE_ASAN void TickSample::Init(Isolate* isolate,
GetStackSample(isolate, regs, record_c_entry_frame, GetStackSample(isolate, regs, record_c_entry_frame,
reinterpret_cast<void**>(&stack[0]), kMaxFramesCount, &info); reinterpret_cast<void**>(&stack[0]), kMaxFramesCount, &info);
frames_count = static_cast<unsigned>(info.frames_count); frames_count = static_cast<unsigned>(info.frames_count);
if (!frames_count) {
// It is executing JS but failed to collect a stack trace.
// Mark the sample as spoiled.
timestamp = base::TimeTicks();
pc = 0;
}
} }
...@@ -797,7 +805,7 @@ void Sampler::SampleStack(const v8::RegisterState& state) { ...@@ -797,7 +805,7 @@ void Sampler::SampleStack(const v8::RegisterState& state) {
TickSample sample_obj; TickSample sample_obj;
if (sample == NULL) sample = &sample_obj; if (sample == NULL) sample = &sample_obj;
sample->Init(isolate_, state, TickSample::kIncludeCEntryFrame, true); sample->Init(isolate_, state, TickSample::kIncludeCEntryFrame, true);
if (is_counting_samples_) { if (is_counting_samples_ && !sample->timestamp.IsNull()) {
if (sample->state == JS) ++js_sample_count_; if (sample->state == JS) ++js_sample_count_;
if (sample->state == EXTERNAL) ++external_sample_count_; if (sample->state == EXTERNAL) ++external_sample_count_;
} }
......
...@@ -428,11 +428,13 @@ TEST(SampleIds) { ...@@ -428,11 +428,13 @@ TEST(SampleIds) {
// (root)#1 -> aaa #2 -> bbb #4 -> ccc #5 - sample2 // (root)#1 -> aaa #2 -> bbb #4 -> ccc #5 - sample2
// -> ccc #6 -> aaa #7 - sample3 // -> ccc #6 -> aaa #7 - sample3
TickSample sample1; TickSample sample1;
sample1.timestamp = v8::base::TimeTicks::HighResolutionNow();
sample1.pc = ToAddress(0x1600); sample1.pc = ToAddress(0x1600);
sample1.stack[0] = ToAddress(0x1510); sample1.stack[0] = ToAddress(0x1510);
sample1.frames_count = 1; sample1.frames_count = 1;
generator.RecordTickSample(sample1); generator.RecordTickSample(sample1);
TickSample sample2; TickSample sample2;
sample2.timestamp = v8::base::TimeTicks::HighResolutionNow();
sample2.pc = ToAddress(0x1925); sample2.pc = ToAddress(0x1925);
sample2.stack[0] = ToAddress(0x1780); sample2.stack[0] = ToAddress(0x1780);
sample2.stack[1] = ToAddress(0x10000); // non-existent. sample2.stack[1] = ToAddress(0x10000); // non-existent.
...@@ -440,6 +442,7 @@ TEST(SampleIds) { ...@@ -440,6 +442,7 @@ TEST(SampleIds) {
sample2.frames_count = 3; sample2.frames_count = 3;
generator.RecordTickSample(sample2); generator.RecordTickSample(sample2);
TickSample sample3; TickSample sample3;
sample3.timestamp = v8::base::TimeTicks::HighResolutionNow();
sample3.pc = ToAddress(0x1510); sample3.pc = ToAddress(0x1510);
sample3.stack[0] = ToAddress(0x1910); sample3.stack[0] = ToAddress(0x1910);
sample3.stack[1] = ToAddress(0x1610); sample3.stack[1] = ToAddress(0x1610);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment