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

Unified Diff: runtime/vm/os_win.cc

Issue 1367973004: Make timeline use the same clock source as mojo's tracing infrastructure (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/os_macos.cc ('k') | runtime/vm/timeline.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/os_win.cc
diff --git a/runtime/vm/os_win.cc b/runtime/vm/os_win.cc
index 85133418f1de562b9b26421541df1e7f68582824..0e07cdf919ea5cf3f9c18d71d0554ee082d48af1 100644
--- a/runtime/vm/os_win.cc
+++ b/runtime/vm/os_win.cc
@@ -121,6 +121,26 @@ int64_t OS::GetCurrentTimeMicros() {
}
+static int64_t qpc_ticks_per_second = 0;
+
+int64_t OS::GetCurrentTraceMicros() {
+ if (qpc_ticks_per_second == 0) {
+ // QueryPerformanceCounter not supported, fallback.
+ return GetCurrentTimeMicros();
+ }
+ // Grab performance counter value.
+ LARGE_INTEGER now;
+ QueryPerformanceCounter(&now);
+ int64_t qpc_value = static_cast<int64_t>(now.QuadPart);
+ // Convert to microseconds.
+ int64_t seconds = qpc_value / qpc_ticks_per_second;
+ int64_t leftover_ticks = qpc_value - (seconds * qpc_ticks_per_second);
+ int64_t result = seconds * kMicrosecondsPerSecond;
+ result += ((leftover_ticks * kMicrosecondsPerSecond) / qpc_ticks_per_second);
+ return result;
+}
+
+
void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) {
const int kMinimumAlignment = 16;
ASSERT(Utils::IsPowerOfTwo(alignment));
@@ -350,6 +370,12 @@ void OS::InitOnce() {
_set_abort_behavior(0, _WRITE_ABORT_MSG);
MonitorWaitData::monitor_wait_data_key_ = OSThread::CreateThreadLocal();
MonitorData::GetMonitorWaitDataForThread();
+ LARGE_INTEGER ticks_per_sec;
+ if (!QueryPerformanceFrequency(&ticks_per_sec)) {
+ qpc_ticks_per_second = 0;
+ } else {
+ qpc_ticks_per_second = static_cast<int64_t>(ticks_per_sec.QuadPart);
+ }
}
« no previous file with comments | « runtime/vm/os_macos.cc ('k') | runtime/vm/timeline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698