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

Side by Side Diff: tools/timer/SysTimer_windows.cpp

Issue 397843002: revert timer changes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SysTimer_windows.h" 7 #include "SysTimer_windows.h"
8 8
9 #include <intrin.h>
10
11 static ULONGLONG win_cpu_time() { 9 static ULONGLONG win_cpu_time() {
12 FILETIME createTime; 10 FILETIME createTime;
13 FILETIME exitTime; 11 FILETIME exitTime;
14 FILETIME usrTime; 12 FILETIME usrTime;
15 FILETIME sysTime; 13 FILETIME sysTime;
16 if (0 == GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &sysTi me, &usrTime)) { 14 if (0 == GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &sysTi me, &usrTime)) {
17 return 0; 15 return 0;
18 } 16 }
19 ULARGE_INTEGER start_cpu_sys; 17 ULARGE_INTEGER start_cpu_sys;
20 ULARGE_INTEGER start_cpu_usr; 18 ULARGE_INTEGER start_cpu_usr;
21 start_cpu_sys.LowPart = sysTime.dwLowDateTime; 19 start_cpu_sys.LowPart = sysTime.dwLowDateTime;
22 start_cpu_sys.HighPart = sysTime.dwHighDateTime; 20 start_cpu_sys.HighPart = sysTime.dwHighDateTime;
23 start_cpu_usr.LowPart = usrTime.dwLowDateTime; 21 start_cpu_usr.LowPart = usrTime.dwLowDateTime;
24 start_cpu_usr.HighPart = usrTime.dwHighDateTime; 22 start_cpu_usr.HighPart = usrTime.dwHighDateTime;
25 return start_cpu_sys.QuadPart + start_cpu_usr.QuadPart; 23 return start_cpu_sys.QuadPart + start_cpu_usr.QuadPart;
26 } 24 }
27 25
26 void SysTimer::startWall() {
27 if (0 == ::QueryPerformanceCounter(&fStartWall)) {
28 fStartWall.QuadPart = 0;
29 }
30 }
28 void SysTimer::startCpu() { 31 void SysTimer::startCpu() {
29 fStartCpu = win_cpu_time(); 32 fStartCpu = win_cpu_time();
30 } 33 }
31 34
32 double SysTimer::endCpu() { 35 double SysTimer::endCpu() {
33 ULONGLONG end_cpu = win_cpu_time(); 36 ULONGLONG end_cpu = win_cpu_time();
34 return static_cast<double>(end_cpu - fStartCpu) / 10000.0L; 37 return static_cast<double>(end_cpu - fStartCpu) / 10000.0L;
35 } 38 }
36
37 static void wall_timestamp(LARGE_INTEGER* now) {
38 _ReadWriteBarrier();
39 if (0 == ::QueryPerformanceCounter(now)) {
40 now->QuadPart = 0;
41 }
42 _ReadWriteBarrier();
43 }
44
45 void SysTimer::startWall() {
46 wall_timestamp(&fStartWall);
47 }
48
49 double SysTimer::endWall() { 39 double SysTimer::endWall() {
50 LARGE_INTEGER end_wall; 40 LARGE_INTEGER end_wall;
51 wall_timestamp(&end_wall); 41 if (0 == ::QueryPerformanceCounter(&end_wall)) {
42 end_wall.QuadPart = 0;
43 }
52 44
53 LARGE_INTEGER ticks_elapsed; 45 LARGE_INTEGER ticks_elapsed;
54 ticks_elapsed.QuadPart = end_wall.QuadPart - fStartWall.QuadPart; 46 ticks_elapsed.QuadPart = end_wall.QuadPart - fStartWall.QuadPart;
55 47
56 LARGE_INTEGER frequency; 48 LARGE_INTEGER frequency;
57 if (0 == ::QueryPerformanceFrequency(&frequency)) { 49 if (0 == ::QueryPerformanceFrequency(&frequency)) {
58 return 0.0L; 50 return 0.0L;
59 } else { 51 } else {
60 return static_cast<double>(ticks_elapsed.QuadPart) 52 return static_cast<double>(ticks_elapsed.QuadPart)
61 / static_cast<double>(frequency.QuadPart) 53 / static_cast<double>(frequency.QuadPart)
62 * 1000.0L; 54 * 1000.0L;
63 } 55 }
64 } 56 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698