;;AUTOLOAD: meminfo
;;AUTOLOAD: gcinfo
;;AUTOLOAD: klcfinfo
;;AUTOLOAD: hashinfo


;; emulation of the old meminfo function
;; addition: (meminfo :all t) lists all buckets

(setq meminfo:sizes:small 
  '(8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536)
)
(setq meminfo:sizes:all 
  '(8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536
    131072 262144 524288 1048576 2097152 4194304 8388608 16777216 
    33554432 67108864
  )
)

(defun meminfo (&key all &aux (res (*:memory)) (cells (getn res 2))
    (*print-readably* ())
    val
    (meminfo:sizes (if all meminfo:sizes:all meminfo:sizes:small))	
  )
  (print-format "Memory allocation statistics\n")
  (print-format "size")
  (dolist (s  meminfo:sizes)
    (if 
      (>= s 1048576) (setq s (+ (expand-num (/ s 1048576) 4 :filler #\ ) "M"))
      (>= s 1024) (setq s (+ (expand-num (/ s 1024) 4 :filler #\ ) "k"))
      (setq s (expand-num s 5 :filler #\ ))
    )
    (write s)
  )
  
  (print-format "\nfree")
  (dolist (s  meminfo:sizes)
    (setq val 0)
    (dolist (cell cells)
      (if (= s (0 cell)) (setq val (get cell 2 0)))
    )
    (write (expand-num val 5 :filler #\ ))
  )
  
  (print-format "\nused")
  (dolist (s  meminfo:sizes)
    (setq val 0)
    (dolist (cell cells)
      (if (= s (0 cell)) (setq val (get cell 1 0)))
    )
    (write (expand-num val 5 :filler #\ ))
  )
  
  (print-format "\n  Total in use: %0, total free: %1\n" (0 res) (1 res))
  
  ()    
)
  
(defvar gcinfo ())
(defvar klcfinfo ())
(defvar hashinfo ())
