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 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, keeping the specified samling freq. | 1806 // Loop until the sampler is disengaged, keeping the specified samling freq. |
1807 for ( ; sampler_->IsActive(); Sleep(sampler_->interval_)) { | 1807 for ( ; sampler_->IsActive(); Sleep(sampler_->interval_)) { |
1808 #ifdef ENABLE_CPP_PROFILES_PROCESSOR | 1808 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
1809 if (Logger::state() == GC) continue; | 1809 TickSample* sample = CpuProfiler::TickSampleEvent(); |
1810 | 1810 if (sample == NULL) continue; |
1811 TickSample* sample = NULL; | 1811 sample->pc = NULL; // Impossible value if sampling succeeds. |
| 1812 sample->frames_count = 0; |
1812 #else | 1813 #else |
1813 TickSample sample_obj; | 1814 TickSample sample_obj; |
1814 TickSample* sample = &sample_obj; | 1815 TickSample* sample = &sample_obj; |
| 1816 #endif // ENABLE_CPP_PROFILES_PROCESSOR |
1815 | 1817 |
1816 // We always sample the VM state. | 1818 // We always sample the VM state. |
1817 sample->state = Logger::state(); | 1819 sample->state = Logger::state(); |
1818 #endif // ENABLE_CPP_PROFILES_PROCESSOR | |
1819 | |
1820 // If profiling, we record the pc and sp of the profiled thread. | 1820 // If profiling, we record the pc and sp of the profiled thread. |
1821 if (sampler_->IsProfiling() | 1821 if (sampler_->IsProfiling() |
1822 && SuspendThread(profiled_thread_) != (DWORD)-1) { | 1822 && SuspendThread(profiled_thread_) != (DWORD)-1) { |
1823 context.ContextFlags = CONTEXT_FULL; | 1823 context.ContextFlags = CONTEXT_FULL; |
1824 if (GetThreadContext(profiled_thread_, &context) != 0) { | 1824 if (GetThreadContext(profiled_thread_, &context) != 0) { |
1825 #ifdef ENABLE_CPP_PROFILES_PROCESSOR | 1825 #if V8_HOST_ARCH_X64 |
1826 sample = CpuProfiler::TickSampleEvent(); | 1826 sample->pc = reinterpret_cast<Address>(context.Rip); |
| 1827 sample->sp = reinterpret_cast<Address>(context.Rsp); |
| 1828 sample->fp = reinterpret_cast<Address>(context.Rbp); |
| 1829 #else |
| 1830 sample->pc = reinterpret_cast<Address>(context.Eip); |
| 1831 sample->sp = reinterpret_cast<Address>(context.Esp); |
| 1832 sample->fp = reinterpret_cast<Address>(context.Ebp); |
1827 #endif | 1833 #endif |
1828 if (sample != NULL) { | 1834 sampler_->SampleStack(sample); |
1829 #if V8_HOST_ARCH_X64 | |
1830 sample->pc = reinterpret_cast<Address>(context.Rip); | |
1831 sample->sp = reinterpret_cast<Address>(context.Rsp); | |
1832 sample->fp = reinterpret_cast<Address>(context.Rbp); | |
1833 #else | |
1834 sample->pc = reinterpret_cast<Address>(context.Eip); | |
1835 sample->sp = reinterpret_cast<Address>(context.Esp); | |
1836 sample->fp = reinterpret_cast<Address>(context.Ebp); | |
1837 #endif | |
1838 sampler_->SampleStack(sample); | |
1839 } | |
1840 } | 1835 } |
1841 ResumeThread(profiled_thread_); | 1836 ResumeThread(profiled_thread_); |
1842 } | 1837 } |
1843 | 1838 |
1844 #ifndef ENABLE_CPP_PROFILES_PROCESSOR | 1839 #ifndef ENABLE_CPP_PROFILES_PROCESSOR |
1845 // Invoke tick handler with program counter and stack pointer. | 1840 // Invoke tick handler with program counter and stack pointer. |
1846 sampler_->Tick(sample); | 1841 sampler_->Tick(sample); |
1847 #endif | 1842 #endif |
1848 } | 1843 } |
1849 } | 1844 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1911 | 1906 |
1912 // Release the thread handles | 1907 // Release the thread handles |
1913 CloseHandle(data_->sampler_thread_); | 1908 CloseHandle(data_->sampler_thread_); |
1914 CloseHandle(data_->profiled_thread_); | 1909 CloseHandle(data_->profiled_thread_); |
1915 } | 1910 } |
1916 | 1911 |
1917 | 1912 |
1918 #endif // ENABLE_LOGGING_AND_PROFILING | 1913 #endif // ENABLE_LOGGING_AND_PROFILING |
1919 | 1914 |
1920 } } // namespace v8::internal | 1915 } } // namespace v8::internal |
OLD | NEW |