#!+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*)
"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)
;; documented anywhere and the observed behavior is to
;; sometimes return 1000000 exactly.)
(type (integer 0 1000000) utime-usec stime-usec))
-
(let ((result (+ (the (unsigned-byte 32)
(* (the (unsigned-byte 32) (+ utime-sec stime-sec))
sb!xc:internal-time-units-per-second))
\f
;;;; 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.
(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)
(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))))))
\f
;;;; TIME
(defmacro time (form)
#!+sb-doc
"Execute FORM and print timing information on *TRACE-OUTPUT*."
- `(%time #'(lambda () ,form)))
+ `(%time (lambda () ,form)))
;;; Return all the data that we want TIME to report.
(defun time-get-sys-info ()
;;; The guts of the TIME macro. Compute overheads, run the (compiled)
;;; function, report the times.
(defun %time (fun)
+ (declare (type function fun))
(let (old-run-utime
new-run-utime
old-run-stime