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

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

Issue 1204153002: Add samplingTime mode to nanobench (Closed) Base URL: https://skia.googlesource.com/skia.git@upload_loopSKP
Patch Set: rebase Created 5 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
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_mach.h" 7 #include "SysTimer_mach.h"
8 8
9 static time_value_t mac_cpu_time() { 9 static time_value_t mac_cpu_time() {
10 mach_port_t task = mach_task_self(); 10 mach_port_t task = mach_task_self();
(...skipping 21 matching lines...) Expand all
32 if ((end_clock.microseconds - start_clock.microseconds) < 0) { 32 if ((end_clock.microseconds - start_clock.microseconds) < 0) {
33 duration_clock = (end_clock.seconds - start_clock.seconds-1) * 1000; 33 duration_clock = (end_clock.seconds - start_clock.seconds-1) * 1000;
34 duration_clock += (1000000 + end_clock.microseconds - start_clock.micros econds) / 1000.0; 34 duration_clock += (1000000 + end_clock.microseconds - start_clock.micros econds) / 1000.0;
35 } else { 35 } else {
36 duration_clock = (end_clock.seconds - start_clock.seconds) * 1000; 36 duration_clock = (end_clock.seconds - start_clock.seconds) * 1000;
37 duration_clock += (end_clock.microseconds - start_clock.microseconds) / 1000.0; 37 duration_clock += (end_clock.microseconds - start_clock.microseconds) / 1000.0;
38 } 38 }
39 return duration_clock; 39 return duration_clock;
40 } 40 }
41 41
42 static double wall_interval_in_ms(uint64_t elapsed) {
43 mach_timebase_info_data_t sTimebaseInfo;
44 if (KERN_SUCCESS != mach_timebase_info(&sTimebaseInfo)) {
45 return 0;
46 } else {
47 uint64_t elapsedNano = elapsed * sTimebaseInfo.numer / sTimebaseInfo.den om;
48 return elapsedNano / 1000000.0;
49 }
50 }
51
42 void SysTimer::startWall() { 52 void SysTimer::startWall() {
43 fStartWall = mach_absolute_time(); 53 fStartWall = mach_absolute_time();
44 } 54 }
45 55
46 void SysTimer::startCpu() { 56 void SysTimer::startCpu() {
47 fStartCpu = mac_cpu_time(); 57 fStartCpu = mac_cpu_time();
48 } 58 }
49 59
50 double SysTimer::endCpu() { 60 double SysTimer::endCpu() {
51 time_value_t end_cpu = mac_cpu_time(); 61 time_value_t end_cpu = mac_cpu_time();
52 return interval_in_ms(fStartCpu, end_cpu); 62 return interval_in_ms(fStartCpu, end_cpu);
53 } 63 }
54 64
55 double SysTimer::endWall() { 65 double SysTimer::endWall() {
56 uint64_t end_wall = mach_absolute_time(); 66 uint64_t end_wall = mach_absolute_time();
67 return wall_interval_in_ms(end_wall - fStartWall);
68 }
57 69
58 uint64_t elapsed = end_wall - fStartWall; 70 double GetTimeMs() {
59 mach_timebase_info_data_t sTimebaseInfo; 71 static const uint64_t launchTime = mach_absolute_time();
60 if (KERN_SUCCESS != mach_timebase_info(&sTimebaseInfo)) { 72 return wall_interval_in_ms(mach_absolute_time() - launchTime);
61 return 0;
62 } else {
63 uint64_t elapsedNano = elapsed * sTimebaseInfo.numer / sTimebaseInfo.den om;
64 return elapsedNano / 1000000.0;
65 }
66 } 73 }
OLDNEW
« bench/nanobench.cpp ('K') | « tools/Stats.h ('k') | tools/timer/SysTimer_posix.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698