-(defconstant internal-time-units-per-second 100
- #!+sb-doc
- "The number of internal time units that fit into a second. See
- GET-INTERNAL-REAL-TIME and GET-INTERNAL-RUN-TIME.")
-
-(defconstant micro-seconds-per-internal-time-unit
- (/ 1000000 internal-time-units-per-second))
-\f
-;;; The base number of seconds for our internal "epoch". We initialize
-;;; this to the time of the first call to GET-INTERNAL-REAL-TIME, and
-;;; then subtract this out of the result.
-(defvar *internal-real-time-base-seconds* nil)
-(declaim (type (or (unsigned-byte 32) null) *internal-real-time-base-seconds*))
-
-(defun get-internal-real-time ()
- #!+sb-doc
- "Return the real time in the internal time format. This is useful for
- finding elapsed time. See Internal-Time-Units-Per-Second."
- ;; FIXME: See comment on OPTIMIZE declaration in GET-INTERNAL-RUN-TIME.
- (declare (optimize (speed 3) (safety 3)))
- (multiple-value-bind (ignore seconds useconds) (sb!unix:unix-gettimeofday)
- (declare (ignore ignore) (type (unsigned-byte 32) seconds useconds))
- (let ((base *internal-real-time-base-seconds*)
- (uint (truncate useconds
- micro-seconds-per-internal-time-unit)))
- (declare (type (unsigned-byte 32) uint))
- (cond (base
- (truly-the (unsigned-byte 32)
- (+ (the (unsigned-byte 32)
- (* (the (unsigned-byte 32) (- seconds base))
- internal-time-units-per-second))
- uint)))
- (t
- (setq *internal-real-time-base-seconds* seconds)
- uint)))))
-
-#!-(and sparc svr4)
-(defun get-internal-run-time ()
- #!+sb-doc
- "Return the run time in the internal time format. This is useful for
- finding CPU usage."
- (declare (values (unsigned-byte 32)))
- ;; FIXME: In CMU CL this was (SPEED 3) (SAFETY 0), and perhaps
- ;; someday it should be again, since overhead here is annoying. But
- ;; it's even more annoying to worry about this function returning
- ;; out-of-range values, so while debugging the profiling code,
- ;; I set it to (SAFETY 3) for now.
- (declare (optimize (speed 3) (safety 3)))
- (multiple-value-bind (ignore utime-sec utime-usec stime-sec stime-usec)
- (sb!unix:unix-fast-getrusage sb!unix:rusage_self)
- (declare (ignore ignore)
- (type (unsigned-byte 31) utime-sec stime-sec)
- ;; (Classic CMU CL had these (MOD 1000000) instead, but
- ;; at least in Linux 2.2.12, the type doesn't seem to be
- ;; documented anywhere and the observed behavior is to
- ;; sometimes return 1000000 exactly.)
- (type (integer 0 1000000) utime-usec stime-usec))
- (+ (the (unsigned-byte 32)
- (* (the (unsigned-byte 32) (+ utime-sec stime-sec))
- internal-time-units-per-second))
- (truncate (+ utime-usec stime-usec)
- micro-seconds-per-internal-time-unit))))