| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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/log.h" | 5 #include "src/log.h" |
| 6 | 6 |
| 7 #include <cstdarg> | 7 #include <cstdarg> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "src/v8.h" | 10 #include "src/v8.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 | 230 |
| 231 // Linux perf tool logging support | 231 // Linux perf tool logging support |
| 232 class PerfBasicLogger : public CodeEventLogger { | 232 class PerfBasicLogger : public CodeEventLogger { |
| 233 public: | 233 public: |
| 234 PerfBasicLogger(); | 234 PerfBasicLogger(); |
| 235 virtual ~PerfBasicLogger(); | 235 virtual ~PerfBasicLogger(); |
| 236 | 236 |
| 237 virtual void CodeMoveEvent(Address from, Address to) { } | 237 virtual void CodeMoveEvent(Address from, Address to) { } |
| 238 virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { } | 238 virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { } |
| 239 virtual void CodeDeleteEvent(Address from) { } | |
| 240 | 239 |
| 241 private: | 240 private: |
| 242 virtual void LogRecordedBuffer(Code* code, | 241 virtual void LogRecordedBuffer(Code* code, |
| 243 SharedFunctionInfo* shared, | 242 SharedFunctionInfo* shared, |
| 244 const char* name, | 243 const char* name, |
| 245 int length); | 244 int length); |
| 246 | 245 |
| 247 // Extension added to V8 log file name to get the low-level log name. | 246 // Extension added to V8 log file name to get the low-level log name. |
| 248 static const char kFilenameFormatString[]; | 247 static const char kFilenameFormatString[]; |
| 249 static const int kFilenameBufferPadding; | 248 static const int kFilenameBufferPadding; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 // Low-level logging support. | 296 // Low-level logging support. |
| 298 #define LL_LOG(Call) if (ll_logger_) ll_logger_->Call; | 297 #define LL_LOG(Call) if (ll_logger_) ll_logger_->Call; |
| 299 | 298 |
| 300 class LowLevelLogger : public CodeEventLogger { | 299 class LowLevelLogger : public CodeEventLogger { |
| 301 public: | 300 public: |
| 302 explicit LowLevelLogger(const char* file_name); | 301 explicit LowLevelLogger(const char* file_name); |
| 303 virtual ~LowLevelLogger(); | 302 virtual ~LowLevelLogger(); |
| 304 | 303 |
| 305 virtual void CodeMoveEvent(Address from, Address to); | 304 virtual void CodeMoveEvent(Address from, Address to); |
| 306 virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { } | 305 virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { } |
| 307 virtual void CodeDeleteEvent(Address from); | |
| 308 virtual void SnapshotPositionEvent(Address addr, int pos); | 306 virtual void SnapshotPositionEvent(Address addr, int pos); |
| 309 virtual void CodeMovingGCEvent(); | 307 virtual void CodeMovingGCEvent(); |
| 310 | 308 |
| 311 private: | 309 private: |
| 312 virtual void LogRecordedBuffer(Code* code, | 310 virtual void LogRecordedBuffer(Code* code, |
| 313 SharedFunctionInfo* shared, | 311 SharedFunctionInfo* shared, |
| 314 const char* name, | 312 const char* name, |
| 315 int length); | 313 int length); |
| 316 | 314 |
| 317 // Low-level profiling event structures. | 315 // Low-level profiling event structures. |
| 318 struct CodeCreateStruct { | 316 struct CodeCreateStruct { |
| 319 static const char kTag = 'C'; | 317 static const char kTag = 'C'; |
| 320 | 318 |
| 321 int32_t name_size; | 319 int32_t name_size; |
| 322 Address code_address; | 320 Address code_address; |
| 323 int32_t code_size; | 321 int32_t code_size; |
| 324 }; | 322 }; |
| 325 | 323 |
| 326 | 324 |
| 327 struct CodeMoveStruct { | 325 struct CodeMoveStruct { |
| 328 static const char kTag = 'M'; | 326 static const char kTag = 'M'; |
| 329 | 327 |
| 330 Address from_address; | 328 Address from_address; |
| 331 Address to_address; | 329 Address to_address; |
| 332 }; | 330 }; |
| 333 | 331 |
| 334 | 332 |
| 335 struct CodeDeleteStruct { | |
| 336 static const char kTag = 'D'; | |
| 337 | |
| 338 Address address; | |
| 339 }; | |
| 340 | |
| 341 | |
| 342 struct SnapshotPositionStruct { | 333 struct SnapshotPositionStruct { |
| 343 static const char kTag = 'P'; | 334 static const char kTag = 'P'; |
| 344 | 335 |
| 345 Address address; | 336 Address address; |
| 346 int32_t position; | 337 int32_t position; |
| 347 }; | 338 }; |
| 348 | 339 |
| 349 | 340 |
| 350 static const char kCodeMovingGCTag = 'G'; | 341 static const char kCodeMovingGCTag = 'G'; |
| 351 | 342 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 426 |
| 436 | 427 |
| 437 void LowLevelLogger::CodeMoveEvent(Address from, Address to) { | 428 void LowLevelLogger::CodeMoveEvent(Address from, Address to) { |
| 438 CodeMoveStruct event; | 429 CodeMoveStruct event; |
| 439 event.from_address = from + Code::kHeaderSize; | 430 event.from_address = from + Code::kHeaderSize; |
| 440 event.to_address = to + Code::kHeaderSize; | 431 event.to_address = to + Code::kHeaderSize; |
| 441 LogWriteStruct(event); | 432 LogWriteStruct(event); |
| 442 } | 433 } |
| 443 | 434 |
| 444 | 435 |
| 445 void LowLevelLogger::CodeDeleteEvent(Address from) { | |
| 446 CodeDeleteStruct event; | |
| 447 event.address = from + Code::kHeaderSize; | |
| 448 LogWriteStruct(event); | |
| 449 } | |
| 450 | |
| 451 | |
| 452 void LowLevelLogger::SnapshotPositionEvent(Address addr, int pos) { | 436 void LowLevelLogger::SnapshotPositionEvent(Address addr, int pos) { |
| 453 SnapshotPositionStruct event; | 437 SnapshotPositionStruct event; |
| 454 event.address = addr + Code::kHeaderSize; | 438 event.address = addr + Code::kHeaderSize; |
| 455 event.position = pos; | 439 event.position = pos; |
| 456 LogWriteStruct(event); | 440 LogWriteStruct(event); |
| 457 } | 441 } |
| 458 | 442 |
| 459 | 443 |
| 460 void LowLevelLogger::LogWriteBytes(const char* bytes, int size) { | 444 void LowLevelLogger::LogWriteBytes(const char* bytes, int size) { |
| 461 size_t rv = fwrite(bytes, 1, size, ll_output_handle_); | 445 size_t rv = fwrite(bytes, 1, size, ll_output_handle_); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 473 | 457 |
| 474 #define JIT_LOG(Call) if (jit_logger_) jit_logger_->Call; | 458 #define JIT_LOG(Call) if (jit_logger_) jit_logger_->Call; |
| 475 | 459 |
| 476 | 460 |
| 477 class JitLogger : public CodeEventLogger { | 461 class JitLogger : public CodeEventLogger { |
| 478 public: | 462 public: |
| 479 explicit JitLogger(JitCodeEventHandler code_event_handler); | 463 explicit JitLogger(JitCodeEventHandler code_event_handler); |
| 480 | 464 |
| 481 virtual void CodeMoveEvent(Address from, Address to); | 465 virtual void CodeMoveEvent(Address from, Address to); |
| 482 virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { } | 466 virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { } |
| 483 virtual void CodeDeleteEvent(Address from); | |
| 484 virtual void AddCodeLinePosInfoEvent( | 467 virtual void AddCodeLinePosInfoEvent( |
| 485 void* jit_handler_data, | 468 void* jit_handler_data, |
| 486 int pc_offset, | 469 int pc_offset, |
| 487 int position, | 470 int position, |
| 488 JitCodeEvent::PositionType position_type); | 471 JitCodeEvent::PositionType position_type); |
| 489 | 472 |
| 490 void* StartCodePosInfoEvent(); | 473 void* StartCodePosInfoEvent(); |
| 491 void EndCodePosInfoEvent(Code* code, void* jit_handler_data); | 474 void EndCodePosInfoEvent(Code* code, void* jit_handler_data); |
| 492 | 475 |
| 493 private: | 476 private: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 from_code->instruction_start() - reinterpret_cast<byte*>(from_code); | 521 from_code->instruction_start() - reinterpret_cast<byte*>(from_code); |
| 539 | 522 |
| 540 // Calculate the new start address of the instructions. | 523 // Calculate the new start address of the instructions. |
| 541 event.new_code_start = | 524 event.new_code_start = |
| 542 reinterpret_cast<byte*>(HeapObject::FromAddress(to)) + header_size; | 525 reinterpret_cast<byte*>(HeapObject::FromAddress(to)) + header_size; |
| 543 | 526 |
| 544 code_event_handler_(&event); | 527 code_event_handler_(&event); |
| 545 } | 528 } |
| 546 | 529 |
| 547 | 530 |
| 548 void JitLogger::CodeDeleteEvent(Address from) { | |
| 549 Code* from_code = Code::cast(HeapObject::FromAddress(from)); | |
| 550 | |
| 551 JitCodeEvent event; | |
| 552 event.type = JitCodeEvent::CODE_REMOVED; | |
| 553 event.code_start = from_code->instruction_start(); | |
| 554 event.code_len = from_code->instruction_size(); | |
| 555 | |
| 556 code_event_handler_(&event); | |
| 557 } | |
| 558 | |
| 559 void JitLogger::AddCodeLinePosInfoEvent( | 531 void JitLogger::AddCodeLinePosInfoEvent( |
| 560 void* jit_handler_data, | 532 void* jit_handler_data, |
| 561 int pc_offset, | 533 int pc_offset, |
| 562 int position, | 534 int position, |
| 563 JitCodeEvent::PositionType position_type) { | 535 JitCodeEvent::PositionType position_type) { |
| 564 JitCodeEvent event; | 536 JitCodeEvent event; |
| 565 memset(&event, 0, sizeof(event)); | 537 memset(&event, 0, sizeof(event)); |
| 566 event.type = JitCodeEvent::CODE_ADD_LINE_POS_INFO; | 538 event.type = JitCodeEvent::CODE_ADD_LINE_POS_INFO; |
| 567 event.user_data = jit_handler_data; | 539 event.user_data = jit_handler_data; |
| 568 event.line_info.offset = pc_offset; | 540 event.line_info.offset = pc_offset; |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 | 1308 |
| 1337 void Logger::CodeMoveEvent(Address from, Address to) { | 1309 void Logger::CodeMoveEvent(Address from, Address to) { |
| 1338 PROFILER_LOG(CodeMoveEvent(from, to)); | 1310 PROFILER_LOG(CodeMoveEvent(from, to)); |
| 1339 | 1311 |
| 1340 if (!is_logging_code_events()) return; | 1312 if (!is_logging_code_events()) return; |
| 1341 CALL_LISTENERS(CodeMoveEvent(from, to)); | 1313 CALL_LISTENERS(CodeMoveEvent(from, to)); |
| 1342 MoveEventInternal(CODE_MOVE_EVENT, from, to); | 1314 MoveEventInternal(CODE_MOVE_EVENT, from, to); |
| 1343 } | 1315 } |
| 1344 | 1316 |
| 1345 | 1317 |
| 1346 void Logger::CodeDeleteEvent(Address from) { | |
| 1347 PROFILER_LOG(CodeDeleteEvent(from)); | |
| 1348 | |
| 1349 if (!is_logging_code_events()) return; | |
| 1350 CALL_LISTENERS(CodeDeleteEvent(from)); | |
| 1351 | |
| 1352 if (!FLAG_log_code || !log_->IsEnabled()) return; | |
| 1353 Log::MessageBuilder msg(log_); | |
| 1354 msg.Append("%s,", kLogEventsNames[CODE_DELETE_EVENT]); | |
| 1355 msg.AppendAddress(from); | |
| 1356 msg.WriteToLogFile(); | |
| 1357 } | |
| 1358 | |
| 1359 | |
| 1360 void Logger::CodeLinePosInfoAddPositionEvent(void* jit_handler_data, | 1318 void Logger::CodeLinePosInfoAddPositionEvent(void* jit_handler_data, |
| 1361 int pc_offset, | 1319 int pc_offset, |
| 1362 int position) { | 1320 int position) { |
| 1363 JIT_LOG(AddCodeLinePosInfoEvent(jit_handler_data, | 1321 JIT_LOG(AddCodeLinePosInfoEvent(jit_handler_data, |
| 1364 pc_offset, | 1322 pc_offset, |
| 1365 position, | 1323 position, |
| 1366 JitCodeEvent::POSITION)); | 1324 JitCodeEvent::POSITION)); |
| 1367 } | 1325 } |
| 1368 | 1326 |
| 1369 | 1327 |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1932 if (jit_logger_) { | 1890 if (jit_logger_) { |
| 1933 removeCodeEventListener(jit_logger_); | 1891 removeCodeEventListener(jit_logger_); |
| 1934 delete jit_logger_; | 1892 delete jit_logger_; |
| 1935 jit_logger_ = NULL; | 1893 jit_logger_ = NULL; |
| 1936 } | 1894 } |
| 1937 | 1895 |
| 1938 return log_->Close(); | 1896 return log_->Close(); |
| 1939 } | 1897 } |
| 1940 | 1898 |
| 1941 } } // namespace v8::internal | 1899 } } // namespace v8::internal |
| OLD | NEW |