Reviewers: alph, loislo, Benedikt Meurer, Jakob,
Description:
Support higher CPU profiler sampling rate on Windows
This change moves sampling from SamplerThread to the profiler events
processing
thread and allows to configure sampling interval on Windows.
Custom tick counter is used instead of OS::Ticks as the latter has maximum
presicion of 1ms while we need 100us. QueryPerformanceCounter is used to
retrieve high-precision time as described in
http://msdn.microsoft.com/en-us/library/ee417693(VS.85).aspx
BUG=v8:2814
Please review this at https://codereview.chromium.org/23271003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/cpu-profiler.h
M src/cpu-profiler.cc
M src/sampler.cc
Index: src/cpu-profiler.cc
diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc
index
158555723935b06026c55fbb84bb5f4d61e18c4d..8dc9622c0976d0c8103b387e637a7f9b1a8da03f
100644
--- a/src/cpu-profiler.cc
+++ b/src/cpu-profiler.cc
@@ -25,6 +25,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
+#include <windows.h>
+#endif
#include "v8.h"
#include "cpu-profiler-inl.h"
@@ -141,6 +144,19 @@ bool ProfilerEventsProcessor::ProcessTicks() {
}
+int64_t ProfilerEventsProcessor::Ticks() {
+#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
+ LARGE_INTEGER perf_counter;
+ if (QueryPerformanceCounter(&perf_counter)) {
+ int64_t result = perf_counter.QuadPart;
+ result = static_cast<int64_t>(result * perf_counter_to_us_rate_);
+ return result;
+ }
+#endif
+ return OS::Ticks();
+}
+
+
void ProfilerEventsProcessor::ProcessEventsAndDoSample() {
int64_t stop_time = OS::Ticks() + period_in_useconds_;
// Keep processing existing events until we need to do next sample.
@@ -168,6 +184,20 @@ void ProfilerEventsProcessor::ProcessEventsAndYield() {
void ProfilerEventsProcessor::Run() {
+#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
+ // Assign this thread to the first core as the perf counter value may be
+ // different on different CPUs. See http://msdn.microsoft.com/
+ // en-us/library/windows/desktop/ee417693(v=vs.85).aspx for more details.
+ const DWORD_PTR thread_affinity_mask = 1;
+ SetThreadAffinityMask(GetCurrentThread(), thread_affinity_mask);
+ LARGE_INTEGER frequency;
+ if (QueryPerformanceFrequency(&frequency)) {
+ perf_counter_to_us_rate_ = 1000000.0 / frequency.QuadPart;
+ } else {
+ perf_counter_to_us_rate_ = 0;
+ }
+#endif
+
while (running_) {
if (Sampler::CanSampleOnProfilerEventsProcessorThread()) {
ProcessEventsAndDoSample();
Index: src/cpu-profiler.h
diff --git a/src/cpu-profiler.h b/src/cpu-profiler.h
index
a9cc61129c5258bf3aeeacb8f15253283015bd02..fa788d01c20af8b66647c8e4ac3d4cf73b3f1e4d
100644
--- a/src/cpu-profiler.h
+++ b/src/cpu-profiler.h
@@ -165,6 +165,7 @@ class ProfilerEventsProcessor : public Thread {
bool ProcessCodeEvent();
bool ProcessTicks();
+ int64_t Ticks();
void ProcessEventsAndDoSample();
void ProcessEventsAndYield();
@@ -178,6 +179,9 @@ class ProfilerEventsProcessor : public Thread {
UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_;
unsigned last_code_event_id_;
unsigned last_processed_code_event_id_;
+#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
+ double perf_counter_to_us_rate_;
+#endif
};
Index: src/sampler.cc
diff --git a/src/sampler.cc b/src/sampler.cc
index
ebef06c832a2b96ae9074782920950aef553620a..e5b081ac4832f7ffa69d9b09d8a8e48ddfe4331e
100644
--- a/src/sampler.cc
+++ b/src/sampler.cc
@@ -609,6 +609,8 @@ bool
Sampler::CanSampleOnProfilerEventsProcessorThread() {
return true;
#elif defined(__MACH__)
return true;
+#elif defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
+ return true;
#else
return false;
#endif
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.