| 1 |
#!r6rs |
| 2 |
;; Copyright (c) 2009 Derick Eddington. All rights reserved. Licensed under an |
| 3 |
;; MIT-style license. My license is in the file named LICENSE from the original |
| 4 |
;; collection this file is distributed with. If this file is redistributed with |
| 5 |
;; some other collection, my license must also be included. |
| 6 |
|
| 7 |
(library (srfi :19 time compat) |
| 8 |
(export |
| 9 |
time-resolution |
| 10 |
current-time |
| 11 |
time-nanosecond |
| 12 |
time-second |
| 13 |
timezone-offset |
| 14 |
cumulative-thread-time |
| 15 |
cumulative-process-time |
| 16 |
cumulative-gc-time) |
| 17 |
(import |
| 18 |
(rnrs base) |
| 19 |
(ironscheme datetime) |
| 20 |
(ironscheme process) |
| 21 |
(only (srfi :19 time not-implemented) cumulative-gc-time)) |
| 22 |
|
| 23 |
(define time-resolution 100) |
| 24 |
|
| 25 |
(define base (datetime->local (make-utc-datetime 1970 1 1))) |
| 26 |
|
| 27 |
(define (current-time) (now)) |
| 28 |
; since 1970, but fractional (100ns per tick in .NET) |
| 29 |
(define (time-nanosecond t) (mod (* 100 (ticks (difference t base))) #e1e9)) |
| 30 |
(define (time-second t) (exact (truncate (total-seconds (difference t base))))) |
| 31 |
(define timezone-offset (exact (truncate (total-seconds (difference (now) (datetime->utc (now))))))) |
| 32 |
;; todo: check if parameters correct |
| 33 |
(define (cumulative-thread-time) |
| 34 |
(datetime-add base (process-user-cpu-time (get-current-process)))) |
| 35 |
(define (cumulative-process-time) |
| 36 |
(datetime-add base (process-total-cpu-time (get-current-process)))) |
| 37 |
) |