Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
5f8fcf4a
Commit
5f8fcf4a
authored
Sep 02, 2020
by
dmauro
Committed by
Derek Mauro
Sep 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
Implements GetTimeInMillis() using std::chrono for portability Fixes #2995 PiperOrigin-RevId: 329709958
parent
7b1cf6dd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
44 deletions
+5
-44
gtest.cc
googletest/src/gtest.cc
+5
-44
No files found.
googletest/src/gtest.cc
View file @
5f8fcf4a
...
...
@@ -44,6 +44,7 @@
#include <wctype.h>
#include <algorithm>
#include <chrono> // NOLINT
#include <cstdint>
#include <iomanip>
#include <limits>
...
...
@@ -55,8 +56,6 @@
#if GTEST_OS_LINUX
# define GTEST_HAS_GETTIMEOFDAY_ 1
# include <fcntl.h> // NOLINT
# include <limits.h> // NOLINT
# include <sched.h> // NOLINT
...
...
@@ -68,7 +67,6 @@
# include <string>
#elif GTEST_OS_ZOS
# define GTEST_HAS_GETTIMEOFDAY_ 1
# include <sys/time.h> // NOLINT
// On z/OS we additionally need strings.h for strcasecmp.
...
...
@@ -94,16 +92,11 @@
# include <sys/stat.h> // NOLINT
# if GTEST_OS_WINDOWS_MINGW
// MinGW has gettimeofday() but not _ftime64().
# define GTEST_HAS_GETTIMEOFDAY_ 1
# include <sys/time.h> // NOLINT
# endif // GTEST_OS_WINDOWS_MINGW
#else
// Assume other platforms have gettimeofday().
# define GTEST_HAS_GETTIMEOFDAY_ 1
// cpplint thinks that the header is already included, so we want to
// silence it.
# include <sys/time.h> // NOLINT
...
...
@@ -1005,42 +998,10 @@ std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {
// Returns the current time in milliseconds.
TimeInMillis
GetTimeInMillis
()
{
#if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__)
// Difference between 1970-01-01 and 1601-01-01 in milliseconds.
// http://analogous.blogspot.com/2005/04/epoch.html
const
TimeInMillis
kJavaEpochToWinFileTimeDelta
=
static_cast
<
TimeInMillis
>
(
116444736UL
)
*
100000UL
;
const
DWORD
kTenthMicrosInMilliSecond
=
10000
;
SYSTEMTIME
now_systime
;
FILETIME
now_filetime
;
ULARGE_INTEGER
now_int64
;
GetSystemTime
(
&
now_systime
);
if
(
SystemTimeToFileTime
(
&
now_systime
,
&
now_filetime
))
{
now_int64
.
LowPart
=
now_filetime
.
dwLowDateTime
;
now_int64
.
HighPart
=
now_filetime
.
dwHighDateTime
;
now_int64
.
QuadPart
=
(
now_int64
.
QuadPart
/
kTenthMicrosInMilliSecond
)
-
kJavaEpochToWinFileTimeDelta
;
return
now_int64
.
QuadPart
;
}
return
0
;
#elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_
__timeb64
now
;
// MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996
// (deprecated function) there.
GTEST_DISABLE_MSC_DEPRECATED_PUSH_
()
_ftime64
(
&
now
);
GTEST_DISABLE_MSC_DEPRECATED_POP_
()
return
static_cast
<
TimeInMillis
>
(
now
.
time
)
*
1000
+
now
.
millitm
;
#elif GTEST_HAS_GETTIMEOFDAY_
struct
timeval
now
;
gettimeofday
(
&
now
,
nullptr
);
return
static_cast
<
TimeInMillis
>
(
now
.
tv_sec
)
*
1000
+
now
.
tv_usec
/
1000
;
#else
# error "Don't know how to get the current time on your system."
#endif
return
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
system_clock
::
now
()
-
std
::
chrono
::
system_clock
::
from_time_t
(
0
))
.
count
();
}
// Utilities
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment