space.scm 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; ,open architecture primitives assembler packages enumerated
  3. ; ,open features sort locations display-conditions
  4. (define length-procedures
  5. (do ((i (- stob-count 1) (- i 1))
  6. (l '() (cons (eval `(lap *length ()
  7. (protocol 1 (push template))
  8. (stack-ref 1)
  9. (stored-object-length
  10. ,(enumerand->name i stob))
  11. (push)
  12. (literal 2)
  13. (push)
  14. (arithmetic-shift)
  15. (return))
  16. (interaction-environment))
  17. l)))
  18. ((< i 0) l)))
  19. (define (space)
  20. (collect)
  21. (display " pure impure total") (newline)
  22. (display " count bytes count bytes count bytes")
  23. (newline)
  24. (let loop ((i 0)
  25. (p-count-total 0)
  26. (p-bytes-total 0)
  27. (i-count-total 0)
  28. (i-bytes-total 0))
  29. (if (< i stob-count)
  30. (begin
  31. (collect)
  32. (let ((xs (find-all i))
  33. (length (list-ref length-procedures i)))
  34. (let loop2 ((j (- (vector-length xs) 1))
  35. (p-count 0)
  36. (i-count 0)
  37. (p-bytes 0)
  38. (i-bytes 0))
  39. (if (< j 0)
  40. (begin (report1 (enumerand->name i stob)
  41. p-count p-bytes
  42. i-count i-bytes)
  43. (loop (+ i 1)
  44. (+ p-count-total p-count)
  45. (+ p-bytes-total p-bytes)
  46. (+ i-count-total i-count)
  47. (+ i-bytes-total i-bytes)))
  48. (if (immutable? (vector-ref xs j))
  49. (loop2 (- j 1)
  50. (+ p-count 1)
  51. i-count
  52. (+ p-bytes (+ 4 (length (vector-ref xs j))))
  53. i-bytes)
  54. (loop2 (- j 1)
  55. p-count
  56. (+ i-count 1)
  57. p-bytes
  58. (+ i-bytes (+ 4 (length (vector-ref xs j))))))))))
  59. (report1 'total
  60. p-count-total p-bytes-total
  61. i-count-total i-bytes-total))))
  62. (define (report1 name p-count p-bytes i-count i-bytes)
  63. (write-padded name 16)
  64. (write-padded p-count 7)
  65. (write-padded p-bytes 7)
  66. (write-padded i-count 7)
  67. (write-padded i-bytes 7)
  68. (write-padded (+ p-count i-count) 7)
  69. (write-padded (+ p-bytes i-bytes) 8)
  70. (newline))
  71. (define least-byte-type (enum stob string))
  72. (define (write-padded x pad)
  73. (let ((s (if (symbol? x)
  74. (symbol->string x)
  75. (number->string x))))
  76. (display (make-string (- pad (string-length s)) #\space))
  77. (display s)))
  78. (define (record-space . pred-option)
  79. (collect)
  80. (let ((pred (if (null? pred-option) (lambda (x) #t) (car pred-option)))
  81. (rs (find-all (enum stob record)))
  82. (a '()))
  83. (do ((i (- (vector-length rs) 1) (- i 1)))
  84. ((< i 0)
  85. (for-each (lambda (z)
  86. (write-padded (cadr z) 7)
  87. (write-padded (* (caddr z) 4) 7)
  88. (display " ")
  89. (write (car z))
  90. (newline))
  91. (sort-list a (lambda (z1 z2)
  92. (> (caddr z1) (caddr z2))))))
  93. (let* ((r (vector-ref rs i))
  94. (probe (assq (record-ref r 0) a)))
  95. (if (pred r)
  96. (if probe
  97. (begin (set-car! (cdr probe) (+ (cadr probe) 1))
  98. (set-car! (cddr probe) (+ (caddr probe)
  99. (+ 1 (record-length r)))))
  100. (set! a (cons (list (record-ref r 0) 1 (+ 1 (record-length r)))
  101. a))))))))
  102. (define (vector-space . pred-option)
  103. (collect)
  104. (let ((pred (if (null? pred-option) (lambda (x) #t) (car pred-option)))
  105. (vs (find-all (enum stob vector))))
  106. (let ((e-count 0)
  107. (e-bytes 0)
  108. (t-count 0)
  109. (t-bytes 0)
  110. (b-count 0)
  111. (b-bytes 0)
  112. (v-count 0)
  113. (v-bytes 0)
  114. (l-count 0)
  115. (l-bytes 0)
  116. (o-count 0)
  117. (o-bytes 0))
  118. (let loop ((i (- (vector-length vs) 1)))
  119. (if (< i 0)
  120. (let ((fz (lambda (k b what)
  121. (write-padded k 7)
  122. (write-padded b 7)
  123. (display what)
  124. (newline))))
  125. (fz t-count t-bytes " table buckets")
  126. (fz e-count e-bytes " table entries")
  127. (fz b-count b-bytes " bindings")
  128. (fz v-count v-bytes " environment info")
  129. (fz l-count l-bytes " lexical environments")
  130. (fz o-count o-bytes " other"))
  131. (let* ((v (vector-ref vs i))
  132. (len (vector-length v))
  133. (bytes (* (+ len 1) 4)))
  134. (cond ((not (pred v)))
  135. ((and (= len 3)
  136. (bucket? (vector-ref v 2)))
  137. (set! e-count (+ e-count 1))
  138. (set! e-bytes (+ e-bytes bytes)))
  139. ((and (= len 3)
  140. (location? (vector-ref v 1)))
  141. (set! b-count (+ b-count 1))
  142. (set! b-bytes (+ b-bytes bytes)))
  143. ((vector-every bucket? v)
  144. (set! t-count (+ t-count 1))
  145. (set! t-bytes (+ t-bytes bytes)))
  146. ((or (and (= len 4)
  147. (integer? (vector-ref v 0))
  148. (list? (vector-ref v 3)))
  149. (vector-every symbol? v))
  150. (set! v-count (+ v-count 1))
  151. (set! v-bytes (+ v-bytes bytes)))
  152. ((and (> len 1)
  153. (or (vector? (vector-ref v 0))
  154. (integer? (vector-ref v 0))))
  155. (set! l-count (+ l-count 1))
  156. (set! l-bytes (+ l-bytes bytes)))
  157. (else
  158. ;;(if (= (remainder i 197) 0)
  159. ;; (begin (write v) (newline)))
  160. (set! o-count (+ o-count 1))
  161. (set! o-bytes (+ o-bytes bytes))))
  162. (loop (- i 1))))))))
  163. (define (bucket? x)
  164. (or (eq? x #f)
  165. (vector? x)))
  166. (define (vector-every pred v)
  167. (let loop ((i (- (vector-length v) 1)))
  168. (if (< i 0)
  169. #t
  170. (if (pred (vector-ref v i))
  171. (loop (- i 1))
  172. #f))))
  173. (define (mutable? x) (not (immutable? x)))
  174. ; Print a random sampling of mutable pairs.
  175. (define (pair-space)
  176. (collect)
  177. (let ((vs (find-all (enum stob pair))))
  178. (let loop ((i (- (vector-length vs) 1))
  179. (j 0))
  180. (if (>= i 0)
  181. (let ((x (vector-ref vs i)))
  182. (if (mutable? x)
  183. (begin (if (= (remainder j 293) 0)
  184. (begin (limited-write x (current-output-port) 4 4)
  185. (newline)))
  186. (loop (- i 1) (+ j 1)))
  187. (loop (- i 1) j)))))))