| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 write_pos_ += data_size; | 117 write_pos_ += data_size; |
| 118 return data_size; | 118 return data_size; |
| 119 } | 119 } |
| 120 | 120 |
| 121 | 121 |
| 122 bool Log::is_stopped_ = false; | 122 bool Log::is_stopped_ = false; |
| 123 Log::WritePtr Log::Write = NULL; | 123 Log::WritePtr Log::Write = NULL; |
| 124 FILE* Log::output_handle_ = NULL; | 124 FILE* Log::output_handle_ = NULL; |
| 125 FILE* Log::output_code_handle_ = NULL; |
| 125 LogDynamicBuffer* Log::output_buffer_ = NULL; | 126 LogDynamicBuffer* Log::output_buffer_ = NULL; |
| 126 // Must be the same message as in Logger::PauseProfiler. | 127 // Must be the same message as in Logger::PauseProfiler. |
| 127 const char* Log::kDynamicBufferSeal = "profiler,\"pause\"\n"; | 128 const char* Log::kDynamicBufferSeal = "profiler,\"pause\"\n"; |
| 128 Mutex* Log::mutex_ = NULL; | 129 Mutex* Log::mutex_ = NULL; |
| 129 char* Log::message_buffer_ = NULL; | 130 char* Log::message_buffer_ = NULL; |
| 130 | 131 |
| 131 | 132 |
| 132 void Log::Init() { | 133 void Log::Init() { |
| 133 mutex_ = OS::CreateMutex(); | 134 mutex_ = OS::CreateMutex(); |
| 134 message_buffer_ = NewArray<char>(kMessageBufferSize); | 135 message_buffer_ = NewArray<char>(kMessageBufferSize); |
| 135 } | 136 } |
| 136 | 137 |
| 137 | 138 |
| 138 void Log::OpenStdout() { | 139 void Log::OpenStdout() { |
| 139 ASSERT(!IsEnabled()); | 140 ASSERT(!IsEnabled()); |
| 140 output_handle_ = stdout; | 141 output_handle_ = stdout; |
| 141 Write = WriteToFile; | 142 Write = WriteToFile; |
| 142 Init(); | 143 Init(); |
| 143 } | 144 } |
| 144 | 145 |
| 145 | 146 |
| 147 static const char kCodeLogExt[] = ".code"; |
| 148 |
| 149 |
| 146 void Log::OpenFile(const char* name) { | 150 void Log::OpenFile(const char* name) { |
| 147 ASSERT(!IsEnabled()); | 151 ASSERT(!IsEnabled()); |
| 148 output_handle_ = OS::FOpen(name, OS::LogFileOpenMode); | 152 output_handle_ = OS::FOpen(name, OS::LogFileOpenMode); |
| 153 if (FLAG_ll_prof) { |
| 154 // Open a file for logging the contents of code objects so that |
| 155 // they can be disassembled later. |
| 156 size_t name_len = strlen(name); |
| 157 ScopedVector<char> code_name(name_len + sizeof(kCodeLogExt)); |
| 158 memcpy(code_name.start(), name, name_len); |
| 159 memcpy(code_name.start() + name_len, kCodeLogExt, sizeof(kCodeLogExt)); |
| 160 output_code_handle_ = OS::FOpen(code_name.start(), OS::LogFileOpenMode); |
| 161 } |
| 149 Write = WriteToFile; | 162 Write = WriteToFile; |
| 150 Init(); | 163 Init(); |
| 151 } | 164 } |
| 152 | 165 |
| 153 | 166 |
| 154 void Log::OpenMemoryBuffer() { | 167 void Log::OpenMemoryBuffer() { |
| 155 ASSERT(!IsEnabled()); | 168 ASSERT(!IsEnabled()); |
| 156 output_buffer_ = new LogDynamicBuffer( | 169 output_buffer_ = new LogDynamicBuffer( |
| 157 kDynamicBufferBlockSize, kMaxDynamicBufferSize, | 170 kDynamicBufferBlockSize, kMaxDynamicBufferSize, |
| 158 kDynamicBufferSeal, StrLength(kDynamicBufferSeal)); | 171 kDynamicBufferSeal, StrLength(kDynamicBufferSeal)); |
| 159 Write = WriteToMemory; | 172 Write = WriteToMemory; |
| 160 Init(); | 173 Init(); |
| 161 } | 174 } |
| 162 | 175 |
| 163 | 176 |
| 164 void Log::Close() { | 177 void Log::Close() { |
| 165 if (Write == WriteToFile) { | 178 if (Write == WriteToFile) { |
| 166 if (output_handle_ != NULL) fclose(output_handle_); | 179 if (output_handle_ != NULL) fclose(output_handle_); |
| 167 output_handle_ = NULL; | 180 output_handle_ = NULL; |
| 181 if (output_code_handle_ != NULL) fclose(output_code_handle_); |
| 182 output_code_handle_ = NULL; |
| 168 } else if (Write == WriteToMemory) { | 183 } else if (Write == WriteToMemory) { |
| 169 delete output_buffer_; | 184 delete output_buffer_; |
| 170 output_buffer_ = NULL; | 185 output_buffer_ = NULL; |
| 171 } else { | 186 } else { |
| 172 ASSERT(Write == NULL); | 187 ASSERT(Write == NULL); |
| 173 } | 188 } |
| 174 Write = NULL; | 189 Write = NULL; |
| 175 | 190 |
| 176 DeleteArray(message_buffer_); | 191 DeleteArray(message_buffer_); |
| 177 message_buffer_ = NULL; | 192 message_buffer_ = NULL; |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 PrintBackwardReference(backref, best.distance, best.copy_from_pos); | 503 PrintBackwardReference(backref, best.distance, best.copy_from_pos); |
| 489 ASSERT(strlen(backref.start()) - best.backref_size == 0); | 504 ASSERT(strlen(backref.start()) - best.backref_size == 0); |
| 490 prev_record->Truncate(static_cast<int>(unchanged_len + best.backref_size)); | 505 prev_record->Truncate(static_cast<int>(unchanged_len + best.backref_size)); |
| 491 } | 506 } |
| 492 return true; | 507 return true; |
| 493 } | 508 } |
| 494 | 509 |
| 495 #endif // ENABLE_LOGGING_AND_PROFILING | 510 #endif // ENABLE_LOGGING_AND_PROFILING |
| 496 | 511 |
| 497 } } // namespace v8::internal | 512 } } // namespace v8::internal |
| OLD | NEW |