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 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 delete data_; | 1810 delete data_; |
1811 } | 1811 } |
1812 | 1812 |
1813 | 1813 |
1814 // Start profiling. | 1814 // Start profiling. |
1815 void Sampler::Start() { | 1815 void Sampler::Start() { |
1816 // If we are profiling, we need to be able to access the calling | 1816 // If we are profiling, we need to be able to access the calling |
1817 // thread. | 1817 // thread. |
1818 if (IsProfiling()) { | 1818 if (IsProfiling()) { |
1819 // Get a handle to the calling thread. This is the thread that we are | 1819 // Get a handle to the calling thread. This is the thread that we are |
1820 // going to profile. We need to duplicate the handle because we are | 1820 // going to profile. We need to make a copy of the handle because we are |
1821 // going to use it in the sampler thread. using GetThreadHandle() will | 1821 // going to use it in the sampler thread. Using GetThreadHandle() will |
1822 // not work in this case. | 1822 // not work in this case. We're using OpenThread because DuplicateHandle |
1823 BOOL ok = DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), | 1823 // for some reason doesn't work in Chrome's sandbox. |
1824 GetCurrentProcess(), &data_->profiled_thread_, | 1824 data_->profiled_thread_ = OpenThread(THREAD_GET_CONTEXT | |
1825 THREAD_GET_CONTEXT | THREAD_SUSPEND_RESUME | | 1825 THREAD_SUSPEND_RESUME | |
1826 THREAD_QUERY_INFORMATION, FALSE, 0); | 1826 THREAD_QUERY_INFORMATION, |
| 1827 FALSE, |
| 1828 GetCurrentThreadId()); |
| 1829 BOOL ok = data_->profiled_thread_ != NULL; |
1827 if (!ok) return; | 1830 if (!ok) return; |
1828 } | 1831 } |
1829 | 1832 |
1830 // Start sampler thread. | 1833 // Start sampler thread. |
1831 unsigned int tid; | 1834 unsigned int tid; |
1832 active_ = true; | 1835 active_ = true; |
1833 data_->sampler_thread_ = reinterpret_cast<HANDLE>( | 1836 data_->sampler_thread_ = reinterpret_cast<HANDLE>( |
1834 _beginthreadex(NULL, 0, SamplerEntry, data_, 0, &tid)); | 1837 _beginthreadex(NULL, 0, SamplerEntry, data_, 0, &tid)); |
1835 // Set thread to high priority to increase sampling accuracy. | 1838 // Set thread to high priority to increase sampling accuracy. |
1836 SetThreadPriority(data_->sampler_thread_, THREAD_PRIORITY_TIME_CRITICAL); | 1839 SetThreadPriority(data_->sampler_thread_, THREAD_PRIORITY_TIME_CRITICAL); |
(...skipping 11 matching lines...) Expand all Loading... |
1848 | 1851 |
1849 // Release the thread handles | 1852 // Release the thread handles |
1850 CloseHandle(data_->sampler_thread_); | 1853 CloseHandle(data_->sampler_thread_); |
1851 CloseHandle(data_->profiled_thread_); | 1854 CloseHandle(data_->profiled_thread_); |
1852 } | 1855 } |
1853 | 1856 |
1854 | 1857 |
1855 #endif // ENABLE_LOGGING_AND_PROFILING | 1858 #endif // ENABLE_LOGGING_AND_PROFILING |
1856 | 1859 |
1857 } } // namespace v8::internal | 1860 } } // namespace v8::internal |
OLD | NEW |