From 5a06df46864f010befaf8c57af1801fb43cbea86 Mon Sep 17 00:00:00 2001 From: mtklein Date: Thu, 22 Oct 2015 17:49:22 -0700 Subject: Revert of SkTime::GetNSecs() (patchset #10 id:180001 of https://codereview.chromium.org/1422513003/ ) Reason for revert: https://codereview.chromium.org/1412453006 Original issue's description: > SkTime::GetNSecs() > > - Move high-precision wall timers from tools/timer to SkTime. > - Implement SkTime::GetMSecs() in terms of SkTime::GetNSecs(). > - Delete unused tools/timer code. > > I have no idea what's going on there in src/animator. > I don't intend to investigate. > > BUG=skia: > > Committed: https://skia.googlesource.com/skia/+/70084cbc16ee8162649f2601377feb6e49de0217 > > CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-x86_64-Debug-CrOS_Link-Trybot > > Committed: https://skia.googlesource.com/skia/+/a1840d50e29fd95e4df2d1168fe54c34c2a5c30c TBR=caryclark@google.com,reed@google.com,mtklein@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1417753003 --- tools/timer/SysTimer_posix.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tools/timer/SysTimer_posix.cpp (limited to 'tools/timer/SysTimer_posix.cpp') diff --git a/tools/timer/SysTimer_posix.cpp b/tools/timer/SysTimer_posix.cpp new file mode 100644 index 0000000000..4b7d708aab --- /dev/null +++ b/tools/timer/SysTimer_posix.cpp @@ -0,0 +1,51 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "SysTimer_posix.h" + +static double interval_in_ms(timespec start_clock, timespec end_clock) +{ + double duration_clock; + if ((end_clock.tv_nsec - start_clock.tv_nsec) < 0) { + duration_clock = (end_clock.tv_sec - start_clock.tv_sec - 1) * 1000; + duration_clock += (1000000000 + end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0; + } else { + duration_clock = (end_clock.tv_sec - start_clock.tv_sec) * 1000; + duration_clock += (end_clock.tv_nsec - start_clock.tv_nsec) / 1000000.0; + } + return duration_clock; +} + +void SysTimer::startWall() { + if (-1 == clock_gettime(CLOCK_MONOTONIC, &fWall)) { + timespec none = {0, 0}; + fWall = none; + } +} +void SysTimer::startCpu() { + if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &fCpu)) { + timespec none = {0, 0}; + fCpu = none; + } +} + +double SysTimer::endCpu() { + timespec end_cpu; + if (-1 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_cpu)) { + timespec none = {0, 0}; + end_cpu = none; + } + return interval_in_ms(fCpu, end_cpu); +} + +double SysTimer::endWall() { + timespec end_wall; + if (-1 == clock_gettime(CLOCK_MONOTONIC, &end_wall)) { + timespec none = {0, 0}; + end_wall = none; + } + return interval_in_ms(fWall, end_wall); +} -- cgit v1.2.3