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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 // Inserts collected profiling data into buffer. | 549 // Inserts collected profiling data into buffer. |
550 void Insert(TickSample* sample) { | 550 void Insert(TickSample* sample) { |
551 if (paused_) | 551 if (paused_) |
552 return; | 552 return; |
553 | 553 |
554 if (Succ(head_) == tail_) { | 554 if (Succ(head_) == tail_) { |
555 overflow_ = true; | 555 overflow_ = true; |
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 void pause() { paused_ = true; } | 566 void pause() { paused_ = true; } |
567 void resume() { paused_ = false; } | 567 void resume() { paused_ = false; } |
568 | 568 |
569 private: | 569 private: |
570 // Waits for a signal and removes profiling data. | 570 // Waits for a signal and removes profiling data. |
571 bool Remove(TickSample* sample) { | 571 bool Remove(TickSample* sample) { |
572 buffer_semaphore_->Wait(); // Wait for an element. | 572 buffer_semaphore_.Wait(); // Wait for an element. |
573 *sample = buffer_[tail_]; | 573 *sample = buffer_[tail_]; |
574 bool result = overflow_; | 574 bool result = overflow_; |
575 tail_ = Succ(tail_); | 575 tail_ = Succ(tail_); |
576 overflow_ = false; | 576 overflow_ = false; |
577 return result; | 577 return result; |
578 } | 578 } |
579 | 579 |
580 // Returns the next index in the cyclic buffer. | 580 // Returns the next index in the cyclic buffer. |
581 int Succ(int index) { return (index + 1) % kBufferSize; } | 581 int Succ(int index) { return (index + 1) % kBufferSize; } |
582 | 582 |
583 Isolate* isolate_; | 583 Isolate* isolate_; |
584 // Cyclic buffer for communicating profiling samples | 584 // Cyclic buffer for communicating profiling samples |
585 // between the signal handler and the worker thread. | 585 // between the signal handler and the worker thread. |
586 static const int kBufferSize = 128; | 586 static const int kBufferSize = 128; |
587 TickSample buffer_[kBufferSize]; // Buffer storage. | 587 TickSample buffer_[kBufferSize]; // Buffer storage. |
588 int head_; // Index to the buffer head. | 588 int head_; // Index to the buffer head. |
589 int tail_; // Index to the buffer tail. | 589 int tail_; // Index to the buffer tail. |
590 bool overflow_; // Tell whether a buffer overflow has occurred. | 590 bool overflow_; // Tell whether a buffer overflow has occurred. |
591 // Sempahore used for buffer synchronization. | 591 // Sempahore used for buffer synchronization. |
592 SmartPointer<Semaphore> buffer_semaphore_; | 592 Semaphore buffer_semaphore_; |
593 | 593 |
594 // Tells whether profiler is engaged, that is, processing thread is stated. | 594 // Tells whether profiler is engaged, that is, processing thread is stated. |
595 bool engaged_; | 595 bool engaged_; |
596 | 596 |
597 // Tells whether worker thread should continue running. | 597 // Tells whether worker thread should continue running. |
598 bool running_; | 598 bool running_; |
599 | 599 |
600 // Tells whether we are currently recording tick samples. | 600 // Tells whether we are currently recording tick samples. |
601 bool paused_; | 601 bool paused_; |
602 }; | 602 }; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 | 638 |
639 // | 639 // |
640 // Profiler implementation. | 640 // Profiler implementation. |
641 // | 641 // |
642 Profiler::Profiler(Isolate* isolate) | 642 Profiler::Profiler(Isolate* isolate) |
643 : Thread("v8:Profiler"), | 643 : Thread("v8:Profiler"), |
644 isolate_(isolate), | 644 isolate_(isolate), |
645 head_(0), | 645 head_(0), |
646 tail_(0), | 646 tail_(0), |
647 overflow_(false), | 647 overflow_(false), |
648 buffer_semaphore_(OS::CreateSemaphore(0)), | 648 buffer_semaphore_(0), |
649 engaged_(false), | 649 engaged_(false), |
650 running_(false), | 650 running_(false), |
651 paused_(false) { | 651 paused_(false) { |
652 } | 652 } |
653 | 653 |
654 | 654 |
655 void Profiler::Engage() { | 655 void Profiler::Engage() { |
656 if (engaged_) return; | 656 if (engaged_) return; |
657 engaged_ = true; | 657 engaged_ = true; |
658 | 658 |
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1906 if (jit_logger_) { | 1906 if (jit_logger_) { |
1907 removeCodeEventListener(jit_logger_); | 1907 removeCodeEventListener(jit_logger_); |
1908 delete jit_logger_; | 1908 delete jit_logger_; |
1909 jit_logger_ = NULL; | 1909 jit_logger_ = NULL; |
1910 } | 1910 } |
1911 | 1911 |
1912 return log_->Close(); | 1912 return log_->Close(); |
1913 } | 1913 } |
1914 | 1914 |
1915 } } // namespace v8::internal | 1915 } } // namespace v8::internal |
OLD | NEW |