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

Side by Side Diff: bench/BenchSysTimer_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
(Empty)
1
2 /*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8 #include "BenchSysTimer_posix.h"
9
10 //Time
11 #include <time.h>
12
13 static double intervalInMSec(const timespec start_clock
14 , const timespec end_clock)
15 {
16 double duration_clock;
17 if ((end_clock.tv_nsec - start_clock.tv_nsec) < 0) {
18 duration_clock = (end_clock.tv_sec - start_clock.tv_sec-1)*1000;
19 duration_clock += (1000000000 + end_clock.tv_nsec - start_clock.tv_nsec)
20 / 1000000.0;
21 } else {
22 duration_clock = (end_clock.tv_sec - start_clock.tv_sec)*1000;
23 duration_clock += (end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0;
24 }
25 return duration_clock;
26 }
27
28 void BenchSysTimer::startWall() {
29 if (-1 == clock_gettime(CLOCK_MONOTONIC, &this->fWall)) {
30 timespec none = {0, 0};
31 this->fWall = none;
32 }
33 }
34 void BenchSysTimer::startCpu() {
35 if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &this->fCpu)) {
36 timespec none = {0, 0};
37 this->fCpu = none;
38 }
39 }
40
41 double BenchSysTimer::endCpu() {
42 timespec end_cpu;
43 if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_cpu)) {
44 timespec none = {0, 0};
45 end_cpu = none;
46 }
47 return intervalInMSec(this->fCpu, end_cpu);
48 }
49
50 double BenchSysTimer::endWall() {
51 timespec end_wall;
52 if (-1 == clock_gettime(CLOCK_MONOTONIC, &end_wall)) {
53 timespec none = {0, 0};
54 end_wall = none;
55 }
56 return intervalInMSec(this->fWall, end_wall);
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698