[Yum-devel] [PATCH] use USER_HZ value reported by OS
Nils Philippsen
nils at redhat.com
Wed Sep 28 15:25:56 UTC 2011
POSIX operating systems report the USER_HZ value (i.e. how many jiffies
fit in one second, concerning userspace) via sysconf(_SC_CLK_TCK).
---
utils.py | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/utils.py b/utils.py
index 99533a6..08b09fb 100755
--- a/utils.py
+++ b/utils.py
@@ -15,6 +15,7 @@
"""Various utility functions, and a utility class."""
+import os
import sys
import time
import exceptions
@@ -30,6 +31,12 @@ from optparse import OptionGroup
import yum.plugins as plugins
from urlgrabber.progress import format_number
+try:
+ _USER_HZ = os.sysconf(os.sysconf_names['SC_CLK_TCK'])
+except (AttributeError, KeyError):
+ # Huh, non-Unix platform? Or just really old?
+ _USER_HZ = 100
+
def suppress_keyboard_interrupt_message():
"""Change settings so that nothing will be printed to the
terminal after an uncaught :class:`exceptions.KeyboardInterrupt`.
@@ -45,14 +52,13 @@ def suppress_keyboard_interrupt_message():
sys.excepthook = new_hook
def jiffies_to_seconds(jiffies):
- """Convert a number of jiffies to seconds, using the convention
- that 100 jiffies = 1 second.
+ """Convert a number of jiffies to seconds. How many jiffies are in a second
+ is system-dependent, e.g. 100 jiffies = 1 second is common.
:param jiffies: a number of jiffies
:return: the equivalent number of seconds
"""
- Hertz = 100 # FIXME: Hack, need to get this, AT_CLKTCK elf note *sigh*
- return int(jiffies) / Hertz
+ return int(jiffies) / _USER_HZ
def seconds_to_ui_time(seconds):
"""Return a human-readable string representation of the length of
--
1.7.6.2
More information about the Yum-devel
mailing list