diff --git a/src/Ganeti/Utils.hs b/src/Ganeti/Utils.hs index 74ad060c764cdeae0c7808a0a3e8efa769657784..cfaaaab2faee2e2ea73ae5c5b071cf26536e4a49 100644 --- a/src/Ganeti/Utils.hs +++ b/src/Ganeti/Utils.hs @@ -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