| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/log.h" | 5 #include "src/log.h" |
| 6 | 6 |
| 7 #include <cstdarg> | 7 #include <cstdarg> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "src/v8.h" | 10 #include "src/v8.h" |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 public: | 600 public: |
| 601 explicit Profiler(Isolate* isolate); | 601 explicit Profiler(Isolate* isolate); |
| 602 void Engage(); | 602 void Engage(); |
| 603 void Disengage(); | 603 void Disengage(); |
| 604 | 604 |
| 605 // Inserts collected profiling data into buffer. | 605 // Inserts collected profiling data into buffer. |
| 606 void Insert(TickSample* sample) { | 606 void Insert(TickSample* sample) { |
| 607 if (paused_) | 607 if (paused_) |
| 608 return; | 608 return; |
| 609 | 609 |
| 610 if (Succ(head_) == tail_) { | 610 if (Succ(head_) == static_cast<int>(base::NoBarrier_Load(&tail_))) { |
| 611 overflow_ = true; | 611 overflow_ = true; |
| 612 } else { | 612 } else { |
| 613 buffer_[head_] = *sample; | 613 buffer_[head_] = *sample; |
| 614 head_ = Succ(head_); | 614 head_ = Succ(head_); |
| 615 buffer_semaphore_.Signal(); // Tell we have an element. | 615 buffer_semaphore_.Signal(); // Tell we have an element. |
| 616 } | 616 } |
| 617 } | 617 } |
| 618 | 618 |
| 619 virtual void Run(); | 619 virtual void Run(); |
| 620 | 620 |
| 621 // Pause and Resume TickSample data collection. | 621 // Pause and Resume TickSample data collection. |
| 622 void pause() { paused_ = true; } | 622 void pause() { paused_ = true; } |
| 623 void resume() { paused_ = false; } | 623 void resume() { paused_ = false; } |
| 624 | 624 |
| 625 private: | 625 private: |
| 626 // Waits for a signal and removes profiling data. | 626 // Waits for a signal and removes profiling data. |
| 627 bool Remove(TickSample* sample) { | 627 bool Remove(TickSample* sample) { |
| 628 buffer_semaphore_.Wait(); // Wait for an element. | 628 buffer_semaphore_.Wait(); // Wait for an element. |
| 629 *sample = buffer_[tail_]; | 629 *sample = buffer_[base::NoBarrier_Load(&tail_)]; |
| 630 bool result = overflow_; | 630 bool result = overflow_; |
| 631 tail_ = Succ(tail_); | 631 base::NoBarrier_Store(&tail_, static_cast<base::Atomic32>( |
| 632 Succ(base::NoBarrier_Load(&tail_)))); |
| 632 overflow_ = false; | 633 overflow_ = false; |
| 633 return result; | 634 return result; |
| 634 } | 635 } |
| 635 | 636 |
| 636 // Returns the next index in the cyclic buffer. | 637 // Returns the next index in the cyclic buffer. |
| 637 int Succ(int index) { return (index + 1) % kBufferSize; } | 638 int Succ(int index) { return (index + 1) % kBufferSize; } |
| 638 | 639 |
| 639 Isolate* isolate_; | 640 Isolate* isolate_; |
| 640 // Cyclic buffer for communicating profiling samples | 641 // Cyclic buffer for communicating profiling samples |
| 641 // between the signal handler and the worker thread. | 642 // between the signal handler and the worker thread. |
| 642 static const int kBufferSize = 128; | 643 static const int kBufferSize = 128; |
| 643 TickSample buffer_[kBufferSize]; // Buffer storage. | 644 TickSample buffer_[kBufferSize]; // Buffer storage. |
| 644 int head_; // Index to the buffer head. | 645 int head_; // Index to the buffer head. |
| 645 int tail_; // Index to the buffer tail. | 646 base::Atomic32 tail_; // Index to the buffer tail. |
| 646 bool overflow_; // Tell whether a buffer overflow has occurred. | 647 bool overflow_; // Tell whether a buffer overflow has occurred. |
| 647 // Sempahore used for buffer synchronization. | 648 // Sempahore used for buffer synchronization. |
| 648 base::Semaphore buffer_semaphore_; | 649 base::Semaphore buffer_semaphore_; |
| 649 | 650 |
| 650 // Tells whether profiler is engaged, that is, processing thread is stated. | 651 // Tells whether profiler is engaged, that is, processing thread is stated. |
| 651 bool engaged_; | 652 bool engaged_; |
| 652 | 653 |
| 653 // Tells whether worker thread should continue running. | 654 // Tells whether worker thread should continue running. |
| 654 bool running_; | 655 bool running_; |
| 655 | 656 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 }; | 693 }; |
| 693 | 694 |
| 694 | 695 |
| 695 // | 696 // |
| 696 // Profiler implementation. | 697 // Profiler implementation. |
| 697 // | 698 // |
| 698 Profiler::Profiler(Isolate* isolate) | 699 Profiler::Profiler(Isolate* isolate) |
| 699 : base::Thread(Options("v8:Profiler")), | 700 : base::Thread(Options("v8:Profiler")), |
| 700 isolate_(isolate), | 701 isolate_(isolate), |
| 701 head_(0), | 702 head_(0), |
| 702 tail_(0), | |
| 703 overflow_(false), | 703 overflow_(false), |
| 704 buffer_semaphore_(0), | 704 buffer_semaphore_(0), |
| 705 engaged_(false), | 705 engaged_(false), |
| 706 running_(false), | 706 running_(false), |
| 707 paused_(false) {} | 707 paused_(false) { |
| 708 base::NoBarrier_Store(&tail_, 0); |
| 709 } |
| 708 | 710 |
| 709 | 711 |
| 710 void Profiler::Engage() { | 712 void Profiler::Engage() { |
| 711 if (engaged_) return; | 713 if (engaged_) return; |
| 712 engaged_ = true; | 714 engaged_ = true; |
| 713 | 715 |
| 714 std::vector<base::OS::SharedLibraryAddress> addresses = | 716 std::vector<base::OS::SharedLibraryAddress> addresses = |
| 715 base::OS::GetSharedLibraryAddresses(); | 717 base::OS::GetSharedLibraryAddresses(); |
| 716 for (size_t i = 0; i < addresses.size(); ++i) { | 718 for (size_t i = 0; i < addresses.size(); ++i) { |
| 717 LOG(isolate_, SharedLibraryEvent( | 719 LOG(isolate_, SharedLibraryEvent( |
| (...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1936 if (jit_logger_) { | 1938 if (jit_logger_) { |
| 1937 removeCodeEventListener(jit_logger_); | 1939 removeCodeEventListener(jit_logger_); |
| 1938 delete jit_logger_; | 1940 delete jit_logger_; |
| 1939 jit_logger_ = NULL; | 1941 jit_logger_ = NULL; |
| 1940 } | 1942 } |
| 1941 | 1943 |
| 1942 return log_->Close(); | 1944 return log_->Close(); |
| 1943 } | 1945 } |
| 1944 | 1946 |
| 1945 } } // namespace v8::internal | 1947 } } // namespace v8::internal |
| OLD | NEW |