#| Copyright (c) 2007 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |# (in-package :nio-utils) (declaim (optimize (debug 3) (speed 3) (space 0))) (defun get-readable (format-string &optional (time (get-universal-time))) (multiple-value-bind (second minute hour date month year) (decode-universal-time time) (with-output-to-string (out) (format out format-string year month date hour minute second)))) (defun get-readable-time ( &optional (time (get-universal-time))) (get-readable "~A/~2,'0d/~2,'0d ~2,'0d:~2,'0d:~2,'0d" time)) ;;High res timer (let ((internal-base (get-internal-real-time)) (universal-base (get-universal-time))) ; ; Gets the time including milliseconds by using a base time from universal time and ; tracking high res passing of time using the get-internal-real-time ; Probably not that accurate in absolute terms i.e. may drift from the base, ; but good enough for performance timings ; (defun get-universal-high-res() (let ((current-internal (get-internal-real-time))) (+ universal-base (/ (- current-internal internal-base) internal-time-units-per-second) ))) (defun get-readable-high-res-time() (let ((estimated-universal-float (get-universal-high-res))) (multiple-value-bind (estimated-universal estimated-universal-rem) (floor estimated-universal-float) (format nil "~A.~3,'0d"(get-readable-time estimated-universal) (* 1000 estimated-universal-rem))))) ) (defparameter *format-mutex* (nio-compat:make-mutex "format lock")) ;Format the message to destination but prepend a high res time to the message, useful for logging (defmacro format-log (destination control-string &rest format-arguments) `(nio-compat:with-mutex (*format-mutex*) (format ,destination (concatenate 'string "~A - " ,control-string) (get-readable-high-res-time) ,@format-arguments)))