| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 explicit LogMessageBuilder(); | 292 explicit LogMessageBuilder(); |
| 293 ~LogMessageBuilder() { } | 293 ~LogMessageBuilder() { } |
| 294 | 294 |
| 295 void Append(const char* format, ...); | 295 void Append(const char* format, ...); |
| 296 void Append(const char* format, va_list args); | 296 void Append(const char* format, va_list args); |
| 297 void Append(const char c); | 297 void Append(const char c); |
| 298 void Append(String *str); | 298 void Append(String *str); |
| 299 void AppendDetailed(String* str, bool show_impl_info); | 299 void AppendDetailed(String* str, bool show_impl_info); |
| 300 | 300 |
| 301 void WriteToLogFile(); | 301 void WriteToLogFile(); |
| 302 void WriteCStringToLogFile(const char* str); |
| 302 | 303 |
| 303 private: | 304 private: |
| 304 ScopedLock sl; | 305 ScopedLock sl; |
| 305 int pos_; | 306 int pos_; |
| 306 }; | 307 }; |
| 307 | 308 |
| 308 | 309 |
| 309 // Create a message builder starting from position 0. This acquires the mutex | 310 // Create a message builder starting from position 0. This acquires the mutex |
| 310 // in the logger as well. | 311 // in the logger as well. |
| 311 LogMessageBuilder::LogMessageBuilder(): sl(Logger::mutex_), pos_(0) { | 312 LogMessageBuilder::LogMessageBuilder(): sl(Logger::mutex_), pos_(0) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 389 } |
| 389 } | 390 } |
| 390 | 391 |
| 391 // Write the log message to the log file currently opened. | 392 // Write the log message to the log file currently opened. |
| 392 void LogMessageBuilder::WriteToLogFile() { | 393 void LogMessageBuilder::WriteToLogFile() { |
| 393 ASSERT(pos_ <= Logger::kMessageBufferSize); | 394 ASSERT(pos_ <= Logger::kMessageBufferSize); |
| 394 size_t rv = fwrite(Logger::message_buffer_, 1, pos_, Logger::logfile_); | 395 size_t rv = fwrite(Logger::message_buffer_, 1, pos_, Logger::logfile_); |
| 395 ASSERT(rv == static_cast<size_t>(pos_)); | 396 ASSERT(rv == static_cast<size_t>(pos_)); |
| 396 USE(rv); | 397 USE(rv); |
| 397 } | 398 } |
| 399 |
| 400 // Write a null-terminated string to to the log file currently opened. |
| 401 void LogMessageBuilder::WriteCStringToLogFile(const char* str) { |
| 402 size_t len = strlen(str); |
| 403 size_t rv = fwrite(str, 1, len, Logger::logfile_); |
| 404 ASSERT(rv == len); |
| 405 USE(rv); |
| 406 } |
| 398 #endif | 407 #endif |
| 399 | 408 |
| 400 | 409 |
| 401 // | 410 // |
| 402 // Logger class implementation. | 411 // Logger class implementation. |
| 403 // | 412 // |
| 404 Ticker* Logger::ticker_ = NULL; | 413 Ticker* Logger::ticker_ = NULL; |
| 405 char* Logger::message_buffer_ = NULL; | 414 char* Logger::message_buffer_ = NULL; |
| 406 FILE* Logger::logfile_ = NULL; | 415 FILE* Logger::logfile_ = NULL; |
| 407 Profiler* Logger::profiler_ = NULL; | 416 Profiler* Logger::profiler_ = NULL; |
| 408 Mutex* Logger::mutex_ = NULL; | 417 Mutex* Logger::mutex_ = NULL; |
| 409 VMState* Logger::current_state_ = NULL; | 418 VMState* Logger::current_state_ = NULL; |
| 410 VMState Logger::bottom_state_(EXTERNAL); | 419 VMState Logger::bottom_state_(EXTERNAL); |
| 411 SlidingStateWindow* Logger::sliding_state_window_ = NULL; | 420 SlidingStateWindow* Logger::sliding_state_window_ = NULL; |
| 412 | 421 |
| 413 #endif // ENABLE_LOGGING_AND_PROFILING | 422 #endif // ENABLE_LOGGING_AND_PROFILING |
| 414 | 423 |
| 415 | 424 |
| 416 void Logger::Preamble(const char* content) { | 425 void Logger::Preamble(const char* content) { |
| 417 #ifdef ENABLE_LOGGING_AND_PROFILING | 426 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 418 if (logfile_ == NULL || !FLAG_log_code) return; | 427 if (logfile_ == NULL || !FLAG_log_code) return; |
| 419 LogMessageBuilder msg; | 428 LogMessageBuilder msg; |
| 420 msg.Append("%s", content); | 429 msg.WriteCStringToLogFile(content); |
| 421 msg.WriteToLogFile(); | |
| 422 #endif | 430 #endif |
| 423 } | 431 } |
| 424 | 432 |
| 425 | 433 |
| 426 void Logger::StringEvent(const char* name, const char* value) { | 434 void Logger::StringEvent(const char* name, const char* value) { |
| 427 #ifdef ENABLE_LOGGING_AND_PROFILING | 435 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 428 if (FLAG_log) UncheckedStringEvent(name, value); | 436 if (FLAG_log) UncheckedStringEvent(name, value); |
| 429 #endif | 437 #endif |
| 430 } | 438 } |
| 431 | 439 |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 LogMessageBuilder msg; | 759 LogMessageBuilder msg; |
| 752 msg.Append("code-creation,%s,0x%x,%d,\"args_count: %d\"\n", tag, | 760 msg.Append("code-creation,%s,0x%x,%d,\"args_count: %d\"\n", tag, |
| 753 reinterpret_cast<unsigned int>(code->address()), | 761 reinterpret_cast<unsigned int>(code->address()), |
| 754 code->ExecutableSize(), | 762 code->ExecutableSize(), |
| 755 args_count); | 763 args_count); |
| 756 msg.WriteToLogFile(); | 764 msg.WriteToLogFile(); |
| 757 #endif | 765 #endif |
| 758 } | 766 } |
| 759 | 767 |
| 760 | 768 |
| 769 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { |
| 770 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 771 if (logfile_ == NULL || !FLAG_log_code) return; |
| 772 LogMessageBuilder msg; |
| 773 msg.Append("code-creation,%s,0x%x,%d,\"", "RegExp", |
| 774 reinterpret_cast<unsigned int>(code->address()), |
| 775 code->ExecutableSize()); |
| 776 msg.AppendDetailed(source, false); |
| 777 msg.Append("\"\n"); |
| 778 msg.WriteToLogFile(); |
| 779 #endif |
| 780 } |
| 781 |
| 782 |
| 761 void Logger::CodeAllocateEvent(Code* code, Assembler* assem) { | 783 void Logger::CodeAllocateEvent(Code* code, Assembler* assem) { |
| 762 #ifdef ENABLE_LOGGING_AND_PROFILING | 784 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 763 if (logfile_ == NULL || !FLAG_log_code) return; | 785 if (logfile_ == NULL || !FLAG_log_code) return; |
| 764 LogMessageBuilder msg; | 786 LogMessageBuilder msg; |
| 765 msg.Append("code-allocate,0x%x,0x%x\n", | 787 msg.Append("code-allocate,0x%x,0x%x\n", |
| 766 reinterpret_cast<unsigned int>(code->address()), | 788 reinterpret_cast<unsigned int>(code->address()), |
| 767 reinterpret_cast<unsigned int>(assem)); | 789 reinterpret_cast<unsigned int>(assem)); |
| 768 msg.WriteToLogFile(); | 790 msg.WriteToLogFile(); |
| 769 #endif | 791 #endif |
| 770 } | 792 } |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 // All other %'s expand to themselves. | 1025 // All other %'s expand to themselves. |
| 1004 stream.Put('%'); | 1026 stream.Put('%'); |
| 1005 stream.Put(*p); | 1027 stream.Put(*p); |
| 1006 break; | 1028 break; |
| 1007 } | 1029 } |
| 1008 } else { | 1030 } else { |
| 1009 stream.Put(*p); | 1031 stream.Put(*p); |
| 1010 } | 1032 } |
| 1011 } | 1033 } |
| 1012 SmartPointer<const char> expanded = stream.ToCString(); | 1034 SmartPointer<const char> expanded = stream.ToCString(); |
| 1013 logfile_ = OS::FOpen(*expanded, "w"); | 1035 logfile_ = OS::FOpen(*expanded, OS::LogFileOpenMode); |
| 1014 } else { | 1036 } else { |
| 1015 logfile_ = OS::FOpen(FLAG_logfile, "w"); | 1037 logfile_ = OS::FOpen(FLAG_logfile, OS::LogFileOpenMode); |
| 1016 } | 1038 } |
| 1017 message_buffer_ = NewArray<char>(kMessageBufferSize); | 1039 message_buffer_ = NewArray<char>(kMessageBufferSize); |
| 1018 mutex_ = OS::CreateMutex(); | 1040 mutex_ = OS::CreateMutex(); |
| 1019 } | 1041 } |
| 1020 | 1042 |
| 1021 current_state_ = &bottom_state_; | 1043 current_state_ = &bottom_state_; |
| 1022 | 1044 |
| 1023 // as log is initialized early with V8, we can assume that JS execution | 1045 // as log is initialized early with V8, we can assume that JS execution |
| 1024 // frames can never reach this point on stack | 1046 // frames can never reach this point on stack |
| 1025 int stack_var; | 1047 int stack_var; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 } else if (previous_->state_ == EXTERNAL) { | 1184 } else if (previous_->state_ == EXTERNAL) { |
| 1163 // We are leaving V8. | 1185 // We are leaving V8. |
| 1164 Heap::Protect(); | 1186 Heap::Protect(); |
| 1165 } | 1187 } |
| 1166 } | 1188 } |
| 1167 #endif | 1189 #endif |
| 1168 } | 1190 } |
| 1169 #endif | 1191 #endif |
| 1170 | 1192 |
| 1171 } } // namespace v8::internal | 1193 } } // namespace v8::internal |
| OLD | NEW |