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

Side by Side Diff: tools/timer/SysTimer_posix.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_posix.h" 7 #include "SysTimer_posix.h"
9 8
10 //Time 9 static double interval_in_ms(timespec start_clock, timespec end_clock)
11 #include <time.h>
12
13 static double intervalInMSec(const timespec start_clock
14 , const timespec end_clock)
15 { 10 {
16 double duration_clock; 11 double duration_clock;
17 if ((end_clock.tv_nsec - start_clock.tv_nsec) < 0) { 12 if ((end_clock.tv_nsec - start_clock.tv_nsec) < 0) {
18 duration_clock = (end_clock.tv_sec - start_clock.tv_sec-1)*1000; 13 duration_clock = (end_clock.tv_sec - start_clock.tv_sec - 1) * 1000;
19 duration_clock += (1000000000 + end_clock.tv_nsec - start_clock.tv_nsec) 14 duration_clock += (1000000000 + end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0;
20 / 1000000.0;
21 } else { 15 } else {
22 duration_clock = (end_clock.tv_sec - start_clock.tv_sec)*1000; 16 duration_clock = (end_clock.tv_sec - start_clock.tv_sec) * 1000;
23 duration_clock += (end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0; 17 duration_clock += (end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0;
24 } 18 }
25 return duration_clock; 19 return duration_clock;
26 } 20 }
27 21
28 void BenchSysTimer::startWall() { 22 void SysTimer::startWall() {
29 if (-1 == clock_gettime(CLOCK_MONOTONIC, &this->fWall)) { 23 if (-1 == clock_gettime(CLOCK_MONOTONIC, &fWall)) {
30 timespec none = {0, 0}; 24 timespec none = {0, 0};
31 this->fWall = none; 25 fWall = none;
32 } 26 }
33 } 27 }
34 void BenchSysTimer::startCpu() { 28 void SysTimer::startCpu() {
35 if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &this->fCpu)) { 29 if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &fCpu)) {
36 timespec none = {0, 0}; 30 timespec none = {0, 0};
37 this->fCpu = none; 31 fCpu = none;
38 } 32 }
39 } 33 }
40 34
41 double BenchSysTimer::endCpu() { 35 double SysTimer::endCpu() {
42 timespec end_cpu; 36 timespec end_cpu;
43 if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_cpu)) { 37 if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_cpu)) {
44 timespec none = {0, 0}; 38 timespec none = {0, 0};
45 end_cpu = none; 39 end_cpu = none;
46 } 40 }
47 return intervalInMSec(this->fCpu, end_cpu); 41 return interval_in_ms(fCpu, end_cpu);
48 } 42 }
49 43
50 double BenchSysTimer::endWall() { 44 double SysTimer::endWall() {
51 timespec end_wall; 45 timespec end_wall;
52 if (-1 == clock_gettime(CLOCK_MONOTONIC, &end_wall)) { 46 if (-1 == clock_gettime(CLOCK_MONOTONIC, &end_wall)) {
53 timespec none = {0, 0}; 47 timespec none = {0, 0};
54 end_wall = none; 48 end_wall = none;
55 } 49 }
56 return intervalInMSec(this->fWall, end_wall); 50 return interval_in_ms(fWall, end_wall);
57 } 51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698