Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: src/platform-win32.cc

Issue 1635005: Allow new CPU profiling subsystem to coexist nicely with the old one. (Closed)
Patch Set: Fix TickSampleEvent Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, 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 TickSample sample_obj;
1809 TickSample* sample = NULL;
1808 #ifdef ENABLE_CPP_PROFILES_PROCESSOR 1810 #ifdef ENABLE_CPP_PROFILES_PROCESSOR
1809 TickSample* sample = CpuProfiler::TickSampleEvent(); 1811 sample = CpuProfiler::TickSampleEvent();
1810 if (sample == NULL) continue; 1812 #endif
1811 sample->pc = NULL; // Impossible value if sampling succeeds. 1813 if (sample == NULL) sample = &sample_obj;
1812 sample->frames_count = 0;
1813 #else
1814 TickSample sample_obj;
1815 TickSample* sample = &sample_obj;
1816 #endif // ENABLE_CPP_PROFILES_PROCESSOR
1817 1814
1818 // We always sample the VM state. 1815 // We always sample the VM state.
1819 sample->state = VMState::current_state(); 1816 sample->state = VMState::current_state();
1820 // If profiling, we record the pc and sp of the profiled thread. 1817 // If profiling, we record the pc and sp of the profiled thread.
1821 if (sampler_->IsProfiling() 1818 if (sampler_->IsProfiling()
1822 && SuspendThread(profiled_thread_) != (DWORD)-1) { 1819 && SuspendThread(profiled_thread_) != (DWORD)-1) {
1823 context.ContextFlags = CONTEXT_FULL; 1820 context.ContextFlags = CONTEXT_FULL;
1824 if (GetThreadContext(profiled_thread_, &context) != 0) { 1821 if (GetThreadContext(profiled_thread_, &context) != 0) {
1825 #if V8_HOST_ARCH_X64 1822 #if V8_HOST_ARCH_X64
1826 sample->pc = reinterpret_cast<Address>(context.Rip); 1823 sample->pc = reinterpret_cast<Address>(context.Rip);
1827 sample->sp = reinterpret_cast<Address>(context.Rsp); 1824 sample->sp = reinterpret_cast<Address>(context.Rsp);
1828 sample->fp = reinterpret_cast<Address>(context.Rbp); 1825 sample->fp = reinterpret_cast<Address>(context.Rbp);
1829 #else 1826 #else
1830 sample->pc = reinterpret_cast<Address>(context.Eip); 1827 sample->pc = reinterpret_cast<Address>(context.Eip);
1831 sample->sp = reinterpret_cast<Address>(context.Esp); 1828 sample->sp = reinterpret_cast<Address>(context.Esp);
1832 sample->fp = reinterpret_cast<Address>(context.Ebp); 1829 sample->fp = reinterpret_cast<Address>(context.Ebp);
1833 #endif 1830 #endif
1834 sampler_->SampleStack(sample); 1831 sampler_->SampleStack(sample);
1835 } 1832 }
1836 ResumeThread(profiled_thread_); 1833 ResumeThread(profiled_thread_);
1837 } 1834 }
1838 1835
1839 #ifndef ENABLE_CPP_PROFILES_PROCESSOR
1840 // Invoke tick handler with program counter and stack pointer. 1836 // Invoke tick handler with program counter and stack pointer.
1841 sampler_->Tick(sample); 1837 sampler_->Tick(sample);
1842 #endif
1843 } 1838 }
1844 } 1839 }
1845 }; 1840 };
1846 1841
1847 1842
1848 // Entry point for sampler thread. 1843 // Entry point for sampler thread.
1849 static unsigned int __stdcall SamplerEntry(void* arg) { 1844 static unsigned int __stdcall SamplerEntry(void* arg) {
1850 Sampler::PlatformData* data = 1845 Sampler::PlatformData* data =
1851 reinterpret_cast<Sampler::PlatformData*>(arg); 1846 reinterpret_cast<Sampler::PlatformData*>(arg);
1852 data->Runner(); 1847 data->Runner();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 1901
1907 // Release the thread handles 1902 // Release the thread handles
1908 CloseHandle(data_->sampler_thread_); 1903 CloseHandle(data_->sampler_thread_);
1909 CloseHandle(data_->profiled_thread_); 1904 CloseHandle(data_->profiled_thread_);
1910 } 1905 }
1911 1906
1912 1907
1913 #endif // ENABLE_LOGGING_AND_PROFILING 1908 #endif // ENABLE_LOGGING_AND_PROFILING
1914 1909
1915 } } // namespace v8::internal 1910 } } // namespace v8::internal
OLDNEW
« src/cpu-profiler-inl.h ('K') | « src/platform-macos.cc ('k') | src/v8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698