This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: consecutive 'let
2007/12/27, Jake Miles wrote:
> Glad to help. Incidentally, I just want to make sure you're aware of
> let*, which is 'consecutive let', meaning that let variables can be
> used in later let variables' expressions (if they all need to access
> each other use letrec). Also, set! technically isn't necessary here -
> you can just initialize those values in the let expression (in which
> case the first expression in the dynamic-wind could just be (lambda ()
> #t) because it doesn't have to do anything.
Ok. Many thanks.
How this variant?
(define-simple-class <process-data> ()
(end-non-heap-mem :: <java.lang.management.MemoryUsage> init-value: #!null)
(end-heap-mem :: <java.lang.management.MemoryUsage> init-value: #!null)
(end-time :: <gnu.math.IntNum> init-value: #!null)
(start-non-heap-mem :: <java.lang.management.MemoryUsage> init-value: #!null)
(start-heap-mem :: <java.lang.management.MemoryUsage> init-value: #!null)
(start-time :: <gnu.math.IntNum> init-value: #!null)
(value init-value: ()))
(define (time-process-data process) :: <process-data>
(let ((mem-bean :: <java.lang.management.MemoryMXBean>
(java.lang.management.ManagementFactory:getMemoryMXBean)))
(mem-bean:gc) (mem-bean:gc) (mem-bean:gc) ;; Why so much? I do not know :)
(let ((data :: <process-data>
(make <process-data>
start-non-heap-mem: (mem-bean:getNonHeapMemoryUsage)
start-heap-mem: (mem-bean:getHeapMemoryUsage)
start-time: (java.lang.System:currentTimeMillis))))
(set! (*:.value data)
(dynamic-wind
(lambda () #t)
;; run our process (a function)
process
(lambda ()
(set! (*:.end-non-heap-mem data)
(mem-bean:getNonHeapMemoryUsage))
(set! (*:.end-heap-mem data) (mem-bean:getHeapMemoryUsage))
(set! (*:.end-time data)
(java.lang.System:currentTimeMillis)))))
(mem-bean:gc) ;; This is need?
data)))
(define (print-time-process-data data :: <process-data>)
(format #t "Value: ~A\n" data:value)
(format #t "Duration: ~,3F sec.\n"
(/ (- data:end-time data:start-time) 1000.0))
(format #t "Memory usage:\n Heap memory:\n")
(format #t " init: ~:D\n"
(- data:end-heap-mem:init data:start-heap-mem:init))
(format #t " used: ~:D\n"
(- data:end-heap-mem:used data:start-heap-mem:used))
(format #t " committed: ~:D\n"
(- data:end-heap-mem:committed data:start-heap-mem:committed))
(format #t " max: ~:D\n"
(- data:end-heap-mem:max data:start-heap-mem:max))
(format #t " Non heap memory:\n")
(format #t " init: ~:D\n"
(- data:end-non-heap-mem:init data:start-non-heap-mem:init))
(format #t " used: ~:D\n"
(- data:end-non-heap-mem:used data:start-non-heap-mem:used))
(format #t " committed: ~:D\n"
(- data:end-non-heap-mem:committed
data:start-non-heap-mem:committed))
(format #t " max: ~:D\n"
(- data:end-non-heap-mem:max data:start-non-heap-mem:max)))
(define (time-process process)
(print-time-process-data (time-process-data process)))
(define-syntax time
(syntax-rules ()
((time expression)
;; =>
(time-process (lambda () expression)))))
--
WBR, Yaroslav Kavenchuk.