blob: 7fdcf6e933fe2b0754f1da1d5b11eaeb96b4a847 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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.orgf0488722014-05-13 18:00:26 +000024#endif
25
26namespace rtc {
27
tommi7d0d0e02016-01-25 03:09:29 -080028Timing::Timing() {}
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000029
tommi7d0d0e02016-01-25 03:09:29 -080030Timing::~Timing() {}
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000031
tommi@webrtc.orgecb87232014-07-08 12:48:29 +000032// static
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000033double 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
50double Timing::TimerNow() {
51 return (static_cast<double>(TimeNanos()) / kNumNanosecsPerSec);
52}
53
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000054} // namespace rtc