On Thu, Jan 17, 2013 at 3:05 PM, Iustin Pop <ius...@google.com> wrote:
> 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: Iustin Pop <ius...@google.com> > --- > src/Ganeti/Utils.hs | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/src/Ganeti/Utils.hs b/src/Ganeti/Utils.hs > index 95f4280..9755e36 100644 > --- a/src/Ganeti/Utils.hs > +++ b/src/Ganeti/Utils.hs > @@ -46,6 +46,7 @@ module Ganeti.Utils > , rStripSpace > , newUUID > , getCurrentTime > + , getCurrentTimeUSec > , clockTimeToString > , chompPrefix > ) where > @@ -291,13 +292,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 > -- > 1.7.10.4 > > LGTM. Thanks, Michele