I'd like to implement some fine logging functions, that is with a
precision of at least 1 millisecond.
I found the get-universal-time/get-decoded-time standard functions but
they both miss the millisecond info.
Any idea ?
············@gmail.com writes:
> I'd like to implement some fine logging functions, that is with a
> precision of at least 1 millisecond.
> I found the get-universal-time/get-decoded-time standard functions but
> they both miss the millisecond info.
GET-INTERNAL-REAL-TIME and GET-INTERNAL-RUN-TIME
with INTERNAL-TIME-UNITS-PER-SECOND
--
__Pascal_Bourguignon__
http://www.informatimago.com/
On Feb 16, 3:51 pm, Pascal Bourguignon <····@informatimago.com> wrote:
> ············@gmail.com writes:
> > I'd like to implement some fine logging functions, that is with a
> > precision of at least 1 millisecond.
> > I found the get-universal-time/get-decoded-time standard functions but
> > they both miss the millisecond info.
>
> GET-INTERNAL-REAL-TIME and GET-INTERNAL-RUN-TIME
> with INTERNAL-TIME-UNITS-PER-SECOND
>
Well, no since internal-*-time do not offer access to year+month+day
+hour+min+second informations. And those are so helpfull in log
analysis I can't (imagine to) consider not using them.
············@gmail.com writes:
> On Feb 16, 3:51 pm, Pascal Bourguignon <····@informatimago.com> wrote:
>> ············@gmail.com writes:
>> > I'd like to implement some fine logging functions, that is with a
>> > precision of at least 1 millisecond.
>> > I found the get-universal-time/get-decoded-time standard functions but
>> > they both miss the millisecond info.
>>
>> GET-INTERNAL-REAL-TIME and GET-INTERNAL-RUN-TIME
>> with INTERNAL-TIME-UNITS-PER-SECOND
>>
>
> Well, no since internal-*-time do not offer access to year+month+day
> +hour+min+second informations. And those are so helpfull in log
> analysis I can't (imagine to) consider not using them.
You can synchronize both clocks.
(defvar *internal-real-time-sync*
(progn
(loop :with coarse-time = (get-universal-time)
:while (= coarse-time (get-universal-time)))
(loop
:with coarse-time = (get-universal-time)
:for current-time = (get-universal-time)
:while (= coarse-time current-time)
:finally (return (cons (get-universal-time) (get-internal-real-time))))))
;; Then:
(defun precise-universal-time ()
(+ (coerce (car *internal-real-time-sync*) 'double-float)
(/ (- (get-internal-real-time) (cdr *internal-real-time-sync*))
internal-time-units-per-second)))
C/USER[60]> (progn (format t "~19,6F~%" (PRECISE-UNIVERSAL-TIME))
(sleep 1.35)
(format t "~19,6F~%" (PRECISE-UNIVERSAL-TIME))
(values))
3380630664.406471
3380630665.760221
Just remember to use TRUNCATE before calling DECODE-UNIVERSAL-TIME.
--
__Pascal Bourguignon__ http://www.informatimago.com/
Nobody can fix the economy. Nobody can be trusted with their finger
on the button. Nobody's perfect. VOTE FOR NOBODY.
On Feb 16, 5:05 pm, Pascal Bourguignon <····@informatimago.com> wrote:
> ············@gmail.com writes:
> > On Feb 16, 3:51 pm, Pascal Bourguignon <····@informatimago.com> wrote:
> >> ············@gmail.com writes:
> >> > I'd like to implement some fine logging functions, that is with a
> >> > precision of at least 1 millisecond.
> >> > I found the get-universal-time/get-decoded-time standard functions but
> >> > they both miss the millisecond info.
>
> >> GET-INTERNAL-REAL-TIME and GET-INTERNAL-RUN-TIME
> >> with INTERNAL-TIME-UNITS-PER-SECOND
>
> > Well, no since internal-*-time do not offer access to year+month+day
> > +hour+min+second informations. And those are so helpfull in log
> > analysis I can't (imagine to) consider not using them.
>
> You can synchronize both clocks.
>
> (defvar *internal-real-time-sync*
> (progn
> (loop :with coarse-time = (get-universal-time)
> :while (= coarse-time (get-universal-time)))
> (loop
> :with coarse-time = (get-universal-time)
> :for current-time = (get-universal-time)
> :while (= coarse-time current-time)
> :finally (return (cons (get-universal-time) (get-internal-real-time))))))
>
> ;; Then:
>
> (defun precise-universal-time ()
> (+ (coerce (car *internal-real-time-sync*) 'double-float)
> (/ (- (get-internal-real-time) (cdr *internal-real-time-sync*))
> internal-time-units-per-second)))
>
> C/USER[60]> (progn (format t "~19,6F~%" (PRECISE-UNIVERSAL-TIME))
> (sleep 1.35)
> (format t "~19,6F~%" (PRECISE-UNIVERSAL-TIME))
> (values))
> 3380630664.406471
> 3380630665.760221
>
> Just remember to use TRUNCATE before calling DECODE-UNIVERSAL-TIME.
>
Well ... thanks. Time for me to learn beyond the simple loop
flavour ;)