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

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

Issue 344213003: Move BenchTimer to tools as Timer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fixes Created 6 years, 6 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
2 /* 1 /*
3 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
4 * 3 *
5 * 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
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 #include "BenchSysTimer_mach.h" 7 #include "SysTimer_mach.h"
9 8
10 //Time 9 static time_value_t mac_cpu_time() {
11 #include <mach/mach.h>
12 #include <mach/mach_time.h>
13
14 static time_value_t macCpuTime() {
15 mach_port_t task = mach_task_self(); 10 mach_port_t task = mach_task_self();
16 if (task == MACH_PORT_NULL) { 11 if (task == MACH_PORT_NULL) {
17 time_value_t none = {0, 0}; 12 time_value_t none = {0, 0};
18 return none; 13 return none;
19 } 14 }
20 15
21 task_thread_times_info thread_info_data; 16 task_thread_times_info thread_info_data;
22 mach_msg_type_number_t thread_info_count = TASK_THREAD_TIMES_INFO_COUNT; 17 mach_msg_type_number_t thread_info_count = TASK_THREAD_TIMES_INFO_COUNT;
23 if (KERN_SUCCESS != task_info(task, 18 if (KERN_SUCCESS != task_info(task,
24 TASK_THREAD_TIMES_INFO, 19 TASK_THREAD_TIMES_INFO,
25 reinterpret_cast<task_info_t>(&thread_info_data), 20 reinterpret_cast<task_info_t>(&thread_info_dat a),
26 &thread_info_count)) 21 &thread_info_count)) {
27 {
28 time_value_t none = {0, 0}; 22 time_value_t none = {0, 0};
29 return none; 23 return none;
30 } 24 }
31 25
32 time_value_add(&thread_info_data.user_time, &thread_info_data.system_time) 26 time_value_add(&thread_info_data.user_time, &thread_info_data.system_time)
33 return thread_info_data.user_time; 27 return thread_info_data.user_time;
34 } 28 }
35 29
36 static double intervalInMSec(const time_value_t start_clock 30 static double interval_in_ms(time_value_t start_clock, time_value_t end_clock) {
37 , const time_value_t end_clock)
38 {
39 double duration_clock; 31 double duration_clock;
40 if ((end_clock.microseconds - start_clock.microseconds) < 0) { 32 if ((end_clock.microseconds - start_clock.microseconds) < 0) {
41 duration_clock = (end_clock.seconds - start_clock.seconds-1)*1000; 33 duration_clock = (end_clock.seconds - start_clock.seconds-1) * 1000;
42 duration_clock += (1000000 34 duration_clock += (1000000 + end_clock.microseconds - start_clock.micros econds) / 1000.0;
43 + end_clock.microseconds
44 - start_clock.microseconds) / 1000.0;
45 } else { 35 } else {
46 duration_clock = (end_clock.seconds - start_clock.seconds)*1000; 36 duration_clock = (end_clock.seconds - start_clock.seconds) * 1000;
47 duration_clock += (end_clock.microseconds - start_clock.microseconds) 37 duration_clock += (end_clock.microseconds - start_clock.microseconds) / 1000.0;
48 / 1000.0;
49 } 38 }
50 return duration_clock; 39 return duration_clock;
51 } 40 }
52 41
53 void BenchSysTimer::startWall() { 42 void SysTimer::startWall() {
54 this->fStartWall = mach_absolute_time(); 43 fStartWall = mach_absolute_time();
55 }
56 void BenchSysTimer::startCpu() {
57 this->fStartCpu = macCpuTime();
58 } 44 }
59 45
60 double BenchSysTimer::endCpu() { 46 void SysTimer::startCpu() {
61 time_value_t end_cpu = macCpuTime(); 47 fStartCpu = mac_cpu_time();
62 return intervalInMSec(this->fStartCpu, end_cpu);
63 } 48 }
64 double BenchSysTimer::endWall() { 49
50 double SysTimer::endCpu() {
51 time_value_t end_cpu = mac_cpu_time();
52 return interval_in_ms(fStartCpu, end_cpu);
53 }
54
55 double SysTimer::endWall() {
65 uint64_t end_wall = mach_absolute_time(); 56 uint64_t end_wall = mach_absolute_time();
66 57
67 uint64_t elapsed = end_wall - this->fStartWall; 58 uint64_t elapsed = end_wall - fStartWall;
68 mach_timebase_info_data_t sTimebaseInfo; 59 mach_timebase_info_data_t sTimebaseInfo;
69 if (KERN_SUCCESS != mach_timebase_info(&sTimebaseInfo)) { 60 if (KERN_SUCCESS != mach_timebase_info(&sTimebaseInfo)) {
70 return 0; 61 return 0;
71 } else { 62 } else {
72 uint64_t elapsedNano = elapsed * sTimebaseInfo.numer 63 uint64_t elapsedNano = elapsed * sTimebaseInfo.numer / sTimebaseInfo.den om;
73 / sTimebaseInfo.denom;
74 return elapsedNano / 1000000.0; 64 return elapsedNano / 1000000.0;
75 } 65 }
76 } 66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698