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

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

Issue 2558283002: [turbofan] Fix source position integration with Linux perf (Closed)
Patch Set: Remove dead code 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/isolate.cc ('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 Object* name_or_url = script->GetNameOrSourceURL();
253 int name_length = 0;
254 std::unique_ptr<char[]> name_string;
255 if (name_or_url->IsString()) {
256 return 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 DisallowHeapAllocation disallow;
273 return pos.InliningStack(code)[0];
274 } else {
275 return SourcePositionInfo(pos, function);
276 }
277 }
278
279 } // namespace
280
249 void PerfJitLogger::LogWriteDebugInfo(Code* code, SharedFunctionInfo* shared) { 281 void PerfJitLogger::LogWriteDebugInfo(Code* code, SharedFunctionInfo* shared) {
250 DisallowHeapAllocation no_gc;
251 // Compute the entry count and get the name of the script. 282 // Compute the entry count and get the name of the script.
252 uint32_t entry_count = 0; 283 uint32_t entry_count = 0;
253 for (SourcePositionTableIterator iterator(code->source_position_table()); 284 for (SourcePositionTableIterator iterator(code->source_position_table());
254 !iterator.done(); iterator.Advance()) { 285 !iterator.done(); iterator.Advance()) {
255 entry_count++; 286 entry_count++;
256 } 287 }
257 if (entry_count == 0) return; 288 if (entry_count == 0) return;
258 Script* script = Script::cast(shared->script()); 289 Handle<Script> script(Script::cast(shared->script()));
259 Object* name_or_url = script->GetNameOrSourceURL();
260
261 int name_length = 0;
262 std::unique_ptr<char[]> name_string;
263 if (name_or_url->IsString()) {
264 name_string =
265 String::cast(name_or_url)
266 ->ToCString(DISALLOW_NULLS, FAST_STRING_TRAVERSAL, &name_length);
267 DCHECK_EQ(0, name_string.get()[name_length]);
268 } else {
269 const char unknown[] = "<unknown>";
270 name_length = static_cast<int>(strlen(unknown));
271 char* buffer = NewArray<char>(name_length);
272 base::OS::StrNCpy(buffer, name_length + 1, unknown,
273 static_cast<size_t>(name_length));
274 name_string = std::unique_ptr<char[]>(buffer);
275 }
276 DCHECK_EQ(name_length, static_cast<int>(strlen(name_string.get())));
277 290
278 PerfJitCodeDebugInfo debug_info; 291 PerfJitCodeDebugInfo debug_info;
279 292
280 debug_info.event_ = PerfJitCodeLoad::kDebugInfo; 293 debug_info.event_ = PerfJitCodeLoad::kDebugInfo;
281 debug_info.time_stamp_ = GetTimestamp(); 294 debug_info.time_stamp_ = GetTimestamp();
282 debug_info.address_ = reinterpret_cast<uint64_t>(code->instruction_start()); 295 debug_info.address_ = reinterpret_cast<uint64_t>(code->instruction_start());
283 debug_info.entry_count_ = entry_count; 296 debug_info.entry_count_ = entry_count;
284 297
285 uint32_t size = sizeof(debug_info); 298 uint32_t size = sizeof(debug_info);
286 // Add the sizes of fixed parts of entries. 299 // Add the sizes of fixed parts of entries.
287 size += entry_count * sizeof(PerfJitDebugEntry); 300 size += entry_count * sizeof(PerfJitDebugEntry);
288 // Add the size of the name after the first entry. 301 // Add the size of the name after each entry.
289 size += (static_cast<uint32_t>(name_length) + 1) * entry_count; 302
303 Handle<Code> code_handle(code);
304 Handle<SharedFunctionInfo> function_handle(shared);
305 for (SourcePositionTableIterator iterator(code->source_position_table());
306 !iterator.done(); iterator.Advance()) {
307 SourcePositionInfo info(GetSourcePositionInfo(code_handle, function_handle,
308 iterator.source_position()));
309 Handle<Script> script(Script::cast(info.function->script()));
310 std::unique_ptr<char[]> name_string = GetScriptName(script);
311 size += (static_cast<uint32_t>(strlen(name_string.get())) + 1);
312 }
290 313
291 int padding = ((size + 7) & (~7)) - size; 314 int padding = ((size + 7) & (~7)) - size;
292
293 debug_info.size_ = size + padding; 315 debug_info.size_ = size + padding;
294
295 LogWriteBytes(reinterpret_cast<const char*>(&debug_info), sizeof(debug_info)); 316 LogWriteBytes(reinterpret_cast<const char*>(&debug_info), sizeof(debug_info));
296 317
297 int script_line_offset = script->line_offset();
298 FixedArray* line_ends = FixedArray::cast(script->line_ends());
299 Address code_start = code->instruction_start(); 318 Address code_start = code->instruction_start();
300 319
301 for (SourcePositionTableIterator iterator(code->source_position_table()); 320 for (SourcePositionTableIterator iterator(code->source_position_table());
302 !iterator.done(); iterator.Advance()) { 321 !iterator.done(); iterator.Advance()) {
303 int position = iterator.source_position().ScriptOffset(); 322 SourcePositionInfo info(GetSourcePositionInfo(code_handle, function_handle,
304 int line_number = script->GetLineNumber(position); 323 iterator.source_position()));
305 // Compute column.
306 int relative_line_number = line_number - script_line_offset;
307 int start =
308 (relative_line_number == 0)
309 ? 0
310 : Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1;
311 int column_offset = position - start;
312 if (relative_line_number == 0) {
313 // For the case where the code is on the same line as the script tag.
314 column_offset += script->column_offset();
315 }
316
317 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.
318 entry.address_ = 330 entry.address_ =
319 reinterpret_cast<uint64_t>(code_start + iterator.code_offset()); 331 reinterpret_cast<intptr_t>(code_start + iterator.code_offset() + 0x40);
320 entry.line_number_ = line_number; 332 entry.line_number_ = info.line + 1;
321 entry.column_ = column_offset; 333 entry.column_ = info.column + 1;
322 LogWriteBytes(reinterpret_cast<const char*>(&entry), sizeof(entry)); 334 LogWriteBytes(reinterpret_cast<const char*>(&entry), sizeof(entry));
323 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);
324 } 339 }
325 char padding_bytes[] = "\0\0\0\0\0\0\0\0"; 340 char padding_bytes[] = "\0\0\0\0\0\0\0\0";
326 LogWriteBytes(padding_bytes, padding); 341 LogWriteBytes(padding_bytes, padding);
327 } 342 }
328 343
329 void PerfJitLogger::LogWriteUnwindingInfo(Code* code) { 344 void PerfJitLogger::LogWriteUnwindingInfo(Code* code) {
330 PerfJitCodeUnwindingInfo unwinding_info_header; 345 PerfJitCodeUnwindingInfo unwinding_info_header;
331 unwinding_info_header.event_ = PerfJitCodeLoad::kUnwindingInfo; 346 unwinding_info_header.event_ = PerfJitCodeLoad::kUnwindingInfo;
332 unwinding_info_header.time_stamp_ = GetTimestamp(); 347 unwinding_info_header.time_stamp_ = GetTimestamp();
333 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
385 header.time_stamp_ = 400 header.time_stamp_ =
386 static_cast<uint64_t>(base::OS::TimeCurrentMillis() * 1000.0); 401 static_cast<uint64_t>(base::OS::TimeCurrentMillis() * 1000.0);
387 header.flags_ = 0; 402 header.flags_ = 0;
388 403
389 LogWriteBytes(reinterpret_cast<const char*>(&header), sizeof(header)); 404 LogWriteBytes(reinterpret_cast<const char*>(&header), sizeof(header));
390 } 405 }
391 406
392 #endif // V8_OS_LINUX 407 #endif // V8_OS_LINUX
393 } // namespace internal 408 } // namespace internal
394 } // namespace v8 409 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698