This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: consecutive 'let


2007/12/26, Jake Miles wrote:
> Hi Yaroslav.  As far as I can tell there's no need to make this a
> macro - you could do it with a function like so.
...
> The dynamic-wind ensures that you will report the time and memory
> usage no matter what process does.
>

Many thanks! This is work:

(define (time-process process)
  (let ((mem-bean :: <java.lang.management.MemoryMXBean>
	 (java.lang.management.ManagementFactory:getMemoryMXBean))
	(start-heap-mem :: <java.lang.management.MemoryUsage> #!null)
	(start-non-heap-mem :: <java.lang.management.MemoryUsage> #!null)
	(start-time :: <gnu.math.IntNum>  #!null)
	(ret ()))
    (format #t "Value: ~A\n"

      (dynamic-wind

	  (lambda ()
	    (mem-bean:gc) (mem-bean:gc) (mem-bean:gc) ;; Why so much? I do not know :)
	    (set! start-time (java.lang.System:currentTimeMillis))
	    (set! start-non-heap-mem (mem-bean:getNonHeapMemoryUsage))
	    (set! start-heap-mem (mem-bean:getHeapMemoryUsage)))
	
	  ;; run our process (a function)
	  process
	
	  (lambda ()
	    (let ((end-heap-mem :: <java.lang.management.MemoryUsage>
(mem-bean:getHeapMemoryUsage))
		  (end-non-heap-mem :: <java.lang.management.MemoryUsage>
(mem-bean:getNonHeapMemoryUsage))
		  (end-time :: <gnu.math.IntNum> (java.lang.System:currentTimeMillis)))
	      (format #t "Duration: ~A sec.\n" (/ (- end-time start-time) 1000.0))
	      (format #t "Memory usage:\n  Heap memory:\n")
	      (format #t "    init:      ~A\n" (- end-heap-mem:init
start-heap-mem:init))
	      (format #t "    used:      ~A\n" (- end-heap-mem:used
start-heap-mem:used))
	      (format #t "    committed: ~A\n" (- end-heap-mem:committed
start-heap-mem:committed))
	      (format #t "    max:       ~A\n" (- end-heap-mem:max start-heap-mem:max))
	      (format #t "  Non heap memory:\n")
	      (format #t "    init:      ~A\n" (- end-non-heap-mem:init
start-non-heap-mem:init))
	      (format #t "    used:      ~A\n" (- end-non-heap-mem:used
start-non-heap-mem:used))
	      (format #t "    committed: ~A\n" (- end-non-heap-mem:committed
start-non-heap-mem:committed))
	      (format #t "    max:       ~A\n" (- end-non-heap-mem:max
start-non-heap-mem:max)))
	    (mem-bean:gc))))))


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]