| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 vm_tid_(syscall(SYS_gettid)), | 821 vm_tid_(syscall(SYS_gettid)), |
| 822 signal_sender_launched_(false) { | 822 signal_sender_launched_(false) { |
| 823 } | 823 } |
| 824 | 824 |
| 825 void SignalSender() { | 825 void SignalSender() { |
| 826 while (sampler_->IsActive()) { | 826 while (sampler_->IsActive()) { |
| 827 // Glibc doesn't provide a wrapper for tgkill(2). | 827 // Glibc doesn't provide a wrapper for tgkill(2). |
| 828 syscall(SYS_tgkill, vm_tgid_, vm_tid_, SIGPROF); | 828 syscall(SYS_tgkill, vm_tgid_, vm_tid_, SIGPROF); |
| 829 // Convert ms to us and subtract 100 us to compensate delays | 829 // Convert ms to us and subtract 100 us to compensate delays |
| 830 // occuring during signal delivery. | 830 // occuring during signal delivery. |
| 831 int result = usleep(sampler_->interval_ * 1000 - 100); | 831 const useconds_t interval = sampler_->interval_ * 1000 - 100; |
| 832 ASSERT(result == 0 || errno == EINTR); | 832 int result = usleep(interval); |
| 833 #ifdef DEBUG |
| 834 if (result != 0 && errno != EINTR) { |
| 835 fprintf(stderr, |
| 836 "SignalSender usleep error; interval = %u, errno = %d\n", |
| 837 interval, |
| 838 errno); |
| 839 ASSERT(result == 0 || errno == EINTR); |
| 840 } |
| 841 #endif |
| 833 USE(result); | 842 USE(result); |
| 834 } | 843 } |
| 835 } | 844 } |
| 836 | 845 |
| 837 Sampler* sampler_; | 846 Sampler* sampler_; |
| 838 bool signal_handler_installed_; | 847 bool signal_handler_installed_; |
| 839 struct sigaction old_signal_handler_; | 848 struct sigaction old_signal_handler_; |
| 840 int vm_tgid_; | 849 int vm_tgid_; |
| 841 int vm_tid_; | 850 int vm_tid_; |
| 842 bool signal_sender_launched_; | 851 bool signal_sender_launched_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 855 Sampler::Sampler(int interval, bool profiling) | 864 Sampler::Sampler(int interval, bool profiling) |
| 856 : interval_(interval), | 865 : interval_(interval), |
| 857 profiling_(profiling), | 866 profiling_(profiling), |
| 858 synchronous_(profiling), | 867 synchronous_(profiling), |
| 859 active_(false) { | 868 active_(false) { |
| 860 data_ = new PlatformData(this); | 869 data_ = new PlatformData(this); |
| 861 } | 870 } |
| 862 | 871 |
| 863 | 872 |
| 864 Sampler::~Sampler() { | 873 Sampler::~Sampler() { |
| 874 ASSERT(!data_->signal_sender_launched_); |
| 865 delete data_; | 875 delete data_; |
| 866 } | 876 } |
| 867 | 877 |
| 868 | 878 |
| 869 void Sampler::Start() { | 879 void Sampler::Start() { |
| 870 // There can only be one active sampler at the time on POSIX | 880 // There can only be one active sampler at the time on POSIX |
| 871 // platforms. | 881 // platforms. |
| 872 if (active_sampler_ != NULL) return; | 882 if (active_sampler_ != NULL) return; |
| 873 | 883 |
| 874 // Request profiling signals. | 884 // Request profiling signals. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 } | 920 } |
| 911 | 921 |
| 912 // This sampler is no longer the active sampler. | 922 // This sampler is no longer the active sampler. |
| 913 active_sampler_ = NULL; | 923 active_sampler_ = NULL; |
| 914 } | 924 } |
| 915 | 925 |
| 916 | 926 |
| 917 #endif // ENABLE_LOGGING_AND_PROFILING | 927 #endif // ENABLE_LOGGING_AND_PROFILING |
| 918 | 928 |
| 919 } } // namespace v8::internal | 929 } } // namespace v8::internal |
| OLD | NEW |