diff options
author | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 22:34:29 +0000 |
---|---|---|
committer | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 22:34:29 +0000 |
commit | 85d61a05f6c55f38f219d9a3ff0c5bec66db7e72 (patch) | |
tree | ebbac0e264c6091abfd6bcbe41d5aa27fcb6f5e5 /chrome/browser/sync/util | |
parent | e376aa74c136126e808c5865ef0cf24ed2a999f7 (diff) | |
download | chromium_src-85d61a05f6c55f38f219d9a3ff0c5bec66db7e72.zip chromium_src-85d61a05f6c55f38f219d9a3ff0c5bec66db7e72.tar.gz chromium_src-85d61a05f6c55f38f219d9a3ff0c5bec66db7e72.tar.bz2 |
Remove the high res timer, which is unused.
Review URL: http://codereview.chromium.org/369006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/util')
-rw-r--r-- | chrome/browser/sync/util/highres_timer.h | 15 | ||||
-rw-r--r-- | chrome/browser/sync/util/highres_timer_linux.cc | 29 | ||||
-rw-r--r-- | chrome/browser/sync/util/highres_timer_linux.h | 79 | ||||
-rw-r--r-- | chrome/browser/sync/util/highres_timer_mac.cc | 53 | ||||
-rw-r--r-- | chrome/browser/sync/util/highres_timer_mac.h | 69 | ||||
-rw-r--r-- | chrome/browser/sync/util/highres_timer_unittest.cc | 41 | ||||
-rw-r--r-- | chrome/browser/sync/util/highres_timer_win.cc | 46 | ||||
-rw-r--r-- | chrome/browser/sync/util/highres_timer_win.h | 78 |
8 files changed, 0 insertions, 410 deletions
diff --git a/chrome/browser/sync/util/highres_timer.h b/chrome/browser/sync/util/highres_timer.h deleted file mode 100644 index 2c6513d..0000000 --- a/chrome/browser/sync/util/highres_timer.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// High resolution timer functions defined for each OS. - -#include "build/build_config.h" - -#if defined(OS_WIN) -#include "chrome/browser/sync/util/highres_timer_win.h" -#elif defined(OS_MACOSX) -#include "chrome/browser/sync/util/highres_timer_mac.h" -#else -#include "chrome/browser/sync/util/highres_timer_linux.h" -#endif diff --git a/chrome/browser/sync/util/highres_timer_linux.cc b/chrome/browser/sync/util/highres_timer_linux.cc deleted file mode 100644 index 77350f9..0000000 --- a/chrome/browser/sync/util/highres_timer_linux.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// High resolution timer functions for use in Linux. - -#include "chrome/browser/sync/util/highres_timer.h" - -const uint64 MICROS_IN_MILLI = 1000L; -const uint64 MICROS_IN_HALF_MILLI = 500L; -const uint64 MICROS_IN_HALF_SECOND = 500000L; - -uint64 HighresTimer::GetElapsedMs() const { - uint64 end_time = GetCurrentTicks(); - - // Scale to ms and round to nearest ms - rounding is important because - // otherwise the truncation error may accumulate e.g. in sums. - return (uint64(end_time - start_ticks_) + MICROS_IN_HALF_MILLI) / - MICROS_IN_MILLI; -} - -uint64 HighresTimer::GetElapsedSec() const { - uint64 end_time = GetCurrentTicks(); - - // Scale to ms and round to nearest ms - rounding is important because - // otherwise the truncation error may accumulate e.g. in sums. - return (uint64(end_time - start_ticks_) + MICROS_IN_HALF_SECOND) / - MICROS_IN_SECOND; -} diff --git a/chrome/browser/sync/util/highres_timer_linux.h b/chrome/browser/sync/util/highres_timer_linux.h deleted file mode 100644 index 01a022d..0000000 --- a/chrome/browser/sync/util/highres_timer_linux.h +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// High resolution timer functions for use in Linux. - -#ifndef CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_LINUX_H_ -#define CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_LINUX_H_ - -#include "base/basictypes.h" - -#include <sys/time.h> - -const uint64 MICROS_IN_SECOND = 1000000L; - -// A handy class for reliably measuring wall-clock time with decent resolution. -// -// We want to measure time with high resolution on Linux. What to do? -// -// RDTSC? Sure, but how do you convert it to wall clock time? -// clock_gettime? It's not in all Linuxes. -// -// Let's just use gettimeofday; it's good to the microsecond. -class HighresTimer { - public: - // Captures the current start time. - HighresTimer(); - - // Captures the current tick, can be used to reset a timer for reuse. - void Start(); - - // Returns the elapsed ticks with full resolution. - uint64 GetElapsedTicks() const; - - // Returns the elapsed time in milliseconds, rounded to the nearest - // millisecond. - uint64 GetElapsedMs() const; - - // Returns the elapsed time in seconds, rounded to the nearest second. - uint64 GetElapsedSec() const; - - uint64 start_ticks() const { return start_ticks_; } - - // Returns timer frequency from cache, should be less overhead than - // ::QueryPerformanceFrequency. - static uint64 GetTimerFrequency(); - // Returns current ticks. - static uint64 GetCurrentTicks(); - - private: - // Captured start time. - uint64 start_ticks_; -}; - -inline HighresTimer::HighresTimer() { - Start(); -} - -inline void HighresTimer::Start() { - start_ticks_ = GetCurrentTicks(); -} - -inline uint64 HighresTimer::GetTimerFrequency() { - // Fixed; one "tick" is one microsecond. - return MICROS_IN_SECOND; -} - -inline uint64 HighresTimer::GetCurrentTicks() { - timeval tv; - gettimeofday(&tv, 0); - - return tv.tv_sec * MICROS_IN_SECOND + tv.tv_usec; -} - -inline uint64 HighresTimer::GetElapsedTicks() const { - return start_ticks_ - GetCurrentTicks(); -} - -#endif // CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_LINUX_H_ diff --git a/chrome/browser/sync/util/highres_timer_mac.cc b/chrome/browser/sync/util/highres_timer_mac.cc deleted file mode 100644 index faad058..0000000 --- a/chrome/browser/sync/util/highres_timer_mac.cc +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// High resolution timer functions for use on Mac OS. - -#include "chrome/browser/sync/util/highres_timer.h" - -bool HighresTimer::perf_ratio_collected_ = false; -mach_timebase_info_data_t HighresTimer::perf_ratio_ = {0}; - -static const uint64 kNanosInMilli = 1000000L; -static const uint64 kNanosInHalfMilli = 500000L; -static const uint64 kNanosInSecond = 1000000000L; -static const uint64 kNanosInHalfSecond = 500000000L; - -uint64 HighresTimer::GetElapsedMs() const { - uint64 end_time = GetCurrentTicks(); - - // Scale to ms and round to nearest ms - rounding is important - // because otherwise the truncation error may accumulate e.g. in sums. - // - GetTimerFrequency(); - return ((end_time - start_ticks_) * perf_ratio_.numer + - kNanosInHalfMilli * perf_ratio_.denom) / - (kNanosInMilli * perf_ratio_.denom); -} - -uint64 HighresTimer::GetElapsedSec() const { - uint64 end_time = GetCurrentTicks(); - - // Scale to ms and round to nearest ms - rounding is important - // because otherwise the truncation error may accumulate e.g. in sums. - // - GetTimerFrequency(); - return ((end_time - start_ticks_) * perf_ratio_.numer + - kNanosInHalfSecond * perf_ratio_.denom) / - (kNanosInSecond * perf_ratio_.denom); -} - -void HighresTimer::CollectPerfRatio() { - mach_timebase_info(&perf_ratio_); - perf_ratio_collected_ = true; -} - -uint64 HighresTimer::GetTimerFrequency() { - if (!perf_ratio_collected_) - CollectPerfRatio(); - // we're losing precision by doing the division here, but this value is only - // used to estimate tick time by the unit tests, so we're ok. - return static_cast<uint64>( - perf_ratio_.denom * 1000000000ULL / perf_ratio_.numer); -} diff --git a/chrome/browser/sync/util/highres_timer_mac.h b/chrome/browser/sync/util/highres_timer_mac.h deleted file mode 100644 index 3a35622..0000000 --- a/chrome/browser/sync/util/highres_timer_mac.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// High resolution timer functions for use on Mac OS. - -#ifndef CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_MAC_H_ -#define CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_MAC_H_ - -#include <mach/mach.h> -#include <mach/mach_time.h> - -#include "base/basictypes.h" - -// A handy class for reliably measuring wall-clock time with decent resolution. -class HighresTimer { - public: - // Captures the current start time - HighresTimer(); - - // Captures the current tick, can be used to reset a timer for reuse. - void Start(); - - // Returns the elapsed ticks with full resolution. - uint64 GetElapsedTicks() const; - - // Returns the elapsed time in milliseconds, rounded to the nearest - // millisecond. - uint64 GetElapsedMs() const; - - // Returns the elapsed time in seconds, rounded to the nearest second. - uint64 GetElapsedSec() const; - - uint64 start_ticks() const { return start_ticks_; } - - // Returns timer frequency from cache, should be less overhead than - // ::QueryPerformanceFrequency. - static uint64 GetTimerFrequency(); - // Returns current ticks. - static uint64 GetCurrentTicks(); - - private: - static void CollectPerfRatio(); - - // Captured start time. - uint64 start_ticks_; - - // Captured performance counter frequency. - static bool perf_ratio_collected_; - static mach_timebase_info_data_t perf_ratio_; -}; - -inline HighresTimer::HighresTimer() { - Start(); -} - -inline void HighresTimer::Start() { - start_ticks_ = GetCurrentTicks(); -} - -inline uint64 HighresTimer::GetCurrentTicks() { - return mach_absolute_time(); -} - -inline uint64 HighresTimer::GetElapsedTicks() const { - return start_ticks_ - GetCurrentTicks(); -} - -#endif // CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_MAC_H_ diff --git a/chrome/browser/sync/util/highres_timer_unittest.cc b/chrome/browser/sync/util/highres_timer_unittest.cc deleted file mode 100644 index 2257262..0000000 --- a/chrome/browser/sync/util/highres_timer_unittest.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// High resolution timer unit tests. - -#include "base/basictypes.h" -#include "base/platform_thread.h" -#include "build/build_config.h" -#include "chrome/browser/sync/util/highres_timer.h" -#include "testing/gtest/include/gtest/gtest.h" - -// These unittests have proven to be flaky on buildbot. While we don't want -// them breaking the build, we still build them to guard against bitrot. -// On dev machines during local builds we can enable them. -TEST(HighresTimer, DISABLED_MillisecondClock) { - HighresTimer timer; - - // Note: this could fail if we context switch between initializing the timer - // and here. Very unlikely however. - EXPECT_TRUE(0 == timer.GetElapsedMs()); - timer.Start(); - uint64 half_ms = HighresTimer::GetTimerFrequency() / 2000; - // Busy wait for half a millisecond. - while (timer.start_ticks() + half_ms > HighresTimer::GetCurrentTicks()) { - // Nothing - } - EXPECT_TRUE(1 == timer.GetElapsedMs()); -} - -TEST(HighresTimer, DISABLED_SecondClock) { - HighresTimer timer; - - EXPECT_TRUE(0 == timer.GetElapsedSec()); - PlatformThread::Sleep(250); - EXPECT_TRUE(0 == timer.GetElapsedSec()); - EXPECT_TRUE(230 <= timer.GetElapsedMs()); - EXPECT_TRUE(270 >= timer.GetElapsedMs()); - PlatformThread::Sleep(251); - EXPECT_TRUE(1 == timer.GetElapsedSec()); -} diff --git a/chrome/browser/sync/util/highres_timer_win.cc b/chrome/browser/sync/util/highres_timer_win.cc deleted file mode 100644 index 0d7323a..0000000 --- a/chrome/browser/sync/util/highres_timer_win.cc +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// High resolution timer functions for use in Windows. - -#include "chrome/browser/sync/util/highres_timer.h" - -bool HighresTimer::perf_freq_collected_ = false; -ULONGLONG HighresTimer::perf_freq_ = 0; - -ULONGLONG HighresTimer::GetElapsedMs() const { - ULONGLONG end_time = GetCurrentTicks(); - - // Scale to ms and round to nearest ms - rounding is important because - // otherwise the truncation error may accumulate e.g. in sums. - // - // Given infinite resolution, this expression could be written as: - // trunc((end - start (units:freq*sec))/freq (units:sec) * - // 1000 (unit:ms) + 1/2 (unit:ms)) - ULONGLONG freq = GetTimerFrequency(); - return ((end_time - start_ticks_) * 1000L + freq / 2) / freq; -} - -ULONGLONG HighresTimer::GetElapsedSec() const { - ULONGLONG end_time = GetCurrentTicks(); - - // Round to nearest ms - rounding is important because otherwise the - // truncation error may accumulate e.g. in sums. - // - // Given infinite resolution, this expression could be written as: - // trunc((end - start (units:freq*sec))/freq (unit:sec) + 1/2 (unit:sec)) - ULONGLONG freq = GetTimerFrequency(); - return ((end_time - start_ticks_) + freq / 2) / freq; -} - -void HighresTimer::CollectPerfFreq() { - LARGE_INTEGER freq; - - // Note that this is racy. It's OK, however, because even concurrent - // executions of this are idempotent. - if (::QueryPerformanceFrequency(&freq)) { - perf_freq_ = freq.QuadPart; - perf_freq_collected_ = true; - } -} diff --git a/chrome/browser/sync/util/highres_timer_win.h b/chrome/browser/sync/util/highres_timer_win.h deleted file mode 100644 index d03a872..0000000 --- a/chrome/browser/sync/util/highres_timer_win.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// High resolution timer functions for use in Windows. - -#ifndef CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_WIN_H_ -#define CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_WIN_H_ - -#include <windows.h> - -// A handy class for reliably measuring wall-clock time with decent resolution, -// even on multi-processor machines and on laptops (where RDTSC potentially -// returns different results on different processors and/or the RDTSC timer -// clocks at different rates depending on the power state of the CPU, -// respectively). -class HighresTimer { - public: - // Captures the current start time. - HighresTimer(); - - // Captures the current tick, can be used to reset a timer for reuse. - void Start(); - - // Returns the elapsed ticks with full resolution. - ULONGLONG GetElapsedTicks() const; - - // Returns the elapsed time in milliseconds, rounded to the nearest - // millisecond. - ULONGLONG GetElapsedMs() const; - - // Returns the elapsed time in seconds, rounded to the nearest second. - ULONGLONG GetElapsedSec() const; - - ULONGLONG start_ticks() const { return start_ticks_; } - - // Returns timer frequency from cache, should be less - // overhead than ::QueryPerformanceFrequency. - static ULONGLONG GetTimerFrequency(); - // Returns current ticks. - static ULONGLONG GetCurrentTicks(); - - private: - static void CollectPerfFreq(); - - // Captured start time. - ULONGLONG start_ticks_; - - // Captured performance counter frequency. - static bool perf_freq_collected_; - static ULONGLONG perf_freq_; -}; - -inline HighresTimer::HighresTimer() { - Start(); -} - -inline void HighresTimer::Start() { - start_ticks_ = GetCurrentTicks(); -} - -inline ULONGLONG HighresTimer::GetTimerFrequency() { - if (!perf_freq_collected_) - CollectPerfFreq(); - return perf_freq_; -} - -inline ULONGLONG HighresTimer::GetCurrentTicks() { - LARGE_INTEGER ticks; - ::QueryPerformanceCounter(&ticks); - return ticks.QuadPart; -} - -inline ULONGLONG HighresTimer::GetElapsedTicks() const { - return start_ticks_ - GetCurrentTicks(); -} - -#endif // CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_WIN_H_ |