Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Shayne Fletcher
Glasgow Haskell Compiler
Commits
ed198935
Commit
ed198935
authored
May 03, 1999
by
sof
Browse files
[project @ 1999-05-03 13:22:29 by sof]
Win32'ified
parent
04783b79
Changes
2
Hide whitespace changes
Inline
Side-by-side
ghc/lib/std/cbits/getCPUTime.c
View file @
ed198935
/*
* (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
*
* $Id: getCPUTime.c,v 1.
4
1999/0
3
/0
1 09:04:07
sof Exp $
* $Id: getCPUTime.c,v 1.
5
1999/0
5
/0
3 13:22:29
sof Exp $
*
* getCPUTime Runtime Support
*/
...
...
@@ -51,6 +51,10 @@
#define HAVE_GETRUSAGE
#endif
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
StgInt
clockTicks
()
{
...
...
@@ -71,6 +75,7 @@ clockTicks ()
* seconds to overflow 31 bits.
*/
#ifndef _WIN32
StgByteArray
getCPUTime
(
StgByteArray
cpuStruct
)
{
...
...
@@ -114,3 +119,48 @@ getCPUTime(StgByteArray cpuStruct)
#endif
return
(
StgByteArray
)
cpuStruct
;
}
#else
#ifdef _WIN32
/* 100ns units per sec, really */
#define NS_PER_SEC 10000000LL
#define FT2usecs(ll,ft) \
(ll)=(ft).dwHighDateTime; \
(ll) <<= 32; \
(ll) |= (ft).dwLowDateTime;
#endif
/* cygwin32 or mingw32 version */
StgByteArray
getCPUTime
(
StgByteArray
cpuStruct
)
{
FILETIME
creationTime
,
exitTime
,
kernelTime
,
userTime
;
StgInt
*
cpu
=
(
StgInt
*
)
cpuStruct
;
unsigned
long
long
uT
,
kT
;
/* ToDo: pin down elapsed times to just the OS thread(s) that
are evaluating/managing Haskell code.
*/
if
(
!
GetProcessTimes
(
GetCurrentProcess
(),
&
creationTime
,
&
exitTime
,
&
kernelTime
,
&
userTime
))
{
/* Probably on a Win95 box..*/
cpu
[
0
]
=
0
;
cpu
[
1
]
=
0
;
cpu
[
2
]
=
0
;
cpu
[
3
]
=
0
;
return
(
StgByteArray
)
cpu
;
}
FT2usecs
(
uT
,
userTime
);
FT2usecs
(
kT
,
kernelTime
);
cpu
[
0
]
=
(
unsigned
int
)(
uT
/
NS_PER_SEC
);
cpu
[
1
]
=
(
unsigned
int
)(
uT
*
100
);
cpu
[
0
]
=
(
unsigned
int
)(
kT
/
NS_PER_SEC
);
cpu
[
1
]
=
(
unsigned
int
)(
kT
*
100
);
return
(
StgByteArray
)
cpu
;
}
#endif
/* _WIN32 */
ghc/lib/std/cbits/getClockTime.c
View file @
ed198935
/*
* (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
*
* $Id: getClockTime.c,v 1.
3
199
8/12
/0
2
13:2
7:38 simonm
Exp $
* $Id: getClockTime.c,v 1.
4
199
9/05
/0
3
13:2
2:29 sof
Exp $
*
* getClockTime Runtime Support
*/
...
...
@@ -36,10 +36,24 @@
# endif
#endif
#ifdef HAVE_WINDOWS_H
#include
<windows.h>
#include
<sys/types.h>
#include
<sys/timeb.h>
#endif
StgInt
getClockTime
(
StgByteArray
sec
,
StgByteArray
nsec
)
{
#ifdef HAVE_GETCLOCK
#if defined(_WIN32)
struct
timeb
t
;
_ftime
(
&
t
);
((
unsigned
int
*
)
sec
)[
0
]
=
(
unsigned
int
)
t
.
time
;
((
unsigned
int
*
)
nsec
)[
0
]
=
(
unsigned
int
)
t
.
millitm
*
1000
;
return
0
;
#elif defined(HAVE_GETCLOCK)
struct
timespec
tp
;
if
(
getclock
(
TIMEOFDAY
,
&
tp
)
!=
0
)
{
...
...
@@ -50,8 +64,7 @@ getClockTime(StgByteArray sec, StgByteArray nsec)
((
unsigned
long
int
*
)
sec
)[
0
]
=
tp
.
tv_sec
;
((
unsigned
long
int
*
)
nsec
)[
0
]
=
tp
.
tv_nsec
;
return
0
;
#else
#ifdef HAVE_GETTIMEOFDAY
#elif defined(HAVE_GETTIMEOFDAY)
struct
timeval
tp
;
if
(
gettimeofday
(
&
tp
,
NULL
)
!=
0
)
{
...
...
@@ -73,13 +86,20 @@ getClockTime(StgByteArray sec, StgByteArray nsec)
((
unsigned
long
int
*
)
nsec
)[
0
]
=
0
;
return
0
;
#endif
#endif
}
StgInt
prim_getClockTime
(
StgByteArray
sec
,
StgByteArray
nsec
)
{
#ifdef HAVE_GETCLOCK
#if defined(_WIN32)
struct
timeb
t
;
_ftime
(
&
t
);
((
unsigned
long
int
*
)
sec
)[
0
]
=
t
.
time
;
((
unsigned
long
int
*
)
nsec
)[
0
]
=
t
.
millitm
*
1000
;
return
0
;
#elif defined(HAVE_GETCLOCK)
struct
timespec
tp
;
if
(
getclock
(
TIMEOFDAY
,
&
tp
)
!=
0
)
{
...
...
@@ -90,8 +110,7 @@ prim_getClockTime(StgByteArray sec, StgByteArray nsec)
((
StgInt64
*
)
sec
)[
0
]
=
tp
.
tv_sec
;
((
StgInt64
*
)
nsec
)[
0
]
=
tp
.
tv_nsec
;
return
0
;
#else
#ifdef HAVE_GETTIMEOFDAY
#elif defined(HAVE_GETTIMEOFDAY)
struct
timeval
tp
;
if
(
gettimeofday
(
&
tp
,
NULL
)
!=
0
)
{
...
...
@@ -113,5 +132,4 @@ prim_getClockTime(StgByteArray sec, StgByteArray nsec)
((
StgInt64
*
)
nsec
)[
0
]
=
0
;
return
0
;
#endif
#endif
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment