Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/profiler/profiler-listener.h" | 5 #include "src/profiler/profiler-listener.h" |
| 6 | 6 |
| 7 #include "src/deoptimizer.h" | 7 #include "src/deoptimizer.h" |
| 8 #include "src/profiler/cpu-profiler.h" | 8 #include "src/profiler/cpu-profiler.h" |
| 9 #include "src/profiler/profile-generator-inl.h" | 9 #include "src/profiler/profile-generator-inl.h" |
| 10 #include "src/source-position-table.h" | 10 #include "src/source-position-table.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 Script* script = Script::cast(shared->script()); | 87 Script* script = Script::cast(shared->script()); |
| 88 JITLineInfoTable* line_table = NULL; | 88 JITLineInfoTable* line_table = NULL; |
| 89 if (script) { | 89 if (script) { |
| 90 line_table = new JITLineInfoTable(); | 90 line_table = new JITLineInfoTable(); |
| 91 int offset = abstract_code->IsCode() ? Code::kHeaderSize | 91 int offset = abstract_code->IsCode() ? Code::kHeaderSize |
| 92 : BytecodeArray::kHeaderSize; | 92 : BytecodeArray::kHeaderSize; |
| 93 int start_position = shared->start_position(); | 93 int start_position = shared->start_position(); |
| 94 int end_position = shared->end_position(); | 94 int end_position = shared->end_position(); |
| 95 for (SourcePositionTableIterator it(abstract_code->source_position_table()); | 95 for (SourcePositionTableIterator it(abstract_code->source_position_table()); |
| 96 !it.done(); it.Advance()) { | 96 !it.done(); it.Advance()) { |
| 97 if (it.source_position().InliningId() != SourcePosition::kNotInlined) | |
|
alph
2016/11/17 00:09:44
Why do you skip inlined positions?
If it's not rea
Tobias Tebbi
2016/11/17 11:41:34
Sorry, yes, the TODO should stay. I skip inlined p
| |
| 98 continue; | |
| 97 int position = it.source_position().ScriptOffset(); | 99 int position = it.source_position().ScriptOffset(); |
| 98 // TODO(alph): in case of inlining the position may correspond to an | |
| 99 // inlined function source code. Do not collect positions that fall | |
| 100 // beyond the function source code. There's however a chance the | |
| 101 // inlined function has similar positions but in another script. So | |
| 102 // the proper fix is to store script_id in some form along with the | |
| 103 // inlined function positions. | |
| 104 if (position < start_position || position >= end_position) continue; | |
| 105 int line_number = script->GetLineNumber(position) + 1; | 100 int line_number = script->GetLineNumber(position) + 1; |
| 106 int pc_offset = it.code_offset() + offset; | 101 int pc_offset = it.code_offset() + offset; |
| 107 line_table->SetPosition(pc_offset, line_number); | 102 line_table->SetPosition(pc_offset, line_number); |
| 108 } | 103 } |
| 109 } | 104 } |
| 110 rec->entry = NewCodeEntry( | 105 rec->entry = NewCodeEntry( |
| 111 tag, GetFunctionName(shared->DebugName()), CodeEntry::kEmptyNamePrefix, | 106 tag, GetFunctionName(shared->DebugName()), CodeEntry::kEmptyNamePrefix, |
| 112 GetName(InferScriptName(script_name, shared)), line, column, line_table, | 107 GetName(InferScriptName(script_name, shared)), line, column, line_table, |
| 113 abstract_code->instruction_start()); | 108 abstract_code->instruction_start()); |
| 114 RecordInliningInfo(rec->entry, abstract_code); | 109 RecordInliningInfo(rec->entry, abstract_code); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 DispatchCodeEvent(evt_rec); | 144 DispatchCodeEvent(evt_rec); |
| 150 } | 145 } |
| 151 | 146 |
| 152 void ProfilerListener::CodeDeoptEvent(Code* code, Address pc, | 147 void ProfilerListener::CodeDeoptEvent(Code* code, Address pc, |
| 153 int fp_to_sp_delta) { | 148 int fp_to_sp_delta) { |
| 154 CodeEventsContainer evt_rec(CodeEventRecord::CODE_DEOPT); | 149 CodeEventsContainer evt_rec(CodeEventRecord::CODE_DEOPT); |
| 155 CodeDeoptEventRecord* rec = &evt_rec.CodeDeoptEventRecord_; | 150 CodeDeoptEventRecord* rec = &evt_rec.CodeDeoptEventRecord_; |
| 156 Deoptimizer::DeoptInfo info = Deoptimizer::GetDeoptInfo(code, pc); | 151 Deoptimizer::DeoptInfo info = Deoptimizer::GetDeoptInfo(code, pc); |
| 157 rec->start = code->address(); | 152 rec->start = code->address(); |
| 158 rec->deopt_reason = DeoptimizeReasonToString(info.deopt_reason); | 153 rec->deopt_reason = DeoptimizeReasonToString(info.deopt_reason); |
| 159 rec->position = info.position; | |
| 160 rec->deopt_id = info.deopt_id; | 154 rec->deopt_id = info.deopt_id; |
| 161 rec->pc = reinterpret_cast<void*>(pc); | 155 rec->pc = reinterpret_cast<void*>(pc); |
| 162 rec->fp_to_sp_delta = fp_to_sp_delta; | 156 rec->fp_to_sp_delta = fp_to_sp_delta; |
| 163 DispatchCodeEvent(evt_rec); | 157 DispatchCodeEvent(evt_rec); |
| 164 } | 158 } |
| 165 | 159 |
| 166 void ProfilerListener::GetterCallbackEvent(Name* name, Address entry_point) { | 160 void ProfilerListener::GetterCallbackEvent(Name* name, Address entry_point) { |
| 167 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); | 161 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); |
| 168 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; | 162 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 169 rec->start = entry_point; | 163 rec->start = entry_point; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 if (!inline_stack.empty()) { | 241 if (!inline_stack.empty()) { |
| 248 entry->AddInlineStack(pc_offset, inline_stack); | 242 entry->AddInlineStack(pc_offset, inline_stack); |
| 249 DCHECK(inline_stack.empty()); | 243 DCHECK(inline_stack.empty()); |
| 250 } | 244 } |
| 251 } | 245 } |
| 252 } | 246 } |
| 253 | 247 |
| 254 void ProfilerListener::RecordDeoptInlinedFrames(CodeEntry* entry, | 248 void ProfilerListener::RecordDeoptInlinedFrames(CodeEntry* entry, |
| 255 AbstractCode* abstract_code) { | 249 AbstractCode* abstract_code) { |
| 256 if (abstract_code->kind() != AbstractCode::OPTIMIZED_FUNCTION) return; | 250 if (abstract_code->kind() != AbstractCode::OPTIMIZED_FUNCTION) return; |
| 257 Code* code = abstract_code->GetCode(); | 251 Handle<Code> code(abstract_code->GetCode()); |
|
alph
2016/11/17 00:09:44
Why it needs a handle?
Tobias Tebbi
2016/11/17 11:41:34
It needs a handle because last_position.InliningSt
alph
2016/11/18 22:51:46
Makes sense. Thanks. Handles are slower than raw a
| |
| 258 DeoptimizationInputData* deopt_input_data = | 252 |
| 259 DeoptimizationInputData::cast(code->deoptimization_data()); | 253 SourcePosition last_position = SourcePosition::Unknown(); |
| 260 int const mask = RelocInfo::ModeMask(RelocInfo::DEOPT_ID); | 254 int mask = RelocInfo::ModeMask(RelocInfo::DEOPT_ID) | |
| 261 for (RelocIterator rit(code, mask); !rit.done(); rit.next()) { | 255 RelocInfo::ModeMask(RelocInfo::DEOPT_SCRIPT_OFFSET) | |
| 262 RelocInfo* reloc_info = rit.rinfo(); | 256 RelocInfo::ModeMask(RelocInfo::DEOPT_INLINING_ID); |
| 263 DCHECK(RelocInfo::IsDeoptId(reloc_info->rmode())); | 257 for (RelocIterator it(*code, mask); !it.done(); it.next()) { |
| 264 int deopt_id = static_cast<int>(reloc_info->data()); | 258 RelocInfo* info = it.rinfo(); |
| 265 int translation_index = | 259 if (info->rmode() == RelocInfo::DEOPT_SCRIPT_OFFSET) { |
| 266 deopt_input_data->TranslationIndex(deopt_id)->value(); | 260 int script_offset = static_cast<int>(info->data()); |
| 267 TranslationIterator it(deopt_input_data->TranslationByteArray(), | 261 it.next(); |
| 268 translation_index); | 262 DCHECK(it.rinfo()->rmode() == RelocInfo::DEOPT_INLINING_ID); |
| 269 Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); | 263 int inlining_id = static_cast<int>(it.rinfo()->data()); |
| 270 DCHECK_EQ(Translation::BEGIN, opcode); | 264 last_position = SourcePosition(script_offset, inlining_id); |
|
alph
2016/11/17 00:09:44
nit: use continue
| |
| 271 it.Skip(Translation::NumberOfOperandsFor(opcode)); | 265 } else if (info->rmode() == RelocInfo::DEOPT_ID) { |
| 272 std::vector<CodeEntry::DeoptInlinedFrame> inlined_frames; | 266 int deopt_id = static_cast<int>(info->data()); |
| 273 while (it.HasNext() && | 267 if (!last_position.IsKnown()) continue; |
| 274 Translation::BEGIN != | 268 std::vector<CpuProfileDeoptFrame> inlined_frames; |
| 275 (opcode = static_cast<Translation::Opcode>(it.Next()))) { | 269 for (SourcePositionInfo& pos_info : last_position.InliningStack(code)) { |
| 276 if (opcode != Translation::JS_FRAME && | 270 DCHECK(pos_info.position.ScriptOffset() != kNoSourcePosition); |
| 277 opcode != Translation::INTERPRETED_FRAME) { | 271 size_t offset = static_cast<size_t>(pos_info.position.ScriptOffset()); |
| 278 it.Skip(Translation::NumberOfOperandsFor(opcode)); | 272 int script_id = Script::cast(pos_info.function->script())->id(); |
| 279 continue; | 273 inlined_frames.push_back(CpuProfileDeoptFrame({script_id, offset})); |
| 280 } | 274 } |
| 281 BailoutId ast_id = BailoutId(it.Next()); | 275 if (!inlined_frames.empty() && |
| 282 int shared_info_id = it.Next(); | 276 !entry->HasDeoptInlinedFramesFor(deopt_id)) { |
| 283 it.Next(); // Skip height | 277 entry->AddDeoptInlinedFrames(deopt_id, inlined_frames); |
| 284 SharedFunctionInfo* shared = SharedFunctionInfo::cast( | 278 DCHECK(inlined_frames.empty()); |
| 285 deopt_input_data->LiteralArray()->get(shared_info_id)); | |
| 286 int source_position; | |
| 287 if (opcode == Translation::INTERPRETED_FRAME) { | |
| 288 source_position = | |
| 289 Deoptimizer::ComputeSourcePositionFromBytecodeArray(shared, ast_id); | |
| 290 } else { | |
| 291 DCHECK(opcode == Translation::JS_FRAME); | |
| 292 source_position = | |
| 293 Deoptimizer::ComputeSourcePositionFromBaselineCode(shared, ast_id); | |
| 294 } | 279 } |
| 295 int script_id = v8::UnboundScript::kNoScriptId; | |
| 296 if (shared->script()->IsScript()) { | |
| 297 Script* script = Script::cast(shared->script()); | |
| 298 script_id = script->id(); | |
| 299 } | |
| 300 CodeEntry::DeoptInlinedFrame frame = {source_position, script_id}; | |
| 301 inlined_frames.push_back(frame); | |
| 302 } | |
| 303 if (!inlined_frames.empty() && !entry->HasDeoptInlinedFramesFor(deopt_id)) { | |
| 304 entry->AddDeoptInlinedFrames(deopt_id, inlined_frames); | |
| 305 DCHECK(inlined_frames.empty()); | |
| 306 } | 280 } |
| 307 } | 281 } |
| 308 } | 282 } |
| 309 | 283 |
| 310 CodeEntry* ProfilerListener::NewCodeEntry( | 284 CodeEntry* ProfilerListener::NewCodeEntry( |
| 311 CodeEventListener::LogEventsAndTags tag, const char* name, | 285 CodeEventListener::LogEventsAndTags tag, const char* name, |
| 312 const char* name_prefix, const char* resource_name, int line_number, | 286 const char* name_prefix, const char* resource_name, int line_number, |
| 313 int column_number, JITLineInfoTable* line_info, Address instruction_start) { | 287 int column_number, JITLineInfoTable* line_info, Address instruction_start) { |
| 314 CodeEntry* code_entry = | 288 CodeEntry* code_entry = |
| 315 new CodeEntry(tag, name, name_prefix, resource_name, line_number, | 289 new CodeEntry(tag, name, name_prefix, resource_name, line_number, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 328 | 302 |
| 329 void ProfilerListener::RemoveObserver(CodeEventObserver* observer) { | 303 void ProfilerListener::RemoveObserver(CodeEventObserver* observer) { |
| 330 base::LockGuard<base::Mutex> guard(&mutex_); | 304 base::LockGuard<base::Mutex> guard(&mutex_); |
| 331 auto it = std::find(observers_.begin(), observers_.end(), observer); | 305 auto it = std::find(observers_.begin(), observers_.end(), observer); |
| 332 if (it == observers_.end()) return; | 306 if (it == observers_.end()) return; |
| 333 observers_.erase(it); | 307 observers_.erase(it); |
| 334 } | 308 } |
| 335 | 309 |
| 336 } // namespace internal | 310 } // namespace internal |
| 337 } // namespace v8 | 311 } // namespace v8 |
| OLD | NEW |