diff options
author | Tom Hughes <tomhughes@google.com> | 2022-12-08 17:33:22 (GMT) |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-12-08 17:34:13 (GMT) |
commit | 516940f16d6b35d9c90b20eceb6d1f511407845e (patch) | |
tree | 7f37c91403e391c6cd641b0ae78e0a1dd036584d /googletest | |
parent | d454936a0c0ee999a3512d2494f06f888532fc45 (diff) | |
download | googletest-516940f16d6b35d9c90b20eceb6d1f511407845e.zip googletest-516940f16d6b35d9c90b20eceb6d1f511407845e.tar.gz googletest-516940f16d6b35d9c90b20eceb6d1f511407845e.tar.bz2 |
Fall back to the system clock when building with newlib on a system without a monotonic clock.
PiperOrigin-RevId: 493917905
Change-Id: I20137cfcda3671ffc8edcda2b6554aa392e3a00a
Diffstat (limited to 'googletest')
-rw-r--r-- | googletest/src/gtest.cc | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 281d933..51de00e 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -1123,17 +1123,24 @@ std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) { // A helper class for measuring elapsed times. class Timer { public: - Timer() : start_(std::chrono::steady_clock::now()) {} + Timer() : start_(clock::now()) {} // Return time elapsed in milliseconds since the timer was created. TimeInMillis Elapsed() { return std::chrono::duration_cast<std::chrono::milliseconds>( - std::chrono::steady_clock::now() - start_) + clock::now() - start_) .count(); } private: - std::chrono::steady_clock::time_point start_; + // Fall back to the system_clock when building with newlib on a system + // without a monotonic clock. +#if defined(_NEWLIB_VERSION) && !defined(CLOCK_MONOTONIC) + using clock = std::chrono::system_clock; +#else + using clock = std::chrono::steady_clock; +#endif + clock::time_point start_; }; // Returns a timestamp as milliseconds since the epoch. Note this time may jump |