X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Ftime.lisp;h=451003ad32632a048d537f302b4a502e282a4364;hb=b062a0cffdc3e1706a67c487d2bc5e406c104893;hp=4bb9d9c42737f6bed288147f67a3bdc9d0b8b434;hpb=a530bbe337109d898d5b4a001fc8f1afa3b5dc39;p=sbcl.git diff --git a/src/code/time.lisp b/src/code/time.lisp index 4bb9d9c..451003a 100644 --- a/src/code/time.lisp +++ b/src/code/time.lisp @@ -11,16 +11,13 @@ (in-package "SB!IMPL") -(file-comment - "$Header$") - -(defconstant internal-time-units-per-second 100 +(defconstant sb!xc:internal-time-units-per-second 1000 #!+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)) + (/ 1000000 sb!xc:internal-time-units-per-second)) ;;; 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 @@ -31,9 +28,7 @@ (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))) + finding elapsed time. See INTERNAL-TIME-UNITS-PER-SECOND." (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*) @@ -44,24 +39,17 @@ (truly-the (unsigned-byte 32) (+ (the (unsigned-byte 32) (* (the (unsigned-byte 32) (- seconds base)) - internal-time-units-per-second)) + sb!xc: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) @@ -71,40 +59,20 @@ ;; 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)))) - -#!+(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: See comment on OPTIMIZE declaration in other - ;; version of GET-INTERNAL-RUN-TIME. - (declare (optimize (speed 3) (safety 3))) - (multiple-value-bind (ignore utime stime cutime cstime) - (sb!unix:unix-times) - (declare (ignore ignore cutime cstime) - (type (unsigned-byte 31) utime stime)) - (the (unsigned-byte 32) (+ utime stime)))) + (let ((result (+ (the (unsigned-byte 32) + (* (the (unsigned-byte 32) (+ utime-sec stime-sec)) + sb!xc:internal-time-units-per-second)) + (floor (+ utime-usec + stime-usec + (floor micro-seconds-per-internal-time-unit 2)) + micro-seconds-per-internal-time-unit)))) + result))) ;;;; Encode and decode universal times. -;;; Returns two values: -;;; - the minutes west of GMT. -;;; - T if daylight savings is in effect, NIL if not. -(sb!alien:def-alien-routine get-timezone sb!c-call:void - (when sb!c-call:long :in) - (minutes-west sb!c-call:int :out) - (daylight-savings-p sb!alien:boolean :out)) - -;;; Subtract from the returned Internal-Time to get the universal time. -;;; The offset between our time base and the Perq one is 2145 weeks and -;;; five days. +;;; Subtract from the returned Internal-Time to get the universal +;;; time. The offset between our time base and the Perq one is 2145 +;;; weeks and five days. (defconstant seconds-in-week (* 60 60 24 7)) (defconstant weeks-offset 2145) (defconstant seconds-offset 432000) @@ -117,7 +85,7 @@ (defun get-universal-time () #!+sb-doc - "Returns a single integer for the current time of + "Return a single integer for the current time of day in universal time format." (multiple-value-bind (res secs) (sb!unix:unix-gettimeofday) (declare (ignore res)) @@ -125,7 +93,7 @@ (defun get-decoded-time () #!+sb-doc - "Returns nine values specifying the current time as follows: + "Return nine values specifying the current time as follows: second, minute, hour, date, month, year, day of week (0 = Monday), T (daylight savings times) or NIL (standard time), and timezone." (decode-universal-time (get-universal-time))) @@ -148,15 +116,17 @@ (year NIL) (day NIL) (daylight NIL) - (timezone (if (null time-zone) - (multiple-value-bind - (ignore minwest dst) - (get-timezone (- universal-time - unix-to-universal-time)) - (declare (ignore ignore)) - (setf daylight dst) - minwest) - (* time-zone 60)))) + (timezone (cond + ((null time-zone) + (multiple-value-bind + (ignore minwest dst) + (sb!unix::get-timezone (- universal-time + unix-to-universal-time)) + (declare (ignore ignore)) + (declare (fixnum minwest)) + (setf daylight dst) + minwest)) + (t (* time-zone 60))))) (declare (fixnum timezone)) (multiple-value-bind (t1 seconds) (truncate secs 60) (setq second seconds) @@ -235,39 +205,22 @@ (if time-zone (+ second (* (+ minute (* (+ hours time-zone) 60)) 60)) (let* ((minwest-guess - (nth-value 1 - (get-timezone (- (* hours 60 60) - unix-to-universal-time)))) + (sb!unix::unix-get-minutes-west (- (* hours 60 60) + unix-to-universal-time))) (guess (+ minute (* hours 60) minwest-guess)) (minwest - (nth-value 1 - (get-timezone (- (* guess 60) - unix-to-universal-time))))) + (sb!unix::unix-get-minutes-west (- (* guess 60) + unix-to-universal-time)))) (+ second (* (+ guess (- minwest minwest-guess)) 60)))))) ;;;; TIME (defmacro time (form) #!+sb-doc - "Evaluates the Form and prints timing information on *Trace-Output*." - `(%time #'(lambda () ,form))) - -;;; Try to compile the closure arg to %TIME if it is interpreted. -(defun massage-time-function (fun) - (cond - ((sb!eval:interpreted-function-p fun) - (multiple-value-bind (def env-p) (function-lambda-expression fun) - (declare (ignore def)) - (cond - (env-p - (warn "TIME form in a non-null environment, forced to interpret.~@ - Compiling entire form will produce more accurate times.") - fun) - (t - (compile nil fun))))) - (t fun))) + "Execute FORM and print timing information on *TRACE-OUTPUT*." + `(%time (lambda () ,form))) -;;; Return all the files that we want time to report. +;;; Return all the data that we want TIME to report. (defun time-get-sys-info () (multiple-value-bind (user sys faults) (sb!sys:get-system-info) (values user sys faults (get-bytes-consed)))) @@ -275,8 +228,7 @@ ;;; The guts of the TIME macro. Compute overheads, run the (compiled) ;;; function, report the times. (defun %time (fun) - (let ((fun (massage-time-function fun)) - old-run-utime + (let (old-run-utime new-run-utime old-run-stime new-run-stime @@ -333,12 +285,12 @@ ~S page fault~:P and~% ~ ~S bytes consed.~%" (max (/ (- new-real-time old-real-time) - (float internal-time-units-per-second)) + (float sb!xc:internal-time-units-per-second)) 0.0) (max (/ (- new-run-utime old-run-utime) 1000000.0) 0.0) (max (/ (- new-run-stime old-run-stime) 1000000.0) 0.0) (unless (zerop gc-run-time) (/ (float gc-run-time) - (float internal-time-units-per-second))) + (float sb!xc:internal-time-units-per-second))) (max (- new-page-faults old-page-faults) 0) (max (- new-bytes-consed old-bytes-consed) 0)))))))