Skip to content
Snippets Groups Projects
Commit a6e054a8 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a function to get the current time in microseconds


In some cases we need higher resolution that seconds; I've settled on
microseconds as that is what 'threadDelay' wants, for exactly, so it's
easier if we keep the same units.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent c62df702
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@ module Ganeti.Utils
, rStripSpace
, newUUID
, getCurrentTime
, getCurrentTimeUSec
, clockTimeToString
, chompPrefix
, wrap
......@@ -293,13 +294,22 @@ newUUID = do
contents <- readFile C.randomUuidFile
return $! rStripSpace $ take 128 contents
-- | Returns the current time as an Integer representing the number of
-- seconds from the Unix epoch.
-- | Returns the current time as an 'Integer' representing the number
-- of seconds from the Unix epoch.
getCurrentTime :: IO Integer
getCurrentTime = do
TOD ctime _ <- getClockTime
return ctime
-- | Returns the current time as an 'Integer' representing the number
-- of microseconds from the Unix epoch (hence the need for 'Integer').
getCurrentTimeUSec :: IO Integer
getCurrentTimeUSec = do
TOD ctime pico <- getClockTime
-- pico: 10^-12, micro: 10^-6, so we have to shift seconds left and
-- picoseconds right
return $ ctime * 1000000 + pico `div` 1000000
-- | Convert a ClockTime into a (seconds-only) timestamp.
clockTimeToString :: ClockTime -> String
clockTimeToString (TOD t _) = show t
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment