henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/base/timing.h" |
| 12 | #include "webrtc/base/timeutils.h" |
| 13 | |
| 14 | #if defined(WEBRTC_POSIX) |
| 15 | #include <errno.h> |
| 16 | #include <math.h> |
| 17 | #include <sys/time.h> |
| 18 | #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 19 | #include <mach/mach.h> |
| 20 | #include <mach/clock.h> |
| 21 | #endif |
| 22 | #elif defined(WEBRTC_WIN) |
| 23 | #include <sys/timeb.h> |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 24 | #endif |
| 25 | |
| 26 | namespace rtc { |
| 27 | |
tommi | 7d0d0e0 | 2016-01-25 03:09:29 -0800 | [diff] [blame^] | 28 | Timing::Timing() {} |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 29 | |
tommi | 7d0d0e0 | 2016-01-25 03:09:29 -0800 | [diff] [blame^] | 30 | Timing::~Timing() {} |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 31 | |
tommi@webrtc.org | ecb8723 | 2014-07-08 12:48:29 +0000 | [diff] [blame] | 32 | // static |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 33 | double Timing::WallTimeNow() { |
| 34 | #if defined(WEBRTC_POSIX) |
| 35 | struct timeval time; |
| 36 | gettimeofday(&time, NULL); |
| 37 | // Convert from second (1.0) and microsecond (1e-6). |
| 38 | return (static_cast<double>(time.tv_sec) + |
| 39 | static_cast<double>(time.tv_usec) * 1.0e-6); |
| 40 | |
| 41 | #elif defined(WEBRTC_WIN) |
| 42 | struct _timeb time; |
| 43 | _ftime(&time); |
| 44 | // Convert from second (1.0) and milliseconds (1e-3). |
| 45 | return (static_cast<double>(time.time) + |
| 46 | static_cast<double>(time.millitm) * 1.0e-3); |
| 47 | #endif |
| 48 | } |
| 49 | |
| 50 | double Timing::TimerNow() { |
| 51 | return (static_cast<double>(TimeNanos()) / kNumNanosecsPerSec); |
| 52 | } |
| 53 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 54 | } // namespace rtc |