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

Side by Side Diff: src/perf-jit.cc

Issue 2558283002: [turbofan] Fix source position integration with Linux perf (Closed)
Patch Set: Remove redundant flags Created 4 years 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 unified diff | Download patch
« no previous file with comments | « src/flag-definitions.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 base::LockGuard<base::RecursiveMutex> guard_file(file_mutex_.Pointer()); 205 base::LockGuard<base::RecursiveMutex> guard_file(file_mutex_.Pointer());
206 206
207 if (perf_output_handle_ == nullptr) return; 207 if (perf_output_handle_ == nullptr) return;
208 208
209 // We only support non-interpreted functions. 209 // We only support non-interpreted functions.
210 if (!abstract_code->IsCode()) return; 210 if (!abstract_code->IsCode()) return;
211 Code* code = abstract_code->GetCode(); 211 Code* code = abstract_code->GetCode();
212 DCHECK(code->instruction_start() == code->address() + Code::kHeaderSize); 212 DCHECK(code->instruction_start() == code->address() + Code::kHeaderSize);
213 213
214 // Debug info has to be emitted first. 214 // Debug info has to be emitted first.
215 if (FLAG_perf_prof_debug_info && shared != nullptr) { 215 if (FLAG_perf_prof && shared != nullptr) {
216 LogWriteDebugInfo(code, shared); 216 LogWriteDebugInfo(code, shared);
217 } 217 }
218 218
219 const char* code_name = name; 219 const char* code_name = name;
220 uint8_t* code_pointer = reinterpret_cast<uint8_t*>(code->instruction_start()); 220 uint8_t* code_pointer = reinterpret_cast<uint8_t*>(code->instruction_start());
221 uint32_t code_size = code->is_crankshafted() ? code->safepoint_table_offset() 221 uint32_t code_size = code->is_crankshafted() ? code->safepoint_table_offset()
222 : code->instruction_size(); 222 : code->instruction_size();
223 223
224 // Unwinding info comes right after debug info. 224 // Unwinding info comes right after debug info.
225 if (FLAG_perf_prof_unwinding_info) LogWriteUnwindingInfo(code); 225 if (FLAG_perf_prof_unwinding_info) LogWriteUnwindingInfo(code);
(...skipping 13 matching lines...) Expand all
239 code_load.code_id_ = code_index_; 239 code_load.code_id_ = code_index_;
240 240
241 code_index_++; 241 code_index_++;
242 242
243 LogWriteBytes(reinterpret_cast<const char*>(&code_load), sizeof(code_load)); 243 LogWriteBytes(reinterpret_cast<const char*>(&code_load), sizeof(code_load));
244 LogWriteBytes(code_name, length); 244 LogWriteBytes(code_name, length);
245 LogWriteBytes(string_terminator, 1); 245 LogWriteBytes(string_terminator, 1);
246 LogWriteBytes(reinterpret_cast<const char*>(code_pointer), code_size); 246 LogWriteBytes(reinterpret_cast<const char*>(code_pointer), code_size);
247 } 247 }
248 248
249 namespace {
250
251 std::unique_ptr<char[]> GetScriptName(Handle<Script> script) {
252 Handle<Object> name_or_url(Script::GetNameOrSourceURL(script));
253 int name_length = 0;
254 std::unique_ptr<char[]> name_string;
255 if (name_or_url->IsString()) {
256 return Handle<String>::cast(name_or_url)
257 ->ToCString(DISALLOW_NULLS, FAST_STRING_TRAVERSAL, &name_length);
258 } else {
259 const char unknown[] = "<unknown>";
260 name_length = static_cast<int>(strlen(unknown));
261 char* buffer = NewArray<char>(name_length);
262 base::OS::StrNCpy(buffer, name_length + 1, unknown,
263 static_cast<size_t>(name_length));
264 return std::unique_ptr<char[]>(buffer);
265 }
266 }
267
268 SourcePositionInfo GetSourcePositionInfo(Handle<Code> code,
269 Handle<SharedFunctionInfo> function,
270 SourcePosition pos) {
271 if (code->is_turbofanned() || code->is_crankshafted()) {
272 return pos.InliningStack(code)[0];
273 } else {
274 return SourcePositionInfo(pos, function);
Tobias Tebbi 2016/12/09 14:57:51 This does not compute the line and column. Why not
danno 2016/12/12 09:53:56 Good question. Full code gen uses the deopt input
275 }
276 }
277
278 } // namespace
279
249 void PerfJitLogger::LogWriteDebugInfo(Code* code, SharedFunctionInfo* shared) { 280 void PerfJitLogger::LogWriteDebugInfo(Code* code, SharedFunctionInfo* shared) {
250 // Compute the entry count and get the name of the script. 281 // Compute the entry count and get the name of the script.
251 uint32_t entry_count = 0; 282 uint32_t entry_count = 0;
252 for (SourcePositionTableIterator iterator(code->source_position_table()); 283 for (SourcePositionTableIterator iterator(code->source_position_table());
253 !iterator.done(); iterator.Advance()) { 284 !iterator.done(); iterator.Advance()) {
254 entry_count++; 285 entry_count++;
255 } 286 }
256 if (entry_count == 0) return; 287 if (entry_count == 0) return;
257 Handle<Script> script(Script::cast(shared->script())); 288 Handle<Script> script(Script::cast(shared->script()));
258 Handle<Object> name_or_url(Script::GetNameOrSourceURL(script));
259
260 int name_length = 0;
261 std::unique_ptr<char[]> name_string;
262 if (name_or_url->IsString()) {
263 name_string =
264 Handle<String>::cast(name_or_url)
265 ->ToCString(DISALLOW_NULLS, FAST_STRING_TRAVERSAL, &name_length);
266 DCHECK_EQ(0, name_string.get()[name_length]);
267 } else {
268 const char unknown[] = "<unknown>";
269 name_length = static_cast<int>(strlen(unknown));
270 char* buffer = NewArray<char>(name_length);
271 base::OS::StrNCpy(buffer, name_length + 1, unknown,
272 static_cast<size_t>(name_length));
273 name_string = std::unique_ptr<char[]>(buffer);
274 }
275 DCHECK_EQ(name_length, static_cast<int>(strlen(name_string.get())));
276 289
277 PerfJitCodeDebugInfo debug_info; 290 PerfJitCodeDebugInfo debug_info;
278 291
279 debug_info.event_ = PerfJitCodeLoad::kDebugInfo; 292 debug_info.event_ = PerfJitCodeLoad::kDebugInfo;
280 debug_info.time_stamp_ = GetTimestamp(); 293 debug_info.time_stamp_ = GetTimestamp();
281 debug_info.address_ = reinterpret_cast<uint64_t>(code->instruction_start()); 294 debug_info.address_ = reinterpret_cast<uint64_t>(code->instruction_start());
282 debug_info.entry_count_ = entry_count; 295 debug_info.entry_count_ = entry_count;
283 296
284 uint32_t size = sizeof(debug_info); 297 uint32_t size = sizeof(debug_info);
285 // Add the sizes of fixed parts of entries. 298 // Add the sizes of fixed parts of entries.
286 size += entry_count * sizeof(PerfJitDebugEntry); 299 size += entry_count * sizeof(PerfJitDebugEntry);
287 // Add the size of the name after the first entry. 300 // Add the size of the name after the each entry.
Tobias Tebbi 2016/12/09 14:57:51 typo: after each entry.
danno 2016/12/12 09:53:56 Done.
288 size += (static_cast<uint32_t>(name_length) + 1) * entry_count; 301
302 Handle<Code> code_handle(code);
303 Handle<SharedFunctionInfo> function_handle(shared);
304 for (SourcePositionTableIterator iterator(code->source_position_table());
305 !iterator.done(); iterator.Advance()) {
306 SourcePositionInfo info(GetSourcePositionInfo(code_handle, function_handle,
307 iterator.source_position()));
308 Handle<Script> script(Script::cast(info.function->script()));
309 std::unique_ptr<char[]> name_string = GetScriptName(script);
310 size += (static_cast<uint32_t>(strlen(name_string.get())) + 1);
311 }
289 312
290 int padding = ((size + 7) & (~7)) - size; 313 int padding = ((size + 7) & (~7)) - size;
291
292 debug_info.size_ = size + padding; 314 debug_info.size_ = size + padding;
293
294 LogWriteBytes(reinterpret_cast<const char*>(&debug_info), sizeof(debug_info)); 315 LogWriteBytes(reinterpret_cast<const char*>(&debug_info), sizeof(debug_info));
295 316
296 int script_line_offset = script->line_offset();
297 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); 317 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends()));
298 Address code_start = code->instruction_start(); 318 Address code_start = code->instruction_start();
299 319
300 for (SourcePositionTableIterator iterator(code->source_position_table()); 320 for (SourcePositionTableIterator iterator(code->source_position_table());
301 !iterator.done(); iterator.Advance()) { 321 !iterator.done(); iterator.Advance()) {
302 int position = iterator.source_position().ScriptOffset(); 322 SourcePositionInfo info(GetSourcePositionInfo(code_handle, function_handle,
303 int line_number = Script::GetLineNumber(script, position); 323 iterator.source_position()));
304 // Compute column.
305 int relative_line_number = line_number - script_line_offset;
306 int start =
307 (relative_line_number == 0)
308 ? 0
309 : Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1;
310 int column_offset = position - start;
311 if (relative_line_number == 0) {
312 // For the case where the code is on the same line as the script tag.
313 column_offset += script->column_offset();
314 }
315
316 PerfJitDebugEntry entry; 324 PerfJitDebugEntry entry;
325 // TODO(danno): There seems to be a bug in the dwarf handling of JIT code in
326 // the perf tool. It seems to erroneously believe that the first instruction
327 // of functions is at offset 0x40 when displayed in "perf report". To
328 // compensate for this, add a magic constant to the position addresses when
329 // writing them out.
317 entry.address_ = 330 entry.address_ =
318 reinterpret_cast<uint64_t>(code_start + iterator.code_offset()); 331 reinterpret_cast<intptr_t>(code_start + iterator.code_offset() + 0x40);
319 entry.line_number_ = line_number; 332 entry.line_number_ = info.line + 1;
320 entry.column_ = column_offset; 333 entry.column_ = info.column + 1;
321 LogWriteBytes(reinterpret_cast<const char*>(&entry), sizeof(entry)); 334 LogWriteBytes(reinterpret_cast<const char*>(&entry), sizeof(entry));
322 LogWriteBytes(name_string.get(), name_length + 1); 335 Handle<Script> script(Script::cast(info.function->script()));
336 std::unique_ptr<char[]> name_string = GetScriptName(script);
337 LogWriteBytes(name_string.get(),
338 static_cast<uint32_t>(strlen(name_string.get())) + 1);
323 } 339 }
324 char padding_bytes[] = "\0\0\0\0\0\0\0\0"; 340 char padding_bytes[] = "\0\0\0\0\0\0\0\0";
325 LogWriteBytes(padding_bytes, padding); 341 LogWriteBytes(padding_bytes, padding);
326 } 342 }
327 343
328 void PerfJitLogger::LogWriteUnwindingInfo(Code* code) { 344 void PerfJitLogger::LogWriteUnwindingInfo(Code* code) {
329 PerfJitCodeUnwindingInfo unwinding_info_header; 345 PerfJitCodeUnwindingInfo unwinding_info_header;
330 unwinding_info_header.event_ = PerfJitCodeLoad::kUnwindingInfo; 346 unwinding_info_header.event_ = PerfJitCodeLoad::kUnwindingInfo;
331 unwinding_info_header.time_stamp_ = GetTimestamp(); 347 unwinding_info_header.time_stamp_ = GetTimestamp();
332 unwinding_info_header.eh_frame_hdr_size_ = EhFrameConstants::kEhFrameHdrSize; 348 unwinding_info_header.eh_frame_hdr_size_ = EhFrameConstants::kEhFrameHdrSize;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 header.time_stamp_ = 400 header.time_stamp_ =
385 static_cast<uint64_t>(base::OS::TimeCurrentMillis() * 1000.0); 401 static_cast<uint64_t>(base::OS::TimeCurrentMillis() * 1000.0);
386 header.flags_ = 0; 402 header.flags_ = 0;
387 403
388 LogWriteBytes(reinterpret_cast<const char*>(&header), sizeof(header)); 404 LogWriteBytes(reinterpret_cast<const char*>(&header), sizeof(header));
389 } 405 }
390 406
391 #endif // V8_OS_LINUX 407 #endif // V8_OS_LINUX
392 } // namespace internal 408 } // namespace internal
393 } // namespace v8 409 } // namespace v8
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698