Time.h 1.4 KB
Newer Older
Simon Marlow's avatar
Simon Marlow committed
1 2 3 4 5 6 7
/* ----------------------------------------------------------------------------
 *
 * (c) The GHC Team, 1998-2004
 *
 * Time values in the RTS
 *
 * To understand the structure of the RTS headers, see the wiki:
8
 *   https://gitlab.haskell.org/ghc/ghc/wikis/commentary/source-tree/includes
Simon Marlow's avatar
Simon Marlow committed
9 10 11
 *
 * --------------------------------------------------------------------------*/

12
#pragma once
Simon Marlow's avatar
Simon Marlow committed
13 14 15 16 17 18 19 20 21 22 23

// For most time values in the RTS we use a fixed resolution of nanoseconds,
// normalising the time we get from platform-dependent APIs to this
// resolution.
#define TIME_RESOLUTION 1000000000
typedef int64_t Time;

#define TIME_MAX HS_INT64_MAX

#if TIME_RESOLUTION == 1000000000
// I'm being lazy, but it's awkward to define fully general versions of these
24
#define TimeToMS(t)      ((t) / 1000000)
Simon Marlow's avatar
Simon Marlow committed
25 26
#define TimeToUS(t)      ((t) / 1000)
#define TimeToNS(t)      (t)
27
#define MSToTime(t)      ((Time)(t) * 1000000)
Simon Marlow's avatar
Simon Marlow committed
28 29 30 31 32 33 34 35
#define USToTime(t)      ((Time)(t) * 1000)
#define NSToTime(t)      ((Time)(t))
#else
#error Fix TimeToNS(), TimeToUS() etc.
#endif

#define SecondsToTime(t) ((Time)(t) * TIME_RESOLUTION)
#define TimeToSeconds(t) ((t) / TIME_RESOLUTION)
Ben Gamari's avatar
Ben Gamari committed
36
#define TimeToSecondsDbl(t) ((double)(t) / TIME_RESOLUTION)
Simon Marlow's avatar
Simon Marlow committed
37 38 39 40 41 42 43

// Use instead of SecondsToTime() when we have a floating-point
// seconds value, to avoid truncating it.
INLINE_HEADER Time fsecondsToTime (double t)
{
    return (Time)(t * TIME_RESOLUTION);
}
44 45

Time getProcessElapsedTime (void);