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 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 | 1796 |
1797 Sampler* sampler_; | 1797 Sampler* sampler_; |
1798 HANDLE sampler_thread_; | 1798 HANDLE sampler_thread_; |
1799 HANDLE profiled_thread_; | 1799 HANDLE profiled_thread_; |
1800 | 1800 |
1801 // Sampler thread handler. | 1801 // Sampler thread handler. |
1802 void Runner() { | 1802 void Runner() { |
1803 // Context used for sampling the register state of the profiled thread. | 1803 // Context used for sampling the register state of the profiled thread. |
1804 CONTEXT context; | 1804 CONTEXT context; |
1805 memset(&context, 0, sizeof(context)); | 1805 memset(&context, 0, sizeof(context)); |
1806 // Loop until the sampler is disengaged. | 1806 // Loop until the sampler is disengaged, keeping the specified samling freq. |
1807 while (sampler_->IsActive()) { | 1807 for ( ; sampler_->IsActive(); Sleep(sampler_->interval_)) { |
1808 TickSample sample; | 1808 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
| 1809 if (Logger::state() == GC) continue; |
| 1810 |
| 1811 TickSample* sample = NULL; |
| 1812 #else |
| 1813 TickSample sample_obj, *sample = &sample_obj; |
1809 | 1814 |
1810 // We always sample the VM state. | 1815 // We always sample the VM state. |
1811 sample.state = Logger::state(); | 1816 sample->state = Logger::state(); |
| 1817 #endif // ENABLE_CPP_PROFILES_PROCESSOR |
1812 | 1818 |
1813 // If profiling, we record the pc and sp of the profiled thread. | 1819 // If profiling, we record the pc and sp of the profiled thread. |
1814 if (sampler_->IsProfiling() | 1820 if (sampler_->IsProfiling() |
1815 && SuspendThread(profiled_thread_) != (DWORD)-1) { | 1821 && SuspendThread(profiled_thread_) != (DWORD)-1) { |
1816 context.ContextFlags = CONTEXT_FULL; | 1822 context.ContextFlags = CONTEXT_FULL; |
1817 if (GetThreadContext(profiled_thread_, &context) != 0) { | 1823 if (GetThreadContext(profiled_thread_, &context) != 0) { |
| 1824 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
| 1825 sample = CpuProfiler::TickSampleEvent(); |
| 1826 #endif |
| 1827 if (sample != NULL) { |
1818 #if V8_HOST_ARCH_X64 | 1828 #if V8_HOST_ARCH_X64 |
1819 sample.pc = reinterpret_cast<Address>(context.Rip); | 1829 sample->pc = reinterpret_cast<Address>(context.Rip); |
1820 sample.sp = reinterpret_cast<Address>(context.Rsp); | 1830 sample->sp = reinterpret_cast<Address>(context.Rsp); |
1821 sample.fp = reinterpret_cast<Address>(context.Rbp); | 1831 sample->fp = reinterpret_cast<Address>(context.Rbp); |
1822 #else | 1832 #else |
1823 sample.pc = reinterpret_cast<Address>(context.Eip); | 1833 sample->pc = reinterpret_cast<Address>(context.Eip); |
1824 sample.sp = reinterpret_cast<Address>(context.Esp); | 1834 sample->sp = reinterpret_cast<Address>(context.Esp); |
1825 sample.fp = reinterpret_cast<Address>(context.Ebp); | 1835 sample->fp = reinterpret_cast<Address>(context.Ebp); |
1826 #endif | 1836 #endif |
1827 sampler_->SampleStack(&sample); | 1837 sampler_->SampleStack(sample); |
| 1838 } |
1828 } | 1839 } |
1829 ResumeThread(profiled_thread_); | 1840 ResumeThread(profiled_thread_); |
1830 } | 1841 } |
1831 | 1842 |
| 1843 #ifndef ENABLE_CPP_PROFILES_PROCESSOR |
1832 // Invoke tick handler with program counter and stack pointer. | 1844 // Invoke tick handler with program counter and stack pointer. |
1833 sampler_->Tick(&sample); | 1845 sampler_->Tick(sample); |
1834 | 1846 #endif |
1835 // Wait until next sampling. | |
1836 Sleep(sampler_->interval_); | |
1837 } | 1847 } |
1838 } | 1848 } |
1839 }; | 1849 }; |
1840 | 1850 |
1841 | 1851 |
1842 // Entry point for sampler thread. | 1852 // Entry point for sampler thread. |
1843 static unsigned int __stdcall SamplerEntry(void* arg) { | 1853 static unsigned int __stdcall SamplerEntry(void* arg) { |
1844 Sampler::PlatformData* data = | 1854 Sampler::PlatformData* data = |
1845 reinterpret_cast<Sampler::PlatformData*>(arg); | 1855 reinterpret_cast<Sampler::PlatformData*>(arg); |
1846 data->Runner(); | 1856 data->Runner(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 | 1910 |
1901 // Release the thread handles | 1911 // Release the thread handles |
1902 CloseHandle(data_->sampler_thread_); | 1912 CloseHandle(data_->sampler_thread_); |
1903 CloseHandle(data_->profiled_thread_); | 1913 CloseHandle(data_->profiled_thread_); |
1904 } | 1914 } |
1905 | 1915 |
1906 | 1916 |
1907 #endif // ENABLE_LOGGING_AND_PROFILING | 1917 #endif // ENABLE_LOGGING_AND_PROFILING |
1908 | 1918 |
1909 } } // namespace v8::internal | 1919 } } // namespace v8::internal |
OLD | NEW |