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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #include "v8.h" | 30 #include "v8.h" |
31 | 31 |
32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" |
33 #include "log.h" | 33 #include "log.h" |
34 #include "macro-assembler.h" | 34 #include "macro-assembler.h" |
35 #include "platform.h" | 35 #include "platform.h" |
36 #include "serialize.h" | 36 #include "serialize.h" |
37 #include "string-stream.h" | 37 #include "string-stream.h" |
38 | 38 |
39 namespace v8 { namespace internal { | 39 namespace v8 { |
| 40 namespace internal { |
40 | 41 |
41 #ifdef ENABLE_LOGGING_AND_PROFILING | 42 #ifdef ENABLE_LOGGING_AND_PROFILING |
42 | 43 |
43 // | 44 // |
44 // Sliding state window. Updates counters to keep track of the last | 45 // Sliding state window. Updates counters to keep track of the last |
45 // window of kBufferSize states. This is useful to track where we | 46 // window of kBufferSize states. This is useful to track where we |
46 // spent our time. | 47 // spent our time. |
47 // | 48 // |
48 class SlidingStateWindow { | 49 class SlidingStateWindow { |
49 public: | 50 public: |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 TickSample sample; | 279 TickSample sample; |
279 bool overflow = Logger::profiler_->Remove(&sample); | 280 bool overflow = Logger::profiler_->Remove(&sample); |
280 while (running_) { | 281 while (running_) { |
281 LOG(TickEvent(&sample, overflow)); | 282 LOG(TickEvent(&sample, overflow)); |
282 overflow = Logger::profiler_->Remove(&sample); | 283 overflow = Logger::profiler_->Remove(&sample); |
283 } | 284 } |
284 } | 285 } |
285 | 286 |
286 | 287 |
287 #ifdef ENABLE_LOGGING_AND_PROFILING | 288 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 289 |
| 290 // Functions and data for performing output of log messages. |
| 291 class Log : public AllStatic { |
| 292 public: |
| 293 // Opens stdout for logging. |
| 294 static void OpenStdout(); |
| 295 |
| 296 // Opens file for logging. |
| 297 static void OpenFile(const char* name); |
| 298 |
| 299 // Opens memory buffer for logging. |
| 300 static void OpenMemoryBuffer(); |
| 301 |
| 302 // Frees all resources acquired in Open... functions. |
| 303 static void Close(); |
| 304 |
| 305 // See description in include/v8.h. |
| 306 static int GetLogLines(int from_pos, char* dest_buf, int max_size); |
| 307 |
| 308 // Returns whether logging is enabled. |
| 309 static bool is_enabled() { |
| 310 return output_handle_ != NULL || output_buffer_ != NULL; |
| 311 } |
| 312 |
| 313 private: |
| 314 typedef int (*WritePtr)(const char* msg, int length); |
| 315 |
| 316 // Initialization function called from Open... functions. |
| 317 static void Init(); |
| 318 |
| 319 // Write functions assume that mutex_ is acquired by the caller. |
| 320 static WritePtr Write; |
| 321 |
| 322 // Implementation of writing to a log file. |
| 323 static int WriteToFile(const char* msg, int length) { |
| 324 ASSERT(output_handle_ != NULL); |
| 325 int rv = fwrite(msg, 1, length, output_handle_); |
| 326 ASSERT(length == rv); |
| 327 return rv; |
| 328 } |
| 329 |
| 330 // Implementation of writing to a memory buffer. |
| 331 static int WriteToMemory(const char* msg, int length) { |
| 332 ASSERT(output_buffer_ != NULL); |
| 333 ASSERT(output_buffer_write_pos_ >= output_buffer_); |
| 334 if (output_buffer_write_pos_ + length |
| 335 <= output_buffer_ + kOutputBufferSize) { |
| 336 memcpy(output_buffer_write_pos_, msg, length); |
| 337 output_buffer_write_pos_ += length; |
| 338 return length; |
| 339 } else { |
| 340 // Memory buffer is full, ignore write. |
| 341 return 0; |
| 342 } |
| 343 } |
| 344 |
| 345 // When logging is active, either output_handle_ or output_buffer_ is used |
| 346 // to store a pointer to log destination. If logging was opened via OpenStdout |
| 347 // or OpenFile, then output_handle_ is used. If logging was opened |
| 348 // via OpenMemoryBuffer, then output_buffer_ is used. |
| 349 // mutex_ should be acquired before using output_handle_ or output_buffer_. |
| 350 static FILE* output_handle_; |
| 351 |
| 352 static char* output_buffer_; |
| 353 |
| 354 // mutex_ is a Mutex used for enforcing exclusive |
| 355 // access to the formatting buffer and the log file or log memory buffer. |
| 356 static Mutex* mutex_; |
| 357 |
| 358 // Size of buffer used for memory logging. |
| 359 static const int kOutputBufferSize = 2 * 1024 * 1024; |
| 360 |
| 361 // Writing position in a memory buffer. |
| 362 static char* output_buffer_write_pos_; |
| 363 |
| 364 // Size of buffer used for formatting log messages. |
| 365 static const int kMessageBufferSize = 2048; |
| 366 |
| 367 // Buffer used for formatting log messages. This is a singleton buffer and |
| 368 // mutex_ should be acquired before using it. |
| 369 static char* message_buffer_; |
| 370 |
| 371 friend class LogMessageBuilder; |
| 372 }; |
| 373 |
| 374 |
| 375 Log::WritePtr Log::Write = NULL; |
| 376 FILE* Log::output_handle_ = NULL; |
| 377 char* Log::output_buffer_ = NULL; |
| 378 Mutex* Log::mutex_ = NULL; |
| 379 char* Log::output_buffer_write_pos_ = NULL; |
| 380 char* Log::message_buffer_ = NULL; |
| 381 |
| 382 |
| 383 void Log::Init() { |
| 384 mutex_ = OS::CreateMutex(); |
| 385 message_buffer_ = NewArray<char>(kMessageBufferSize); |
| 386 } |
| 387 |
| 388 |
| 389 void Log::OpenStdout() { |
| 390 ASSERT(!is_enabled()); |
| 391 output_handle_ = stdout; |
| 392 Write = WriteToFile; |
| 393 Init(); |
| 394 } |
| 395 |
| 396 |
| 397 void Log::OpenFile(const char* name) { |
| 398 ASSERT(!is_enabled()); |
| 399 output_handle_ = OS::FOpen(name, OS::LogFileOpenMode); |
| 400 Write = WriteToFile; |
| 401 Init(); |
| 402 } |
| 403 |
| 404 |
| 405 void Log::OpenMemoryBuffer() { |
| 406 ASSERT(!is_enabled()); |
| 407 output_buffer_ = NewArray<char>(kOutputBufferSize); |
| 408 output_buffer_write_pos_ = output_buffer_; |
| 409 Write = WriteToMemory; |
| 410 Init(); |
| 411 } |
| 412 |
| 413 |
| 414 void Log::Close() { |
| 415 if (Write == WriteToFile) { |
| 416 fclose(output_handle_); |
| 417 output_handle_ = NULL; |
| 418 } else if (Write == WriteToMemory) { |
| 419 DeleteArray(output_buffer_); |
| 420 output_buffer_ = NULL; |
| 421 } else { |
| 422 ASSERT(Write == NULL); |
| 423 } |
| 424 Write = NULL; |
| 425 |
| 426 delete mutex_; |
| 427 mutex_ = NULL; |
| 428 |
| 429 DeleteArray(message_buffer_); |
| 430 message_buffer_ = NULL; |
| 431 } |
| 432 |
| 433 |
| 434 int Log::GetLogLines(int from_pos, char* dest_buf, int max_size) { |
| 435 ASSERT(output_buffer_ != NULL); |
| 436 ASSERT(output_buffer_write_pos_ >= output_buffer_); |
| 437 ASSERT(from_pos >= 0); |
| 438 ASSERT(max_size >= 0); |
| 439 int actual_size = max_size; |
| 440 char* buffer_read_pos = output_buffer_ + from_pos; |
| 441 ScopedLock sl(mutex_); |
| 442 if (actual_size == 0 |
| 443 || output_buffer_write_pos_ == output_buffer_ |
| 444 || buffer_read_pos >= output_buffer_write_pos_) { |
| 445 // No data requested or can be returned. |
| 446 return 0; |
| 447 } |
| 448 if (buffer_read_pos + actual_size > output_buffer_write_pos_) { |
| 449 // Requested size overlaps with current writing position and |
| 450 // needs to be truncated. |
| 451 actual_size = output_buffer_write_pos_ - buffer_read_pos; |
| 452 ASSERT(actual_size == 0 || buffer_read_pos[actual_size - 1] == '\n'); |
| 453 } else { |
| 454 // Find previous log line boundary. |
| 455 char* end_pos = buffer_read_pos + actual_size - 1; |
| 456 while (end_pos >= buffer_read_pos && *end_pos != '\n') --end_pos; |
| 457 actual_size = end_pos - buffer_read_pos + 1; |
| 458 } |
| 459 ASSERT(actual_size <= max_size); |
| 460 if (actual_size > 0) { |
| 461 memcpy(dest_buf, buffer_read_pos, actual_size); |
| 462 } |
| 463 return actual_size; |
| 464 } |
| 465 |
| 466 |
288 // Utility class for formatting log messages. It fills the message into the | 467 // Utility class for formatting log messages. It fills the message into the |
289 // static buffer in Logger. | 468 // static buffer in Log. |
290 class LogMessageBuilder BASE_EMBEDDED { | 469 class LogMessageBuilder BASE_EMBEDDED { |
291 public: | 470 public: |
292 explicit LogMessageBuilder(); | 471 explicit LogMessageBuilder(); |
293 ~LogMessageBuilder() { } | 472 ~LogMessageBuilder() { } |
294 | 473 |
295 void Append(const char* format, ...); | 474 void Append(const char* format, ...); |
296 void Append(const char* format, va_list args); | 475 void Append(const char* format, va_list args); |
297 void Append(const char c); | 476 void Append(const char c); |
298 void Append(String *str); | 477 void Append(String *str); |
299 void AppendDetailed(String* str, bool show_impl_info); | 478 void AppendDetailed(String* str, bool show_impl_info); |
300 | 479 |
301 void WriteToLogFile(); | 480 void WriteToLogFile(); |
302 void WriteCStringToLogFile(const char* str); | 481 void WriteCStringToLogFile(const char* str); |
303 | 482 |
304 private: | 483 private: |
305 ScopedLock sl; | 484 ScopedLock sl; |
306 int pos_; | 485 int pos_; |
307 }; | 486 }; |
308 | 487 |
309 | 488 |
310 // Create a message builder starting from position 0. This acquires the mutex | 489 // Create a message builder starting from position 0. This acquires the mutex |
311 // in the logger as well. | 490 // in the logger as well. |
312 LogMessageBuilder::LogMessageBuilder(): sl(Logger::mutex_), pos_(0) { | 491 LogMessageBuilder::LogMessageBuilder(): sl(Log::mutex_), pos_(0) { |
313 ASSERT(Logger::message_buffer_ != NULL); | 492 ASSERT(Log::message_buffer_ != NULL); |
314 } | 493 } |
315 | 494 |
316 | 495 |
317 // Append string data to the log message. | 496 // Append string data to the log message. |
318 void LogMessageBuilder::Append(const char* format, ...) { | 497 void LogMessageBuilder::Append(const char* format, ...) { |
319 Vector<char> buf(Logger::message_buffer_ + pos_, | 498 Vector<char> buf(Log::message_buffer_ + pos_, |
320 Logger::kMessageBufferSize - pos_); | 499 Log::kMessageBufferSize - pos_); |
321 va_list args; | 500 va_list args; |
322 va_start(args, format); | 501 va_start(args, format); |
323 Append(format, args); | 502 Append(format, args); |
324 va_end(args); | 503 va_end(args); |
325 ASSERT(pos_ <= Logger::kMessageBufferSize); | 504 ASSERT(pos_ <= Log::kMessageBufferSize); |
326 } | 505 } |
327 | 506 |
328 | 507 |
329 // Append string data to the log message. | 508 // Append string data to the log message. |
330 void LogMessageBuilder::Append(const char* format, va_list args) { | 509 void LogMessageBuilder::Append(const char* format, va_list args) { |
331 Vector<char> buf(Logger::message_buffer_ + pos_, | 510 Vector<char> buf(Log::message_buffer_ + pos_, |
332 Logger::kMessageBufferSize - pos_); | 511 Log::kMessageBufferSize - pos_); |
333 int result = v8::internal::OS::VSNPrintF(buf, format, args); | 512 int result = v8::internal::OS::VSNPrintF(buf, format, args); |
334 | 513 |
335 // Result is -1 if output was truncated. | 514 // Result is -1 if output was truncated. |
336 if (result >= 0) { | 515 if (result >= 0) { |
337 pos_ += result; | 516 pos_ += result; |
338 } else { | 517 } else { |
339 pos_ = Logger::kMessageBufferSize; | 518 pos_ = Log::kMessageBufferSize; |
340 } | 519 } |
341 ASSERT(pos_ <= Logger::kMessageBufferSize); | 520 ASSERT(pos_ <= Log::kMessageBufferSize); |
342 } | 521 } |
343 | 522 |
344 | 523 |
345 // Append a character to the log message. | 524 // Append a character to the log message. |
346 void LogMessageBuilder::Append(const char c) { | 525 void LogMessageBuilder::Append(const char c) { |
347 if (pos_ < Logger::kMessageBufferSize) { | 526 if (pos_ < Log::kMessageBufferSize) { |
348 Logger::message_buffer_[pos_++] = c; | 527 Log::message_buffer_[pos_++] = c; |
349 } | 528 } |
350 ASSERT(pos_ <= Logger::kMessageBufferSize); | 529 ASSERT(pos_ <= Log::kMessageBufferSize); |
351 } | 530 } |
352 | 531 |
353 | 532 |
354 // Append a heap string. | 533 // Append a heap string. |
355 void LogMessageBuilder::Append(String* str) { | 534 void LogMessageBuilder::Append(String* str) { |
356 AssertNoAllocation no_heap_allocation; // Ensure string stay valid. | 535 AssertNoAllocation no_heap_allocation; // Ensure string stay valid. |
357 int length = str->length(); | 536 int length = str->length(); |
358 for (int i = 0; i < length; i++) { | 537 for (int i = 0; i < length; i++) { |
359 Append(static_cast<char>(str->Get(i))); | 538 Append(static_cast<char>(str->Get(i))); |
360 } | 539 } |
(...skipping 23 matching lines...) Expand all Loading... |
384 } else if (c == '\\') { | 563 } else if (c == '\\') { |
385 Append("\\\\"); | 564 Append("\\\\"); |
386 } else { | 565 } else { |
387 Append("%lc", c); | 566 Append("%lc", c); |
388 } | 567 } |
389 } | 568 } |
390 } | 569 } |
391 | 570 |
392 // Write the log message to the log file currently opened. | 571 // Write the log message to the log file currently opened. |
393 void LogMessageBuilder::WriteToLogFile() { | 572 void LogMessageBuilder::WriteToLogFile() { |
394 ASSERT(pos_ <= Logger::kMessageBufferSize); | 573 ASSERT(pos_ <= Log::kMessageBufferSize); |
395 size_t rv = fwrite(Logger::message_buffer_, 1, pos_, Logger::logfile_); | 574 Log::Write(Log::message_buffer_, pos_); |
396 ASSERT(rv == static_cast<size_t>(pos_)); | |
397 USE(rv); | |
398 } | 575 } |
399 | 576 |
400 // Write a null-terminated string to to the log file currently opened. | 577 // Write a null-terminated string to to the log file currently opened. |
401 void LogMessageBuilder::WriteCStringToLogFile(const char* str) { | 578 void LogMessageBuilder::WriteCStringToLogFile(const char* str) { |
402 size_t len = strlen(str); | 579 int len = strlen(str); |
403 size_t rv = fwrite(str, 1, len, Logger::logfile_); | 580 Log::Write(str, len); |
404 ASSERT(rv == len); | |
405 USE(rv); | |
406 } | 581 } |
407 #endif | 582 #endif |
408 | 583 |
409 | 584 |
410 // | 585 // |
411 // Logger class implementation. | 586 // Logger class implementation. |
412 // | 587 // |
413 Ticker* Logger::ticker_ = NULL; | 588 Ticker* Logger::ticker_ = NULL; |
414 char* Logger::message_buffer_ = NULL; | |
415 FILE* Logger::logfile_ = NULL; | |
416 Profiler* Logger::profiler_ = NULL; | 589 Profiler* Logger::profiler_ = NULL; |
417 Mutex* Logger::mutex_ = NULL; | |
418 VMState* Logger::current_state_ = NULL; | 590 VMState* Logger::current_state_ = NULL; |
419 VMState Logger::bottom_state_(EXTERNAL); | 591 VMState Logger::bottom_state_(EXTERNAL); |
420 SlidingStateWindow* Logger::sliding_state_window_ = NULL; | 592 SlidingStateWindow* Logger::sliding_state_window_ = NULL; |
421 | 593 |
| 594 |
| 595 bool Logger::IsEnabled() { |
| 596 return Log::is_enabled(); |
| 597 } |
| 598 |
422 #endif // ENABLE_LOGGING_AND_PROFILING | 599 #endif // ENABLE_LOGGING_AND_PROFILING |
423 | 600 |
424 | 601 |
425 void Logger::Preamble(const char* content) { | 602 void Logger::Preamble(const char* content) { |
426 #ifdef ENABLE_LOGGING_AND_PROFILING | 603 #ifdef ENABLE_LOGGING_AND_PROFILING |
427 if (logfile_ == NULL || !FLAG_log_code) return; | 604 if (!Log::is_enabled() || !FLAG_log_code) return; |
428 LogMessageBuilder msg; | 605 LogMessageBuilder msg; |
429 msg.WriteCStringToLogFile(content); | 606 msg.WriteCStringToLogFile(content); |
430 #endif | 607 #endif |
431 } | 608 } |
432 | 609 |
433 | 610 |
434 void Logger::StringEvent(const char* name, const char* value) { | 611 void Logger::StringEvent(const char* name, const char* value) { |
435 #ifdef ENABLE_LOGGING_AND_PROFILING | 612 #ifdef ENABLE_LOGGING_AND_PROFILING |
436 if (FLAG_log) UncheckedStringEvent(name, value); | 613 if (FLAG_log) UncheckedStringEvent(name, value); |
437 #endif | 614 #endif |
438 } | 615 } |
439 | 616 |
440 | 617 |
441 #ifdef ENABLE_LOGGING_AND_PROFILING | 618 #ifdef ENABLE_LOGGING_AND_PROFILING |
442 void Logger::UncheckedStringEvent(const char* name, const char* value) { | 619 void Logger::UncheckedStringEvent(const char* name, const char* value) { |
443 if (logfile_ == NULL) return; | 620 if (!Log::is_enabled()) return; |
444 LogMessageBuilder msg; | 621 LogMessageBuilder msg; |
445 msg.Append("%s,\"%s\"\n", name, value); | 622 msg.Append("%s,\"%s\"\n", name, value); |
446 msg.WriteToLogFile(); | 623 msg.WriteToLogFile(); |
447 } | 624 } |
448 #endif | 625 #endif |
449 | 626 |
450 | 627 |
451 void Logger::IntEvent(const char* name, int value) { | 628 void Logger::IntEvent(const char* name, int value) { |
452 #ifdef ENABLE_LOGGING_AND_PROFILING | 629 #ifdef ENABLE_LOGGING_AND_PROFILING |
453 if (logfile_ == NULL || !FLAG_log) return; | 630 if (!Log::is_enabled() || !FLAG_log) return; |
454 LogMessageBuilder msg; | 631 LogMessageBuilder msg; |
455 msg.Append("%s,%d\n", name, value); | 632 msg.Append("%s,%d\n", name, value); |
456 msg.WriteToLogFile(); | 633 msg.WriteToLogFile(); |
457 #endif | 634 #endif |
458 } | 635 } |
459 | 636 |
460 | 637 |
461 void Logger::HandleEvent(const char* name, Object** location) { | 638 void Logger::HandleEvent(const char* name, Object** location) { |
462 #ifdef ENABLE_LOGGING_AND_PROFILING | 639 #ifdef ENABLE_LOGGING_AND_PROFILING |
463 if (logfile_ == NULL || !FLAG_log_handles) return; | 640 if (!Log::is_enabled() || !FLAG_log_handles) return; |
464 LogMessageBuilder msg; | 641 LogMessageBuilder msg; |
465 msg.Append("%s,0x%x\n", name, | 642 msg.Append("%s,0x%x\n", name, |
466 reinterpret_cast<unsigned int>(location)); | 643 reinterpret_cast<unsigned int>(location)); |
467 msg.WriteToLogFile(); | 644 msg.WriteToLogFile(); |
468 #endif | 645 #endif |
469 } | 646 } |
470 | 647 |
471 | 648 |
472 #ifdef ENABLE_LOGGING_AND_PROFILING | 649 #ifdef ENABLE_LOGGING_AND_PROFILING |
473 // ApiEvent is private so all the calls come from the Logger class. It is the | 650 // ApiEvent is private so all the calls come from the Logger class. It is the |
474 // caller's responsibility to ensure that logfile_ is not NULL and that | 651 // caller's responsibility to ensure that log is enabled and that |
475 // FLAG_log_api is true. | 652 // FLAG_log_api is true. |
476 void Logger::ApiEvent(const char* format, ...) { | 653 void Logger::ApiEvent(const char* format, ...) { |
477 ASSERT(logfile_ != NULL && FLAG_log_api); | 654 ASSERT(Log::is_enabled() && FLAG_log_api); |
478 LogMessageBuilder msg; | 655 LogMessageBuilder msg; |
479 va_list ap; | 656 va_list ap; |
480 va_start(ap, format); | 657 va_start(ap, format); |
481 msg.Append(format, ap); | 658 msg.Append(format, ap); |
482 va_end(ap); | 659 va_end(ap); |
483 msg.WriteToLogFile(); | 660 msg.WriteToLogFile(); |
484 } | 661 } |
485 #endif | 662 #endif |
486 | 663 |
487 | 664 |
488 void Logger::ApiNamedSecurityCheck(Object* key) { | 665 void Logger::ApiNamedSecurityCheck(Object* key) { |
489 #ifdef ENABLE_LOGGING_AND_PROFILING | 666 #ifdef ENABLE_LOGGING_AND_PROFILING |
490 if (logfile_ == NULL || !FLAG_log_api) return; | 667 if (!Log::is_enabled() || !FLAG_log_api) return; |
491 if (key->IsString()) { | 668 if (key->IsString()) { |
492 SmartPointer<char> str = | 669 SmartPointer<char> str = |
493 String::cast(key)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 670 String::cast(key)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
494 ApiEvent("api,check-security,\"%s\"\n", *str); | 671 ApiEvent("api,check-security,\"%s\"\n", *str); |
495 } else if (key->IsUndefined()) { | 672 } else if (key->IsUndefined()) { |
496 ApiEvent("api,check-security,undefined\n"); | 673 ApiEvent("api,check-security,undefined\n"); |
497 } else { | 674 } else { |
498 ApiEvent("api,check-security,['no-name']\n"); | 675 ApiEvent("api,check-security,['no-name']\n"); |
499 } | 676 } |
500 #endif | 677 #endif |
501 } | 678 } |
502 | 679 |
503 | 680 |
504 void Logger::SharedLibraryEvent(const char* library_path, | 681 void Logger::SharedLibraryEvent(const char* library_path, |
505 unsigned start, | 682 unsigned start, |
506 unsigned end) { | 683 unsigned end) { |
507 #ifdef ENABLE_LOGGING_AND_PROFILING | 684 #ifdef ENABLE_LOGGING_AND_PROFILING |
508 if (logfile_ == NULL || !FLAG_prof) return; | 685 if (!Log::is_enabled() || !FLAG_prof) return; |
509 LogMessageBuilder msg; | 686 LogMessageBuilder msg; |
510 msg.Append("shared-library,\"%s\",0x%08x,0x%08x\n", library_path, | 687 msg.Append("shared-library,\"%s\",0x%08x,0x%08x\n", library_path, |
511 start, end); | 688 start, end); |
512 msg.WriteToLogFile(); | 689 msg.WriteToLogFile(); |
513 #endif | 690 #endif |
514 } | 691 } |
515 | 692 |
516 | 693 |
517 void Logger::SharedLibraryEvent(const wchar_t* library_path, | 694 void Logger::SharedLibraryEvent(const wchar_t* library_path, |
518 unsigned start, | 695 unsigned start, |
519 unsigned end) { | 696 unsigned end) { |
520 #ifdef ENABLE_LOGGING_AND_PROFILING | 697 #ifdef ENABLE_LOGGING_AND_PROFILING |
521 if (logfile_ == NULL || !FLAG_prof) return; | 698 if (!Log::is_enabled() || !FLAG_prof) return; |
522 LogMessageBuilder msg; | 699 LogMessageBuilder msg; |
523 msg.Append("shared-library,\"%ls\",0x%08x,0x%08x\n", library_path, | 700 msg.Append("shared-library,\"%ls\",0x%08x,0x%08x\n", library_path, |
524 start, end); | 701 start, end); |
525 msg.WriteToLogFile(); | 702 msg.WriteToLogFile(); |
526 #endif | 703 #endif |
527 } | 704 } |
528 | 705 |
529 | 706 |
530 #ifdef ENABLE_LOGGING_AND_PROFILING | 707 #ifdef ENABLE_LOGGING_AND_PROFILING |
531 void Logger::LogRegExpSource(Handle<JSRegExp> regexp) { | 708 void Logger::LogRegExpSource(Handle<JSRegExp> regexp) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 msg.Append('m'); | 743 msg.Append('m'); |
567 } | 744 } |
568 | 745 |
569 msg.WriteToLogFile(); | 746 msg.WriteToLogFile(); |
570 } | 747 } |
571 #endif // ENABLE_LOGGING_AND_PROFILING | 748 #endif // ENABLE_LOGGING_AND_PROFILING |
572 | 749 |
573 | 750 |
574 void Logger::RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache) { | 751 void Logger::RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache) { |
575 #ifdef ENABLE_LOGGING_AND_PROFILING | 752 #ifdef ENABLE_LOGGING_AND_PROFILING |
576 if (logfile_ == NULL || !FLAG_log_regexp) return; | 753 if (!Log::is_enabled() || !FLAG_log_regexp) return; |
577 LogMessageBuilder msg; | 754 LogMessageBuilder msg; |
578 msg.Append("regexp-compile,"); | 755 msg.Append("regexp-compile,"); |
579 LogRegExpSource(regexp); | 756 LogRegExpSource(regexp); |
580 msg.Append(in_cache ? ",hit\n" : ",miss\n"); | 757 msg.Append(in_cache ? ",hit\n" : ",miss\n"); |
581 msg.WriteToLogFile(); | 758 msg.WriteToLogFile(); |
582 #endif | 759 #endif |
583 } | 760 } |
584 | 761 |
585 | 762 |
586 void Logger::LogRuntime(Vector<const char> format, JSArray* args) { | 763 void Logger::LogRuntime(Vector<const char> format, JSArray* args) { |
587 #ifdef ENABLE_LOGGING_AND_PROFILING | 764 #ifdef ENABLE_LOGGING_AND_PROFILING |
588 if (logfile_ == NULL || !FLAG_log_runtime) return; | 765 if (!Log::is_enabled() || !FLAG_log_runtime) return; |
589 HandleScope scope; | 766 HandleScope scope; |
590 LogMessageBuilder msg; | 767 LogMessageBuilder msg; |
591 for (int i = 0; i < format.length(); i++) { | 768 for (int i = 0; i < format.length(); i++) { |
592 char c = format[i]; | 769 char c = format[i]; |
593 if (c == '%' && i <= format.length() - 2) { | 770 if (c == '%' && i <= format.length() - 2) { |
594 i++; | 771 i++; |
595 ASSERT('0' <= format[i] && format[i] <= '9'); | 772 ASSERT('0' <= format[i] && format[i] <= '9'); |
596 Object* obj = args->GetElement(format[i] - '0'); | 773 Object* obj = args->GetElement(format[i] - '0'); |
597 i++; | 774 i++; |
598 switch (format[i]) { | 775 switch (format[i]) { |
(...skipping 20 matching lines...) Expand all Loading... |
619 } | 796 } |
620 } | 797 } |
621 msg.Append('\n'); | 798 msg.Append('\n'); |
622 msg.WriteToLogFile(); | 799 msg.WriteToLogFile(); |
623 #endif | 800 #endif |
624 } | 801 } |
625 | 802 |
626 | 803 |
627 void Logger::ApiIndexedSecurityCheck(uint32_t index) { | 804 void Logger::ApiIndexedSecurityCheck(uint32_t index) { |
628 #ifdef ENABLE_LOGGING_AND_PROFILING | 805 #ifdef ENABLE_LOGGING_AND_PROFILING |
629 if (logfile_ == NULL || !FLAG_log_api) return; | 806 if (!Log::is_enabled() || !FLAG_log_api) return; |
630 ApiEvent("api,check-security,%u\n", index); | 807 ApiEvent("api,check-security,%u\n", index); |
631 #endif | 808 #endif |
632 } | 809 } |
633 | 810 |
634 | 811 |
635 void Logger::ApiNamedPropertyAccess(const char* tag, | 812 void Logger::ApiNamedPropertyAccess(const char* tag, |
636 JSObject* holder, | 813 JSObject* holder, |
637 Object* name) { | 814 Object* name) { |
638 #ifdef ENABLE_LOGGING_AND_PROFILING | 815 #ifdef ENABLE_LOGGING_AND_PROFILING |
639 ASSERT(name->IsString()); | 816 ASSERT(name->IsString()); |
640 if (logfile_ == NULL || !FLAG_log_api) return; | 817 if (!Log::is_enabled() || !FLAG_log_api) return; |
641 String* class_name_obj = holder->class_name(); | 818 String* class_name_obj = holder->class_name(); |
642 SmartPointer<char> class_name = | 819 SmartPointer<char> class_name = |
643 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 820 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
644 SmartPointer<char> property_name = | 821 SmartPointer<char> property_name = |
645 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 822 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
646 Logger::ApiEvent("api,%s,\"%s\",\"%s\"\n", tag, *class_name, *property_name); | 823 Logger::ApiEvent("api,%s,\"%s\",\"%s\"\n", tag, *class_name, *property_name); |
647 #endif | 824 #endif |
648 } | 825 } |
649 | 826 |
650 void Logger::ApiIndexedPropertyAccess(const char* tag, | 827 void Logger::ApiIndexedPropertyAccess(const char* tag, |
651 JSObject* holder, | 828 JSObject* holder, |
652 uint32_t index) { | 829 uint32_t index) { |
653 #ifdef ENABLE_LOGGING_AND_PROFILING | 830 #ifdef ENABLE_LOGGING_AND_PROFILING |
654 if (logfile_ == NULL || !FLAG_log_api) return; | 831 if (!Log::is_enabled() || !FLAG_log_api) return; |
655 String* class_name_obj = holder->class_name(); | 832 String* class_name_obj = holder->class_name(); |
656 SmartPointer<char> class_name = | 833 SmartPointer<char> class_name = |
657 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 834 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
658 Logger::ApiEvent("api,%s,\"%s\",%u\n", tag, *class_name, index); | 835 Logger::ApiEvent("api,%s,\"%s\",%u\n", tag, *class_name, index); |
659 #endif | 836 #endif |
660 } | 837 } |
661 | 838 |
662 void Logger::ApiObjectAccess(const char* tag, JSObject* object) { | 839 void Logger::ApiObjectAccess(const char* tag, JSObject* object) { |
663 #ifdef ENABLE_LOGGING_AND_PROFILING | 840 #ifdef ENABLE_LOGGING_AND_PROFILING |
664 if (logfile_ == NULL || !FLAG_log_api) return; | 841 if (!Log::is_enabled() || !FLAG_log_api) return; |
665 String* class_name_obj = object->class_name(); | 842 String* class_name_obj = object->class_name(); |
666 SmartPointer<char> class_name = | 843 SmartPointer<char> class_name = |
667 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 844 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
668 Logger::ApiEvent("api,%s,\"%s\"\n", tag, *class_name); | 845 Logger::ApiEvent("api,%s,\"%s\"\n", tag, *class_name); |
669 #endif | 846 #endif |
670 } | 847 } |
671 | 848 |
672 | 849 |
673 void Logger::ApiEntryCall(const char* name) { | 850 void Logger::ApiEntryCall(const char* name) { |
674 #ifdef ENABLE_LOGGING_AND_PROFILING | 851 #ifdef ENABLE_LOGGING_AND_PROFILING |
675 if (logfile_ == NULL || !FLAG_log_api) return; | 852 if (!Log::is_enabled() || !FLAG_log_api) return; |
676 Logger::ApiEvent("api,%s\n", name); | 853 Logger::ApiEvent("api,%s\n", name); |
677 #endif | 854 #endif |
678 } | 855 } |
679 | 856 |
680 | 857 |
681 void Logger::NewEvent(const char* name, void* object, size_t size) { | 858 void Logger::NewEvent(const char* name, void* object, size_t size) { |
682 #ifdef ENABLE_LOGGING_AND_PROFILING | 859 #ifdef ENABLE_LOGGING_AND_PROFILING |
683 if (logfile_ == NULL || !FLAG_log) return; | 860 if (!Log::is_enabled() || !FLAG_log) return; |
684 LogMessageBuilder msg; | 861 LogMessageBuilder msg; |
685 msg.Append("new,%s,0x%x,%u\n", name, | 862 msg.Append("new,%s,0x%x,%u\n", name, |
686 reinterpret_cast<unsigned int>(object), | 863 reinterpret_cast<unsigned int>(object), |
687 static_cast<unsigned int>(size)); | 864 static_cast<unsigned int>(size)); |
688 msg.WriteToLogFile(); | 865 msg.WriteToLogFile(); |
689 #endif | 866 #endif |
690 } | 867 } |
691 | 868 |
692 | 869 |
693 void Logger::DeleteEvent(const char* name, void* object) { | 870 void Logger::DeleteEvent(const char* name, void* object) { |
694 #ifdef ENABLE_LOGGING_AND_PROFILING | 871 #ifdef ENABLE_LOGGING_AND_PROFILING |
695 if (logfile_ == NULL || !FLAG_log) return; | 872 if (!Log::is_enabled() || !FLAG_log) return; |
696 LogMessageBuilder msg; | 873 LogMessageBuilder msg; |
697 msg.Append("delete,%s,0x%x\n", name, | 874 msg.Append("delete,%s,0x%x\n", name, |
698 reinterpret_cast<unsigned int>(object)); | 875 reinterpret_cast<unsigned int>(object)); |
699 msg.WriteToLogFile(); | 876 msg.WriteToLogFile(); |
700 #endif | 877 #endif |
701 } | 878 } |
702 | 879 |
703 | 880 |
704 void Logger::CodeCreateEvent(const char* tag, Code* code, const char* comment) { | 881 void Logger::CodeCreateEvent(const char* tag, Code* code, const char* comment) { |
705 #ifdef ENABLE_LOGGING_AND_PROFILING | 882 #ifdef ENABLE_LOGGING_AND_PROFILING |
706 if (logfile_ == NULL || !FLAG_log_code) return; | 883 if (!Log::is_enabled() || !FLAG_log_code) return; |
707 LogMessageBuilder msg; | 884 LogMessageBuilder msg; |
708 msg.Append("code-creation,%s,0x%x,%d,\"", tag, | 885 msg.Append("code-creation,%s,0x%x,%d,\"", tag, |
709 reinterpret_cast<unsigned int>(code->address()), | 886 reinterpret_cast<unsigned int>(code->address()), |
710 code->ExecutableSize()); | 887 code->ExecutableSize()); |
711 for (const char* p = comment; *p != '\0'; p++) { | 888 for (const char* p = comment; *p != '\0'; p++) { |
712 if (*p == '"') { | 889 if (*p == '"') { |
713 msg.Append('\\'); | 890 msg.Append('\\'); |
714 } | 891 } |
715 msg.Append(*p); | 892 msg.Append(*p); |
716 } | 893 } |
717 msg.Append('"'); | 894 msg.Append('"'); |
718 msg.Append('\n'); | 895 msg.Append('\n'); |
719 msg.WriteToLogFile(); | 896 msg.WriteToLogFile(); |
720 #endif | 897 #endif |
721 } | 898 } |
722 | 899 |
723 | 900 |
724 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name) { | 901 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name) { |
725 #ifdef ENABLE_LOGGING_AND_PROFILING | 902 #ifdef ENABLE_LOGGING_AND_PROFILING |
726 if (logfile_ == NULL || !FLAG_log_code) return; | 903 if (!Log::is_enabled() || !FLAG_log_code) return; |
727 LogMessageBuilder msg; | 904 LogMessageBuilder msg; |
728 SmartPointer<char> str = | 905 SmartPointer<char> str = |
729 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 906 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
730 msg.Append("code-creation,%s,0x%x,%d,\"%s\"\n", tag, | 907 msg.Append("code-creation,%s,0x%x,%d,\"%s\"\n", tag, |
731 reinterpret_cast<unsigned int>(code->address()), | 908 reinterpret_cast<unsigned int>(code->address()), |
732 code->ExecutableSize(), *str); | 909 code->ExecutableSize(), *str); |
733 msg.WriteToLogFile(); | 910 msg.WriteToLogFile(); |
734 #endif | 911 #endif |
735 } | 912 } |
736 | 913 |
737 | 914 |
738 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name, | 915 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name, |
739 String* source, int line) { | 916 String* source, int line) { |
740 #ifdef ENABLE_LOGGING_AND_PROFILING | 917 #ifdef ENABLE_LOGGING_AND_PROFILING |
741 if (logfile_ == NULL || !FLAG_log_code) return; | 918 if (!Log::is_enabled() || !FLAG_log_code) return; |
742 LogMessageBuilder msg; | 919 LogMessageBuilder msg; |
743 SmartPointer<char> str = | 920 SmartPointer<char> str = |
744 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 921 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
745 SmartPointer<char> sourcestr = | 922 SmartPointer<char> sourcestr = |
746 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 923 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
747 msg.Append("code-creation,%s,0x%x,%d,\"%s %s:%d\"\n", tag, | 924 msg.Append("code-creation,%s,0x%x,%d,\"%s %s:%d\"\n", tag, |
748 reinterpret_cast<unsigned int>(code->address()), | 925 reinterpret_cast<unsigned int>(code->address()), |
749 code->ExecutableSize(), | 926 code->ExecutableSize(), |
750 *str, *sourcestr, line); | 927 *str, *sourcestr, line); |
751 msg.WriteToLogFile(); | 928 msg.WriteToLogFile(); |
752 #endif | 929 #endif |
753 } | 930 } |
754 | 931 |
755 | 932 |
756 void Logger::CodeCreateEvent(const char* tag, Code* code, int args_count) { | 933 void Logger::CodeCreateEvent(const char* tag, Code* code, int args_count) { |
757 #ifdef ENABLE_LOGGING_AND_PROFILING | 934 #ifdef ENABLE_LOGGING_AND_PROFILING |
758 if (logfile_ == NULL || !FLAG_log_code) return; | 935 if (!Log::is_enabled() || !FLAG_log_code) return; |
759 LogMessageBuilder msg; | 936 LogMessageBuilder msg; |
760 msg.Append("code-creation,%s,0x%x,%d,\"args_count: %d\"\n", tag, | 937 msg.Append("code-creation,%s,0x%x,%d,\"args_count: %d\"\n", tag, |
761 reinterpret_cast<unsigned int>(code->address()), | 938 reinterpret_cast<unsigned int>(code->address()), |
762 code->ExecutableSize(), | 939 code->ExecutableSize(), |
763 args_count); | 940 args_count); |
764 msg.WriteToLogFile(); | 941 msg.WriteToLogFile(); |
765 #endif | 942 #endif |
766 } | 943 } |
767 | 944 |
768 | 945 |
769 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { | 946 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { |
770 #ifdef ENABLE_LOGGING_AND_PROFILING | 947 #ifdef ENABLE_LOGGING_AND_PROFILING |
771 if (logfile_ == NULL || !FLAG_log_code) return; | 948 if (!Log::is_enabled() || !FLAG_log_code) return; |
772 LogMessageBuilder msg; | 949 LogMessageBuilder msg; |
773 msg.Append("code-creation,%s,0x%x,%d,\"", "RegExp", | 950 msg.Append("code-creation,%s,0x%x,%d,\"", "RegExp", |
774 reinterpret_cast<unsigned int>(code->address()), | 951 reinterpret_cast<unsigned int>(code->address()), |
775 code->ExecutableSize()); | 952 code->ExecutableSize()); |
776 msg.AppendDetailed(source, false); | 953 msg.AppendDetailed(source, false); |
777 msg.Append("\"\n"); | 954 msg.Append("\"\n"); |
778 msg.WriteToLogFile(); | 955 msg.WriteToLogFile(); |
779 #endif | 956 #endif |
780 } | 957 } |
781 | 958 |
782 | 959 |
783 void Logger::CodeAllocateEvent(Code* code, Assembler* assem) { | 960 void Logger::CodeAllocateEvent(Code* code, Assembler* assem) { |
784 #ifdef ENABLE_LOGGING_AND_PROFILING | 961 #ifdef ENABLE_LOGGING_AND_PROFILING |
785 if (logfile_ == NULL || !FLAG_log_code) return; | 962 if (!Log::is_enabled() || !FLAG_log_code) return; |
786 LogMessageBuilder msg; | 963 LogMessageBuilder msg; |
787 msg.Append("code-allocate,0x%x,0x%x\n", | 964 msg.Append("code-allocate,0x%x,0x%x\n", |
788 reinterpret_cast<unsigned int>(code->address()), | 965 reinterpret_cast<unsigned int>(code->address()), |
789 reinterpret_cast<unsigned int>(assem)); | 966 reinterpret_cast<unsigned int>(assem)); |
790 msg.WriteToLogFile(); | 967 msg.WriteToLogFile(); |
791 #endif | 968 #endif |
792 } | 969 } |
793 | 970 |
794 | 971 |
795 void Logger::CodeMoveEvent(Address from, Address to) { | 972 void Logger::CodeMoveEvent(Address from, Address to) { |
796 #ifdef ENABLE_LOGGING_AND_PROFILING | 973 #ifdef ENABLE_LOGGING_AND_PROFILING |
797 if (logfile_ == NULL || !FLAG_log_code) return; | 974 if (!Log::is_enabled() || !FLAG_log_code) return; |
798 LogMessageBuilder msg; | 975 LogMessageBuilder msg; |
799 msg.Append("code-move,0x%x,0x%x\n", | 976 msg.Append("code-move,0x%x,0x%x\n", |
800 reinterpret_cast<unsigned int>(from), | 977 reinterpret_cast<unsigned int>(from), |
801 reinterpret_cast<unsigned int>(to)); | 978 reinterpret_cast<unsigned int>(to)); |
802 msg.WriteToLogFile(); | 979 msg.WriteToLogFile(); |
803 #endif | 980 #endif |
804 } | 981 } |
805 | 982 |
806 | 983 |
807 void Logger::CodeDeleteEvent(Address from) { | 984 void Logger::CodeDeleteEvent(Address from) { |
808 #ifdef ENABLE_LOGGING_AND_PROFILING | 985 #ifdef ENABLE_LOGGING_AND_PROFILING |
809 if (logfile_ == NULL || !FLAG_log_code) return; | 986 if (!Log::is_enabled() || !FLAG_log_code) return; |
810 LogMessageBuilder msg; | 987 LogMessageBuilder msg; |
811 msg.Append("code-delete,0x%x\n", reinterpret_cast<unsigned int>(from)); | 988 msg.Append("code-delete,0x%x\n", reinterpret_cast<unsigned int>(from)); |
812 msg.WriteToLogFile(); | 989 msg.WriteToLogFile(); |
813 #endif | 990 #endif |
814 } | 991 } |
815 | 992 |
816 | 993 |
817 void Logger::BeginCodeRegionEvent(CodeRegion* region, | 994 void Logger::BeginCodeRegionEvent(CodeRegion* region, |
818 Assembler* masm, | 995 Assembler* masm, |
819 const char* name) { | 996 const char* name) { |
820 #ifdef ENABLE_LOGGING_AND_PROFILING | 997 #ifdef ENABLE_LOGGING_AND_PROFILING |
821 if (logfile_ == NULL || !FLAG_log_code) return; | 998 if (!Log::is_enabled() || !FLAG_log_code) return; |
822 LogMessageBuilder msg; | 999 LogMessageBuilder msg; |
823 msg.Append("begin-code-region,0x%x,0x%x,0x%x,%s\n", | 1000 msg.Append("begin-code-region,0x%x,0x%x,0x%x,%s\n", |
824 reinterpret_cast<unsigned int>(region), | 1001 reinterpret_cast<unsigned int>(region), |
825 reinterpret_cast<unsigned int>(masm), | 1002 reinterpret_cast<unsigned int>(masm), |
826 masm->pc_offset(), | 1003 masm->pc_offset(), |
827 name); | 1004 name); |
828 msg.WriteToLogFile(); | 1005 msg.WriteToLogFile(); |
829 #endif | 1006 #endif |
830 } | 1007 } |
831 | 1008 |
832 | 1009 |
833 void Logger::EndCodeRegionEvent(CodeRegion* region, Assembler* masm) { | 1010 void Logger::EndCodeRegionEvent(CodeRegion* region, Assembler* masm) { |
834 #ifdef ENABLE_LOGGING_AND_PROFILING | 1011 #ifdef ENABLE_LOGGING_AND_PROFILING |
835 if (logfile_ == NULL || !FLAG_log_code) return; | 1012 if (!Log::is_enabled() || !FLAG_log_code) return; |
836 LogMessageBuilder msg; | 1013 LogMessageBuilder msg; |
837 msg.Append("end-code-region,0x%x,0x%x,0x%x\n", | 1014 msg.Append("end-code-region,0x%x,0x%x,0x%x\n", |
838 reinterpret_cast<unsigned int>(region), | 1015 reinterpret_cast<unsigned int>(region), |
839 reinterpret_cast<unsigned int>(masm), | 1016 reinterpret_cast<unsigned int>(masm), |
840 masm->pc_offset()); | 1017 masm->pc_offset()); |
841 msg.WriteToLogFile(); | 1018 msg.WriteToLogFile(); |
842 #endif | 1019 #endif |
843 } | 1020 } |
844 | 1021 |
845 | 1022 |
846 void Logger::ResourceEvent(const char* name, const char* tag) { | 1023 void Logger::ResourceEvent(const char* name, const char* tag) { |
847 #ifdef ENABLE_LOGGING_AND_PROFILING | 1024 #ifdef ENABLE_LOGGING_AND_PROFILING |
848 if (logfile_ == NULL || !FLAG_log) return; | 1025 if (!Log::is_enabled() || !FLAG_log) return; |
849 LogMessageBuilder msg; | 1026 LogMessageBuilder msg; |
850 msg.Append("%s,%s,", name, tag); | 1027 msg.Append("%s,%s,", name, tag); |
851 | 1028 |
852 uint32_t sec, usec; | 1029 uint32_t sec, usec; |
853 if (OS::GetUserTime(&sec, &usec) != -1) { | 1030 if (OS::GetUserTime(&sec, &usec) != -1) { |
854 msg.Append("%d,%d,", sec, usec); | 1031 msg.Append("%d,%d,", sec, usec); |
855 } | 1032 } |
856 msg.Append("%.0f", OS::TimeCurrentMillis()); | 1033 msg.Append("%.0f", OS::TimeCurrentMillis()); |
857 | 1034 |
858 msg.Append('\n'); | 1035 msg.Append('\n'); |
859 msg.WriteToLogFile(); | 1036 msg.WriteToLogFile(); |
860 #endif | 1037 #endif |
861 } | 1038 } |
862 | 1039 |
863 | 1040 |
864 void Logger::SuspectReadEvent(String* name, Object* obj) { | 1041 void Logger::SuspectReadEvent(String* name, Object* obj) { |
865 #ifdef ENABLE_LOGGING_AND_PROFILING | 1042 #ifdef ENABLE_LOGGING_AND_PROFILING |
866 if (logfile_ == NULL || !FLAG_log_suspect) return; | 1043 if (!Log::is_enabled() || !FLAG_log_suspect) return; |
867 LogMessageBuilder msg; | 1044 LogMessageBuilder msg; |
868 String* class_name = obj->IsJSObject() | 1045 String* class_name = obj->IsJSObject() |
869 ? JSObject::cast(obj)->class_name() | 1046 ? JSObject::cast(obj)->class_name() |
870 : Heap::empty_string(); | 1047 : Heap::empty_string(); |
871 ScopedLock sl(mutex_); | |
872 msg.Append("suspect-read,"); | 1048 msg.Append("suspect-read,"); |
873 msg.Append(class_name); | 1049 msg.Append(class_name); |
874 msg.Append(','); | 1050 msg.Append(','); |
875 msg.Append('"'); | 1051 msg.Append('"'); |
876 msg.Append(name); | 1052 msg.Append(name); |
877 msg.Append('"'); | 1053 msg.Append('"'); |
878 msg.Append('\n'); | 1054 msg.Append('\n'); |
879 msg.WriteToLogFile(); | 1055 msg.WriteToLogFile(); |
880 #endif | 1056 #endif |
881 } | 1057 } |
882 | 1058 |
883 | 1059 |
884 void Logger::HeapSampleBeginEvent(const char* space, const char* kind) { | 1060 void Logger::HeapSampleBeginEvent(const char* space, const char* kind) { |
885 #ifdef ENABLE_LOGGING_AND_PROFILING | 1061 #ifdef ENABLE_LOGGING_AND_PROFILING |
886 if (logfile_ == NULL || !FLAG_log_gc) return; | 1062 if (!Log::is_enabled() || !FLAG_log_gc) return; |
887 LogMessageBuilder msg; | 1063 LogMessageBuilder msg; |
888 msg.Append("heap-sample-begin,\"%s\",\"%s\"\n", space, kind); | 1064 msg.Append("heap-sample-begin,\"%s\",\"%s\"\n", space, kind); |
889 msg.WriteToLogFile(); | 1065 msg.WriteToLogFile(); |
890 #endif | 1066 #endif |
891 } | 1067 } |
892 | 1068 |
893 | 1069 |
894 void Logger::HeapSampleEndEvent(const char* space, const char* kind) { | 1070 void Logger::HeapSampleEndEvent(const char* space, const char* kind) { |
895 #ifdef ENABLE_LOGGING_AND_PROFILING | 1071 #ifdef ENABLE_LOGGING_AND_PROFILING |
896 if (logfile_ == NULL || !FLAG_log_gc) return; | 1072 if (!Log::is_enabled() || !FLAG_log_gc) return; |
897 LogMessageBuilder msg; | 1073 LogMessageBuilder msg; |
898 msg.Append("heap-sample-end,\"%s\",\"%s\"\n", space, kind); | 1074 msg.Append("heap-sample-end,\"%s\",\"%s\"\n", space, kind); |
899 msg.WriteToLogFile(); | 1075 msg.WriteToLogFile(); |
900 #endif | 1076 #endif |
901 } | 1077 } |
902 | 1078 |
903 | 1079 |
904 void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) { | 1080 void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) { |
905 #ifdef ENABLE_LOGGING_AND_PROFILING | 1081 #ifdef ENABLE_LOGGING_AND_PROFILING |
906 if (logfile_ == NULL || !FLAG_log_gc) return; | 1082 if (!Log::is_enabled() || !FLAG_log_gc) return; |
907 LogMessageBuilder msg; | 1083 LogMessageBuilder msg; |
908 msg.Append("heap-sample-item,%s,%d,%d\n", type, number, bytes); | 1084 msg.Append("heap-sample-item,%s,%d,%d\n", type, number, bytes); |
909 msg.WriteToLogFile(); | 1085 msg.WriteToLogFile(); |
910 #endif | 1086 #endif |
911 } | 1087 } |
912 | 1088 |
913 | 1089 |
914 void Logger::DebugTag(const char* call_site_tag) { | 1090 void Logger::DebugTag(const char* call_site_tag) { |
915 #ifdef ENABLE_LOGGING_AND_PROFILING | 1091 #ifdef ENABLE_LOGGING_AND_PROFILING |
916 if (logfile_ == NULL || !FLAG_log) return; | 1092 if (!Log::is_enabled() || !FLAG_log) return; |
917 LogMessageBuilder msg; | 1093 LogMessageBuilder msg; |
918 msg.Append("debug-tag,%s\n", call_site_tag); | 1094 msg.Append("debug-tag,%s\n", call_site_tag); |
919 msg.WriteToLogFile(); | 1095 msg.WriteToLogFile(); |
920 #endif | 1096 #endif |
921 } | 1097 } |
922 | 1098 |
923 | 1099 |
924 void Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) { | 1100 void Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) { |
925 #ifdef ENABLE_LOGGING_AND_PROFILING | 1101 #ifdef ENABLE_LOGGING_AND_PROFILING |
926 if (logfile_ == NULL || !FLAG_log) return; | 1102 if (!Log::is_enabled() || !FLAG_log) return; |
927 StringBuilder s(parameter.length() + 1); | 1103 StringBuilder s(parameter.length() + 1); |
928 for (int i = 0; i < parameter.length(); ++i) { | 1104 for (int i = 0; i < parameter.length(); ++i) { |
929 s.AddCharacter(static_cast<char>(parameter[i])); | 1105 s.AddCharacter(static_cast<char>(parameter[i])); |
930 } | 1106 } |
931 char* parameter_string = s.Finalize(); | 1107 char* parameter_string = s.Finalize(); |
932 LogMessageBuilder msg; | 1108 LogMessageBuilder msg; |
933 msg.Append("debug-queue-event,%s,%15.3f,%s\n", | 1109 msg.Append("debug-queue-event,%s,%15.3f,%s\n", |
934 event_type, | 1110 event_type, |
935 OS::TimeCurrentMillis(), | 1111 OS::TimeCurrentMillis(), |
936 parameter_string); | 1112 parameter_string); |
937 DeleteArray(parameter_string); | 1113 DeleteArray(parameter_string); |
938 msg.WriteToLogFile(); | 1114 msg.WriteToLogFile(); |
939 #endif | 1115 #endif |
940 } | 1116 } |
941 | 1117 |
942 | 1118 |
943 #ifdef ENABLE_LOGGING_AND_PROFILING | 1119 #ifdef ENABLE_LOGGING_AND_PROFILING |
944 void Logger::TickEvent(TickSample* sample, bool overflow) { | 1120 void Logger::TickEvent(TickSample* sample, bool overflow) { |
945 if (logfile_ == NULL || !FLAG_prof) return; | 1121 if (!Log::is_enabled() || !FLAG_prof) return; |
946 LogMessageBuilder msg; | 1122 LogMessageBuilder msg; |
947 msg.Append("tick,0x%x,0x%x,%d", sample->pc, sample->sp, | 1123 msg.Append("tick,0x%x,0x%x,%d", sample->pc, sample->sp, |
948 static_cast<int>(sample->state)); | 1124 static_cast<int>(sample->state)); |
949 if (overflow) { | 1125 if (overflow) { |
950 msg.Append(",overflow"); | 1126 msg.Append(",overflow"); |
951 } | 1127 } |
952 for (int i = 0; i < sample->frames_count; ++i) { | 1128 for (int i = 0; i < sample->frames_count; ++i) { |
953 msg.Append(",0x%x", reinterpret_cast<uint32_t>(sample->stack[i])); | 1129 msg.Append(",0x%x", reinterpret_cast<uint32_t>(sample->stack[i])); |
954 } | 1130 } |
955 msg.Append('\n'); | 1131 msg.Append('\n'); |
956 msg.WriteToLogFile(); | 1132 msg.WriteToLogFile(); |
957 } | 1133 } |
958 | 1134 |
959 | 1135 |
960 bool Logger::IsProfilerPaused() { | 1136 bool Logger::IsProfilerPaused() { |
961 return profiler_->paused(); | 1137 return profiler_->paused(); |
962 } | 1138 } |
963 | 1139 |
964 | 1140 |
965 void Logger::PauseProfiler() { | 1141 void Logger::PauseProfiler() { |
966 profiler_->pause(); | 1142 profiler_->pause(); |
967 } | 1143 } |
968 | 1144 |
969 | 1145 |
970 void Logger::ResumeProfiler() { | 1146 void Logger::ResumeProfiler() { |
971 profiler_->resume(); | 1147 profiler_->resume(); |
972 } | 1148 } |
| 1149 |
| 1150 |
| 1151 int Logger::GetLogLines(int from_pos, char* dest_buf, int max_size) { |
| 1152 return Log::GetLogLines(from_pos, dest_buf, max_size); |
| 1153 } |
| 1154 |
973 #endif | 1155 #endif |
974 | 1156 |
975 | 1157 |
976 bool Logger::Setup() { | 1158 bool Logger::Setup() { |
977 #ifdef ENABLE_LOGGING_AND_PROFILING | 1159 #ifdef ENABLE_LOGGING_AND_PROFILING |
978 // --log-all enables all the log flags. | 1160 // --log-all enables all the log flags. |
979 if (FLAG_log_all) { | 1161 if (FLAG_log_all) { |
980 FLAG_log_runtime = true; | 1162 FLAG_log_runtime = true; |
981 FLAG_log_api = true; | 1163 FLAG_log_api = true; |
982 FLAG_log_code = true; | 1164 FLAG_log_code = true; |
983 FLAG_log_gc = true; | 1165 FLAG_log_gc = true; |
984 FLAG_log_suspect = true; | 1166 FLAG_log_suspect = true; |
985 FLAG_log_handles = true; | 1167 FLAG_log_handles = true; |
986 FLAG_log_regexp = true; | 1168 FLAG_log_regexp = true; |
987 } | 1169 } |
988 | 1170 |
989 // --prof implies --log-code. | 1171 // --prof implies --log-code. |
990 if (FLAG_prof) FLAG_log_code = true; | 1172 if (FLAG_prof) FLAG_log_code = true; |
991 | 1173 |
992 bool open_log_file = FLAG_log || FLAG_log_runtime || FLAG_log_api | 1174 bool open_log_file = FLAG_log || FLAG_log_runtime || FLAG_log_api |
993 || FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect | 1175 || FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect |
994 || FLAG_log_regexp || FLAG_log_state_changes; | 1176 || FLAG_log_regexp || FLAG_log_state_changes; |
995 | 1177 |
996 // If we're logging anything, we need to open the log file. | 1178 // If we're logging anything, we need to open the log file. |
997 if (open_log_file) { | 1179 if (open_log_file) { |
998 if (strcmp(FLAG_logfile, "-") == 0) { | 1180 if (strcmp(FLAG_logfile, "-") == 0) { |
999 logfile_ = stdout; | 1181 Log::OpenStdout(); |
| 1182 } else if (strcmp(FLAG_logfile, "*") == 0) { |
| 1183 Log::OpenMemoryBuffer(); |
1000 } else if (strchr(FLAG_logfile, '%') != NULL) { | 1184 } else if (strchr(FLAG_logfile, '%') != NULL) { |
1001 // If there's a '%' in the log file name we have to expand | 1185 // If there's a '%' in the log file name we have to expand |
1002 // placeholders. | 1186 // placeholders. |
1003 HeapStringAllocator allocator; | 1187 HeapStringAllocator allocator; |
1004 StringStream stream(&allocator); | 1188 StringStream stream(&allocator); |
1005 for (const char* p = FLAG_logfile; *p; p++) { | 1189 for (const char* p = FLAG_logfile; *p; p++) { |
1006 if (*p == '%') { | 1190 if (*p == '%') { |
1007 p++; | 1191 p++; |
1008 switch (*p) { | 1192 switch (*p) { |
1009 case '\0': | 1193 case '\0': |
(...skipping 15 matching lines...) Expand all Loading... |
1025 // All other %'s expand to themselves. | 1209 // All other %'s expand to themselves. |
1026 stream.Put('%'); | 1210 stream.Put('%'); |
1027 stream.Put(*p); | 1211 stream.Put(*p); |
1028 break; | 1212 break; |
1029 } | 1213 } |
1030 } else { | 1214 } else { |
1031 stream.Put(*p); | 1215 stream.Put(*p); |
1032 } | 1216 } |
1033 } | 1217 } |
1034 SmartPointer<const char> expanded = stream.ToCString(); | 1218 SmartPointer<const char> expanded = stream.ToCString(); |
1035 logfile_ = OS::FOpen(*expanded, OS::LogFileOpenMode); | 1219 Log::OpenFile(*expanded); |
1036 } else { | 1220 } else { |
1037 logfile_ = OS::FOpen(FLAG_logfile, OS::LogFileOpenMode); | 1221 Log::OpenFile(FLAG_logfile); |
1038 } | 1222 } |
1039 message_buffer_ = NewArray<char>(kMessageBufferSize); | |
1040 mutex_ = OS::CreateMutex(); | |
1041 } | 1223 } |
1042 | 1224 |
1043 current_state_ = &bottom_state_; | 1225 current_state_ = &bottom_state_; |
1044 | 1226 |
1045 // as log is initialized early with V8, we can assume that JS execution | 1227 // as log is initialized early with V8, we can assume that JS execution |
1046 // frames can never reach this point on stack | 1228 // frames can never reach this point on stack |
1047 int stack_var; | 1229 int stack_var; |
1048 ticker_ = new Ticker(1, reinterpret_cast<unsigned int>(&stack_var)); | 1230 ticker_ = new Ticker(1, reinterpret_cast<unsigned int>(&stack_var)); |
1049 | 1231 |
1050 if (FLAG_sliding_state_window && sliding_state_window_ == NULL) { | 1232 if (FLAG_sliding_state_window && sliding_state_window_ == NULL) { |
(...skipping 21 matching lines...) Expand all Loading... |
1072 if (profiler_ != NULL) { | 1254 if (profiler_ != NULL) { |
1073 profiler_->Disengage(); | 1255 profiler_->Disengage(); |
1074 delete profiler_; | 1256 delete profiler_; |
1075 profiler_ = NULL; | 1257 profiler_ = NULL; |
1076 } | 1258 } |
1077 | 1259 |
1078 delete sliding_state_window_; | 1260 delete sliding_state_window_; |
1079 | 1261 |
1080 delete ticker_; | 1262 delete ticker_; |
1081 | 1263 |
1082 if (logfile_ != NULL) { | 1264 Log::Close(); |
1083 fclose(logfile_); | |
1084 logfile_ = NULL; | |
1085 delete mutex_; | |
1086 mutex_ = NULL; | |
1087 DeleteArray(message_buffer_); | |
1088 } | |
1089 #endif | 1265 #endif |
1090 } | 1266 } |
1091 | 1267 |
1092 | 1268 |
1093 void Logger::EnableSlidingStateWindow() { | 1269 void Logger::EnableSlidingStateWindow() { |
1094 #ifdef ENABLE_LOGGING_AND_PROFILING | 1270 #ifdef ENABLE_LOGGING_AND_PROFILING |
1095 // If the ticker is NULL, Logger::Setup has not been called yet. In | 1271 // If the ticker is NULL, Logger::Setup has not been called yet. In |
1096 // that case, we set the sliding_state_window flag so that the | 1272 // that case, we set the sliding_state_window flag so that the |
1097 // sliding window computation will be started when Logger::Setup is | 1273 // sliding window computation will be started when Logger::Setup is |
1098 // called. | 1274 // called. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 Heap::Unprotect(); | 1359 Heap::Unprotect(); |
1184 } else if (previous_->state_ == EXTERNAL) { | 1360 } else if (previous_->state_ == EXTERNAL) { |
1185 // We are leaving V8. | 1361 // We are leaving V8. |
1186 Heap::Protect(); | 1362 Heap::Protect(); |
1187 } | 1363 } |
1188 } | 1364 } |
1189 #endif | 1365 #endif |
1190 } | 1366 } |
1191 #endif | 1367 #endif |
1192 | 1368 |
1193 } } // namespace v8::internal | 1369 } // namespace internal |
| 1370 } // namespace v8 |
OLD | NEW |