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

Side by Side Diff: src/log-utils.cc

Issue 6904127: ll_prof: Reduce profiling hooks overhead from >400% to 25%. (Closed)
Patch Set: Review fixes Created 9 years, 7 months 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/log-utils.h ('k') | src/utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return data_size; 119 return data_size;
120 } 120 }
121 121
122 // Must be the same message as in Logger::PauseProfiler. 122 // Must be the same message as in Logger::PauseProfiler.
123 const char* const Log::kDynamicBufferSeal = "profiler,\"pause\"\n"; 123 const char* const Log::kDynamicBufferSeal = "profiler,\"pause\"\n";
124 124
125 Log::Log(Logger* logger) 125 Log::Log(Logger* logger)
126 : write_to_file_(false), 126 : write_to_file_(false),
127 is_stopped_(false), 127 is_stopped_(false),
128 output_handle_(NULL), 128 output_handle_(NULL),
129 output_code_handle_(NULL), 129 ll_output_handle_(NULL),
130 output_buffer_(NULL), 130 output_buffer_(NULL),
131 mutex_(NULL), 131 mutex_(NULL),
132 message_buffer_(NULL), 132 message_buffer_(NULL),
133 logger_(logger) { 133 logger_(logger) {
134 } 134 }
135 135
136 136
137 static void AddIsolateIdIfNeeded(StringStream* stream) { 137 static void AddIsolateIdIfNeeded(StringStream* stream) {
138 Isolate* isolate = Isolate::Current(); 138 Isolate* isolate = Isolate::Current();
139 if (isolate->IsDefaultIsolate()) return; 139 if (isolate->IsDefaultIsolate()) return;
(...skipping 21 matching lines...) Expand all
161 if (FLAG_prof) FLAG_log_code = true; 161 if (FLAG_prof) FLAG_log_code = true;
162 162
163 // --prof_lazy controls --log-code, implies --noprof_auto. 163 // --prof_lazy controls --log-code, implies --noprof_auto.
164 if (FLAG_prof_lazy) { 164 if (FLAG_prof_lazy) {
165 FLAG_log_code = false; 165 FLAG_log_code = false;
166 FLAG_prof_auto = false; 166 FLAG_prof_auto = false;
167 } 167 }
168 168
169 bool start_logging = FLAG_log || FLAG_log_runtime || FLAG_log_api 169 bool start_logging = FLAG_log || FLAG_log_runtime || FLAG_log_api
170 || FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect 170 || FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect
171 || FLAG_log_regexp || FLAG_log_state_changes; 171 || FLAG_log_regexp || FLAG_log_state_changes || FLAG_ll_prof;
172 172
173 bool open_log_file = start_logging || FLAG_prof_lazy; 173 bool open_log_file = start_logging || FLAG_prof_lazy;
174 174
175 // If we're logging anything, we need to open the log file. 175 // If we're logging anything, we need to open the log file.
176 if (open_log_file) { 176 if (open_log_file) {
177 if (strcmp(FLAG_logfile, "-") == 0) { 177 if (strcmp(FLAG_logfile, "-") == 0) {
178 OpenStdout(); 178 OpenStdout();
179 } else if (strcmp(FLAG_logfile, "*") == 0) { 179 } else if (strcmp(FLAG_logfile, "*") == 0) {
180 OpenMemoryBuffer(); 180 OpenMemoryBuffer();
181 } else { 181 } else {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 226 }
227 227
228 228
229 void Log::OpenStdout() { 229 void Log::OpenStdout() {
230 ASSERT(!IsEnabled()); 230 ASSERT(!IsEnabled());
231 output_handle_ = stdout; 231 output_handle_ = stdout;
232 write_to_file_ = true; 232 write_to_file_ = true;
233 } 233 }
234 234
235 235
236 static const char kCodeLogExt[] = ".code"; 236 // Extension added to V8 log file name to get the low-level log name.
237 static const char kLowLevelLogExt[] = ".ll";
238
239 // File buffer size of the low-level log. We don't use the default to
240 // minimize the associated overhead.
241 static const int kLowLevelLogBufferSize = 2 * MB;
237 242
238 243
239 void Log::OpenFile(const char* name) { 244 void Log::OpenFile(const char* name) {
240 ASSERT(!IsEnabled()); 245 ASSERT(!IsEnabled());
241 output_handle_ = OS::FOpen(name, OS::LogFileOpenMode); 246 output_handle_ = OS::FOpen(name, OS::LogFileOpenMode);
242 write_to_file_ = true; 247 write_to_file_ = true;
243 if (FLAG_ll_prof) { 248 if (FLAG_ll_prof) {
244 // Open a file for logging the contents of code objects so that 249 // Open the low-level log file.
245 // they can be disassembled later. 250 size_t len = strlen(name);
246 size_t name_len = strlen(name); 251 ScopedVector<char> ll_name(static_cast<int>(len + sizeof(kLowLevelLogExt)));
247 ScopedVector<char> code_name( 252 memcpy(ll_name.start(), name, len);
248 static_cast<int>(name_len + sizeof(kCodeLogExt))); 253 memcpy(ll_name.start() + len, kLowLevelLogExt, sizeof(kLowLevelLogExt));
249 memcpy(code_name.start(), name, name_len); 254 ll_output_handle_ = OS::FOpen(ll_name.start(), OS::LogFileOpenMode);
250 memcpy(code_name.start() + name_len, kCodeLogExt, sizeof(kCodeLogExt)); 255 setvbuf(ll_output_handle_, NULL, _IOFBF, kLowLevelLogBufferSize);
251 output_code_handle_ = OS::FOpen(code_name.start(), OS::LogFileOpenMode);
252 } 256 }
253 } 257 }
254 258
255 259
256 void Log::OpenMemoryBuffer() { 260 void Log::OpenMemoryBuffer() {
257 ASSERT(!IsEnabled()); 261 ASSERT(!IsEnabled());
258 output_buffer_ = new LogDynamicBuffer( 262 output_buffer_ = new LogDynamicBuffer(
259 kDynamicBufferBlockSize, kMaxDynamicBufferSize, 263 kDynamicBufferBlockSize, kMaxDynamicBufferSize,
260 kDynamicBufferSeal, StrLength(kDynamicBufferSeal)); 264 kDynamicBufferSeal, StrLength(kDynamicBufferSeal));
261 write_to_file_ = false; 265 write_to_file_ = false;
262 } 266 }
263 267
264 268
265 void Log::Close() { 269 void Log::Close() {
266 if (write_to_file_) { 270 if (write_to_file_) {
267 if (output_handle_ != NULL) fclose(output_handle_); 271 if (output_handle_ != NULL) fclose(output_handle_);
268 output_handle_ = NULL; 272 output_handle_ = NULL;
269 if (output_code_handle_ != NULL) fclose(output_code_handle_); 273 if (ll_output_handle_ != NULL) fclose(ll_output_handle_);
270 output_code_handle_ = NULL; 274 ll_output_handle_ = NULL;
271 } else { 275 } else {
272 delete output_buffer_; 276 delete output_buffer_;
273 output_buffer_ = NULL; 277 output_buffer_ = NULL;
274 } 278 }
275 279
276 DeleteArray(message_buffer_); 280 DeleteArray(message_buffer_);
277 message_buffer_ = NULL; 281 message_buffer_ = NULL;
278 282
279 delete mutex_; 283 delete mutex_;
280 mutex_ = NULL; 284 mutex_ = NULL;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 } 358 }
355 } 359 }
356 360
357 361
358 void LogMessageBuilder::AppendAddress(Address addr) { 362 void LogMessageBuilder::AppendAddress(Address addr) {
359 Append("0x%" V8PRIxPTR, addr); 363 Append("0x%" V8PRIxPTR, addr);
360 } 364 }
361 365
362 366
363 void LogMessageBuilder::AppendDetailed(String* str, bool show_impl_info) { 367 void LogMessageBuilder::AppendDetailed(String* str, bool show_impl_info) {
368 if (str == NULL) return;
364 AssertNoAllocation no_heap_allocation; // Ensure string stay valid. 369 AssertNoAllocation no_heap_allocation; // Ensure string stay valid.
365 int len = str->length(); 370 int len = str->length();
366 if (len > 0x1000) 371 if (len > 0x1000)
367 len = 0x1000; 372 len = 0x1000;
368 if (show_impl_info) { 373 if (show_impl_info) {
369 Append(str->IsAsciiRepresentation() ? 'a' : '2'); 374 Append(str->IsAsciiRepresentation() ? 'a' : '2');
370 if (StringShape(str).IsExternal()) 375 if (StringShape(str).IsExternal())
371 Append('e'); 376 Append('e');
372 if (StringShape(str).IsSymbol()) 377 if (StringShape(str).IsSymbol())
373 Append('#'); 378 Append('#');
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 if (written != pos_) { 419 if (written != pos_) {
415 log_->stop(); 420 log_->stop();
416 log_->logger_->LogFailure(); 421 log_->logger_->LogFailure();
417 } 422 }
418 } 423 }
419 424
420 425
421 #endif // ENABLE_LOGGING_AND_PROFILING 426 #endif // ENABLE_LOGGING_AND_PROFILING
422 427
423 } } // namespace v8::internal 428 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/log-utils.h ('k') | src/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698