OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 } else { | 556 } else { |
557 buffer_[head_] = *sample; | 557 buffer_[head_] = *sample; |
558 head_ = Succ(head_); | 558 head_ = Succ(head_); |
559 buffer_semaphore_->Signal(); // Tell we have an element. | 559 buffer_semaphore_->Signal(); // Tell we have an element. |
560 } | 560 } |
561 } | 561 } |
562 | 562 |
563 virtual void Run(); | 563 virtual void Run(); |
564 | 564 |
565 // Pause and Resume TickSample data collection. | 565 // Pause and Resume TickSample data collection. |
566 bool paused() const { return paused_; } | |
567 void pause() { paused_ = true; } | 566 void pause() { paused_ = true; } |
568 void resume() { paused_ = false; } | 567 void resume() { paused_ = false; } |
569 | 568 |
570 private: | 569 private: |
571 // Waits for a signal and removes profiling data. | 570 // Waits for a signal and removes profiling data. |
572 bool Remove(TickSample* sample) { | 571 bool Remove(TickSample* sample) { |
573 buffer_semaphore_->Wait(); // Wait for an element. | 572 buffer_semaphore_->Wait(); // Wait for an element. |
574 *sample = buffer_[tail_]; | 573 *sample = buffer_[tail_]; |
575 bool result = overflow_; | 574 bool result = overflow_; |
576 tail_ = Succ(tail_); | 575 tail_ = Succ(tail_); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 ~Ticker() { if (IsActive()) Stop(); } | 615 ~Ticker() { if (IsActive()) Stop(); } |
617 | 616 |
618 virtual void Tick(TickSample* sample) { | 617 virtual void Tick(TickSample* sample) { |
619 if (profiler_) profiler_->Insert(sample); | 618 if (profiler_) profiler_->Insert(sample); |
620 } | 619 } |
621 | 620 |
622 void SetProfiler(Profiler* profiler) { | 621 void SetProfiler(Profiler* profiler) { |
623 ASSERT(profiler_ == NULL); | 622 ASSERT(profiler_ == NULL); |
624 profiler_ = profiler; | 623 profiler_ = profiler; |
625 IncreaseProfilingDepth(); | 624 IncreaseProfilingDepth(); |
626 if (!FLAG_prof_lazy && !IsActive()) Start(); | 625 if (!IsActive()) Start(); |
627 } | 626 } |
628 | 627 |
629 void ClearProfiler() { | 628 void ClearProfiler() { |
630 DecreaseProfilingDepth(); | 629 DecreaseProfilingDepth(); |
631 profiler_ = NULL; | 630 profiler_ = NULL; |
632 if (IsActive()) Stop(); | 631 if (IsActive()) Stop(); |
633 } | 632 } |
634 | 633 |
635 private: | 634 private: |
636 Profiler* profiler_; | 635 Profiler* profiler_; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 | 702 |
704 // | 703 // |
705 // Logger class implementation. | 704 // Logger class implementation. |
706 // | 705 // |
707 | 706 |
708 Logger::Logger(Isolate* isolate) | 707 Logger::Logger(Isolate* isolate) |
709 : isolate_(isolate), | 708 : isolate_(isolate), |
710 ticker_(NULL), | 709 ticker_(NULL), |
711 profiler_(NULL), | 710 profiler_(NULL), |
712 log_events_(NULL), | 711 log_events_(NULL), |
713 logging_nesting_(0), | 712 is_logging_(false), |
714 cpu_profiler_nesting_(0), | |
715 log_(new Log(this)), | 713 log_(new Log(this)), |
716 ll_logger_(NULL), | 714 ll_logger_(NULL), |
717 jit_logger_(NULL), | 715 jit_logger_(NULL), |
718 listeners_(5), | 716 listeners_(5), |
719 is_initialized_(false), | 717 is_initialized_(false), |
720 epoch_(0) { | 718 epoch_(0) { |
721 } | 719 } |
722 | 720 |
723 | 721 |
724 Logger::~Logger() { | 722 Logger::~Logger() { |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 } | 1513 } |
1516 for (int i = 0; i < sample->frames_count; ++i) { | 1514 for (int i = 0; i < sample->frames_count; ++i) { |
1517 msg.Append(','); | 1515 msg.Append(','); |
1518 msg.AppendAddress(sample->stack[i]); | 1516 msg.AppendAddress(sample->stack[i]); |
1519 } | 1517 } |
1520 msg.Append('\n'); | 1518 msg.Append('\n'); |
1521 msg.WriteToLogFile(); | 1519 msg.WriteToLogFile(); |
1522 } | 1520 } |
1523 | 1521 |
1524 | 1522 |
1525 bool Logger::IsProfilerPaused() { | 1523 void Logger::StopProfiler() { |
1526 return profiler_ == NULL || profiler_->paused(); | |
1527 } | |
1528 | |
1529 | |
1530 void Logger::PauseProfiler() { | |
1531 if (!log_->IsEnabled()) return; | 1524 if (!log_->IsEnabled()) return; |
1532 if (profiler_ != NULL) { | 1525 if (profiler_ != NULL) { |
1533 // It is OK to have negative nesting. | 1526 profiler_->pause(); |
1534 if (--cpu_profiler_nesting_ == 0) { | 1527 is_logging_ = false; |
1535 profiler_->pause(); | |
1536 if (FLAG_prof_lazy) { | |
1537 ticker_->Stop(); | |
1538 FLAG_log_code = false; | |
1539 LOG(ISOLATE, UncheckedStringEvent("profiler", "pause")); | |
1540 } | |
1541 --logging_nesting_; | |
1542 } | |
1543 } | 1528 } |
1544 } | 1529 } |
1545 | 1530 |
1546 | |
1547 void Logger::ResumeProfiler() { | |
1548 if (!log_->IsEnabled()) return; | |
1549 if (profiler_ != NULL) { | |
1550 if (cpu_profiler_nesting_++ == 0) { | |
1551 ++logging_nesting_; | |
1552 if (FLAG_prof_lazy) { | |
1553 profiler_->Engage(); | |
1554 LOG(ISOLATE, UncheckedStringEvent("profiler", "resume")); | |
1555 FLAG_log_code = true; | |
1556 LogCompiledFunctions(); | |
1557 LogAccessorCallbacks(); | |
1558 if (!ticker_->IsActive()) ticker_->Start(); | |
1559 } | |
1560 profiler_->resume(); | |
1561 } | |
1562 } | |
1563 } | |
1564 | |
1565 | 1531 |
1566 // This function can be called when Log's mutex is acquired, | 1532 // This function can be called when Log's mutex is acquired, |
1567 // either from main or Profiler's thread. | 1533 // either from main or Profiler's thread. |
1568 void Logger::LogFailure() { | 1534 void Logger::LogFailure() { |
1569 PauseProfiler(); | 1535 StopProfiler(); |
1570 } | 1536 } |
1571 | 1537 |
1572 | 1538 |
1573 class EnumerateOptimizedFunctionsVisitor: public OptimizedFunctionVisitor { | 1539 class EnumerateOptimizedFunctionsVisitor: public OptimizedFunctionVisitor { |
1574 public: | 1540 public: |
1575 EnumerateOptimizedFunctionsVisitor(Handle<SharedFunctionInfo>* sfis, | 1541 EnumerateOptimizedFunctionsVisitor(Handle<SharedFunctionInfo>* sfis, |
1576 Handle<Code>* code_objects, | 1542 Handle<Code>* code_objects, |
1577 int* count) | 1543 int* count) |
1578 : sfis_(sfis), code_objects_(code_objects), count_(count) { } | 1544 : sfis_(sfis), code_objects_(code_objects), count_(count) { } |
1579 | 1545 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 bool Logger::SetUp(Isolate* isolate) { | 1825 bool Logger::SetUp(Isolate* isolate) { |
1860 // Tests and EnsureInitialize() can call this twice in a row. It's harmless. | 1826 // Tests and EnsureInitialize() can call this twice in a row. It's harmless. |
1861 if (is_initialized_) return true; | 1827 if (is_initialized_) return true; |
1862 is_initialized_ = true; | 1828 is_initialized_ = true; |
1863 | 1829 |
1864 // --ll-prof implies --log-code and --log-snapshot-positions. | 1830 // --ll-prof implies --log-code and --log-snapshot-positions. |
1865 if (FLAG_ll_prof) { | 1831 if (FLAG_ll_prof) { |
1866 FLAG_log_snapshot_positions = true; | 1832 FLAG_log_snapshot_positions = true; |
1867 } | 1833 } |
1868 | 1834 |
1869 // --prof_lazy controls --log-code. | |
1870 if (FLAG_prof_lazy) { | |
1871 FLAG_log_code = false; | |
1872 } | |
1873 | |
1874 SmartArrayPointer<const char> log_file_name = | 1835 SmartArrayPointer<const char> log_file_name = |
1875 PrepareLogFileName(FLAG_logfile); | 1836 PrepareLogFileName(FLAG_logfile); |
1876 log_->Initialize(*log_file_name); | 1837 log_->Initialize(*log_file_name); |
1877 | 1838 |
1878 if (FLAG_ll_prof) { | 1839 if (FLAG_ll_prof) { |
1879 ll_logger_ = new LowLevelLogger(*log_file_name); | 1840 ll_logger_ = new LowLevelLogger(*log_file_name); |
1880 addCodeEventListener(ll_logger_); | 1841 addCodeEventListener(ll_logger_); |
1881 } | 1842 } |
1882 | 1843 |
1883 ticker_ = new Ticker(isolate, kSamplingIntervalMs); | 1844 ticker_ = new Ticker(isolate, kSamplingIntervalMs); |
1884 | 1845 |
1885 if (Log::InitLogAtStart()) { | 1846 if (Log::InitLogAtStart()) { |
1886 logging_nesting_ = 1; | 1847 is_logging_ = true; |
1887 } | 1848 } |
1888 | 1849 |
1889 if (FLAG_prof) { | 1850 if (FLAG_prof) { |
1890 profiler_ = new Profiler(isolate); | 1851 profiler_ = new Profiler(isolate); |
1891 if (FLAG_prof_lazy) { | 1852 is_logging_ = true; |
1892 profiler_->pause(); | 1853 profiler_->Engage(); |
1893 } else { | |
1894 logging_nesting_ = 1; | |
1895 profiler_->Engage(); | |
1896 } | |
1897 } | 1854 } |
1898 | 1855 |
1899 if (FLAG_log_internal_timer_events || FLAG_prof) epoch_ = OS::Ticks(); | 1856 if (FLAG_log_internal_timer_events || FLAG_prof) epoch_ = OS::Ticks(); |
1900 | 1857 |
1901 return true; | 1858 return true; |
1902 } | 1859 } |
1903 | 1860 |
1904 | 1861 |
1905 void Logger::SetCodeEventHandler(uint32_t options, | 1862 void Logger::SetCodeEventHandler(uint32_t options, |
1906 JitCodeEventHandler event_handler) { | 1863 JitCodeEventHandler event_handler) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 if (jit_logger_) { | 1907 if (jit_logger_) { |
1951 removeCodeEventListener(jit_logger_); | 1908 removeCodeEventListener(jit_logger_); |
1952 delete jit_logger_; | 1909 delete jit_logger_; |
1953 jit_logger_ = NULL; | 1910 jit_logger_ = NULL; |
1954 } | 1911 } |
1955 | 1912 |
1956 return log_->Close(); | 1913 return log_->Close(); |
1957 } | 1914 } |
1958 | 1915 |
1959 } } // namespace v8::internal | 1916 } } // namespace v8::internal |
OLD | NEW |