Skip to content
Snippets Groups Projects
Commit 30019a2b authored by ram's avatar ram
Browse files

Changed GET-INTERNAL-REAL-TIME to subtract out the time of the first

call to minimize the probability of bignum results.  Changed both
GET-INTERNAL-REAL-TIME and GET-INTERNAL-RUN-TIME to assume that the
syscall does ERRNO checking and to have a locally unsafe policy.
parent b91cd22f
No related branches found
No related tags found
No related merge requests found
...@@ -34,30 +34,46 @@ ...@@ -34,30 +34,46 @@
(not (eq (mod ,sym 400) 0)))) (not (eq (mod ,sym 400) 0))))
(T T))))) (T T)))))
;;; The base number of seconds for our internal "epoch". We initialize this to
;;; the time of the first call to G-I-R-T, 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*))
;;; Get-Internal-Real-Time -- Public ;;; Get-Internal-Real-Time -- Public
;;; ;;;
(defun get-internal-real-time () (defun get-internal-real-time ()
"Return the real time in the internal time format. This is useful for "Return the real time in the internal time format. This is useful for
finding elapsed time. See Internal-Time-Units-Per-Second." finding elapsed time. See Internal-Time-Units-Per-Second."
(multiple-value-bind (result seconds useconds) (mach:unix-gettimeofday) (locally (declare (optimize (speed 3) (safety 0)))
(if result (multiple-value-bind (ignore seconds useconds) (mach:unix-gettimeofday)
(+ (* seconds internal-time-units-per-second) (declare (ignore ignore))
(truncate useconds micro-seconds-per-internal-time-unit)) (let ((base *internal-real-time-base-seconds*)
(error "Unix system call gettimeofday failed: ~A" (uint (truncate useconds
(mach:get-unix-error-msg seconds))))) micro-seconds-per-internal-time-unit)))
(declare (type (unsigned-byte 32) uint))
(cond (base
(+ (* (the (unsigned-byte 32) (- seconds base))
internal-time-units-per-second)
uint))
(t
(setq *internal-real-time-base-seconds* seconds)
uint))))))
;;; Get-Internal-Run-Time -- Public ;;; Get-Internal-Run-Time -- Public
;;; ;;;
(defun get-internal-run-time () (defun get-internal-run-time ()
"Return the run time in the internal time format. This is useful for "Return the run time in the internal time format. This is useful for
finding CPU usage." finding CPU usage."
(multiple-value-bind (result utime stime) (locally (declare (optimize (speed 3) (safety 0)))
(mach:unix-getrusage mach:rusage_self) (multiple-value-bind (ignore utime stime)
(if result (mach:unix-getrusage mach:rusage_self)
(values (truncate (+ utime stime) (declare (ignore ignore))
micro-seconds-per-internal-time-unit)) (values (truncate (the (unsigned-byte 32) (+ utime stime))
(error "Unix system call getrusage failed: ~A" micro-seconds-per-internal-time-unit)))))
(mach:get-unix-error-msg utime)))))
;;; Subtract from the returned Internal_Time to get the universal time. ;;; Subtract from the returned Internal_Time to get the universal time.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment