Mercurial > hg > xemacs-beta
annotate lisp/diagnose.el @ 5238:2cc24c69446c
Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
author | Marcus Crestani <crestani@informatik.uni-tuebingen.de> |
---|---|
date | Mon, 05 Jul 2010 18:17:39 +0200 |
parents | 4c56e7c6a704 |
children | ed74d2ca7082 308d34e9f07d |
rev | line source |
---|---|
2618 | 1 ;;; diagnose.el --- routines for debugging problems in XEmacs |
787 | 2 |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
3 ;; Copyright (C) 2002, 2010 Ben Wing. |
787 | 4 |
5 ;; Maintainer: XEmacs Development Team | |
6 ;; Keywords: dumped | |
7 | |
8 ;; This file is part of XEmacs. | |
9 | |
10 ;; XEmacs is free software; you can redistribute it and/or modify it | |
11 ;; under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; XEmacs is distributed in the hope that it will be useful, but | |
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 ;; General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
23 ;; 02111-1307, USA. | |
24 | |
25 ;;; Synched up with: Not in FSF. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; This file is dumped with XEmacs. | |
30 | |
31 ;;; Code: | |
32 | |
33 | |
34 (defun show-memory-usage () | |
35 "Show statistics about memory usage of various sorts in XEmacs." | |
36 (interactive) | |
37 (garbage-collect) | |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
38 (flet ((show-foo-stats (objtypename statname-plist cleanfun objlist |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
39 &optional objnamelen) |
787 | 40 (let* ((hash (make-hash-table)) |
41 (first t) | |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
42 types origtypes fmt |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
43 (objnamelen (or objnamelen 25)) |
787 | 44 (linelen objnamelen) |
45 (totaltotal 0)) | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
46 (loop for obj in objlist do |
787 | 47 (let ((total 0) |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
48 (stats (object-memory-usage obj))) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
49 ;; Pop off the slice describing the object itself's |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
50 ;; memory |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
51 (while (and stats (not (eq t (pop stats))))) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
52 ;; Pop off the slice describing the associated |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
53 ;; non-Lisp-Object memory from the allocation |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
54 ;; perspective, so we can get to the slice describing |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
55 ;; the memory grouped by type |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
56 (while (and stats (pop stats))) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
57 |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
58 (loop for (type . num) in (remq t stats) while type do |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
59 (if first (push type origtypes)) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
60 (setq type (getf statname-plist type type)) |
787 | 61 (puthash type (+ num (or (gethash type hash) 0)) hash) |
62 (incf total num) | |
63 (if first (push type types))) | |
64 (incf totaltotal total) | |
65 (when first | |
66 (setq types (nreverse types)) | |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
67 (setq origtypes (nreverse origtypes)) |
787 | 68 (setq fmt (concat |
69 (format "%%-%ds" objnamelen) | |
70 (mapconcat | |
71 #'(lambda (type) | |
72 (let ((fieldlen | |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
73 (max 7 (+ 2 (length |
787 | 74 (symbol-name type)))))) |
75 (incf linelen fieldlen) | |
76 (format "%%%ds" fieldlen))) | |
77 types "") | |
2618 | 78 (progn (incf linelen 9) "%9s\n"))) |
787 | 79 (princ "\n") |
80 (princ (apply 'format fmt objtypename | |
81 (append types (list 'total)))) | |
82 (princ (make-string linelen ?-)) | |
83 (princ "\n")) | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
84 (let ((objname (format "%s" (funcall cleanfun obj)))) |
787 | 85 (princ (apply 'format fmt (substring objname 0 |
86 (min (length objname) | |
87 (1- objnamelen))) | |
88 (nconc (mapcar #'(lambda (type) | |
89 (cdr (assq type stats))) | |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
90 origtypes) |
787 | 91 (list total))))) |
92 (setq first nil))) | |
93 (princ "\n") | |
94 (princ (apply 'format fmt "total" | |
95 (nconc (mapcar #'(lambda (type) | |
96 (gethash type hash)) | |
97 types) | |
98 (list totaltotal)))) | |
99 totaltotal))) | |
100 | |
2618 | 101 (let ((grandtotal 0) |
102 (buffer "*memory usage*") | |
103 begin) | |
104 (with-output-to-temp-buffer buffer | |
105 (save-excursion | |
106 (set-buffer buffer) | |
107 (when-fboundp 'charset-list | |
108 (setq begin (point)) | |
109 (incf grandtotal | |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
110 (show-foo-stats 'charset nil 'charset-name |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
111 (mapcar 'get-charset (charset-list)))) |
3066 | 112 (when-fboundp 'sort-numeric-fields |
113 (sort-numeric-fields -1 | |
114 (save-excursion | |
115 (goto-char begin) | |
116 (forward-line 2) | |
117 (point)) | |
118 (save-excursion | |
119 (forward-line -2) | |
120 (point)))) | |
2618 | 121 (princ "\n")) |
122 (setq begin (point)) | |
123 (incf grandtotal | |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
124 (show-foo-stats 'buffer nil 'buffer-name (buffer-list))) |
3066 | 125 (when-fboundp 'sort-numeric-fields |
126 (sort-numeric-fields -1 | |
127 (save-excursion | |
128 (goto-char begin) | |
129 (forward-line 3) | |
130 (point)) | |
131 (save-excursion | |
132 (forward-line -2) | |
133 (point)))) | |
2618 | 134 (princ "\n") |
135 (setq begin (point)) | |
787 | 136 (incf grandtotal |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
137 (show-foo-stats 'window |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
138 '(line-start-cache line-st. |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
139 face-cache face |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
140 glyph-cache glyph |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
141 redisplay-structs redisplay |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
142 scrollbar-instances scrollbar |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
143 window-mirror mirror) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
144 #'(lambda (x) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
145 (buffer-name (window-buffer x))) |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
146 (mapcan #'(lambda (fr) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
147 (window-list fr t)) |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
148 (frame-list)) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
149 16)) |
4103 | 150 (when-fboundp #'sort-numeric-fields |
151 (sort-numeric-fields -1 | |
152 (save-excursion | |
153 (goto-char begin) | |
154 (forward-line 3) | |
155 (point)) | |
156 (save-excursion | |
157 (forward-line -2) | |
158 (point)))) | |
787 | 159 (princ "\n") |
2618 | 160 (let ((total 0) |
161 (fmt "%-30s%10s\n")) | |
162 (setq begin (point)) | |
163 (princ (format fmt "object" "storage")) | |
164 (princ (make-string 40 ?-)) | |
165 (princ "\n") | |
166 (map-plist #'(lambda (stat num) | |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
167 (when (and |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
168 (not |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
169 (string-match |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
170 "\\(.*\\)-ancillary-storage$" |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
171 (symbol-name stat))) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
172 (string-match |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
173 "\\(.*\\)-storage$" |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
174 (symbol-name stat))) |
2618 | 175 (incf total num) |
176 (princ (format fmt | |
177 (match-string 1 (symbol-name stat)) | |
178 num))) | |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
179 ) |
2618 | 180 (sixth (garbage-collect))) |
181 (princ "\n") | |
182 (princ (format fmt "total" total)) | |
183 (incf grandtotal total)) | |
4103 | 184 (when-fboundp #'sort-numeric-fields |
185 (sort-numeric-fields -1 | |
186 (save-excursion | |
187 (goto-char begin) | |
188 (forward-line 2) | |
189 (point)) | |
190 (save-excursion | |
191 (forward-line -2) | |
192 (point)))) | |
787 | 193 |
2618 | 194 (princ (format "\n\ngrand total: %s\n" grandtotal))) |
787 | 195 grandtotal)))) |
2720 | 196 |
197 | |
3041 | 198 (defun show-object-memory-usage-stats () |
3888 | 199 "Show statistics about object memory usage in XEmacs." |
2775 | 200 (interactive) |
201 (garbage-collect) | |
3041 | 202 (let ((buffer "*object memory usage statistics*") |
203 (plist (object-memory-usage-stats)) | |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
204 (fmt "%-28s%10s%10s%10s%10s%10s\n") |
2775 | 205 (grandtotal 0) |
206 begin) | |
207 (flet ((show-stats (match-string) | |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
208 (princ (format "%28s%10s%40s\n" "" "" |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
209 "--------------storage---------------")) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
210 (princ (format fmt "object" "count" "object" "overhead" |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
211 "non-Lisp" "ancillary")) |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
212 (princ (make-string 78 ?-)) |
2775 | 213 (princ "\n") |
214 (let ((total-use 0) | |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
215 (total-non-lisp-use 0) |
2775 | 216 (total-use-overhead 0) |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
217 (total-use-with-overhead 0) |
2775 | 218 (total-count 0)) |
219 (map-plist | |
220 #'(lambda (stat num) | |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
221 (let ((symmatch |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
222 (and (string-match match-string (symbol-name stat)) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
223 (match-string 1 (symbol-name stat))))) |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
224 (when (and symmatch |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
225 (or (< (length symmatch) 9) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
226 (not (equal (substring symmatch -9) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
227 "-non-lisp"))) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
228 (or (< (length symmatch) 15) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
229 (not (equal (substring symmatch -15) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
230 "-lisp-ancillary")))) |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
231 (let* ((storage-use num) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
232 (storage-use-overhead |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
233 (or (plist-get |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
234 plist |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
235 (intern (concat symmatch |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
236 "-storage-overhead"))) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
237 0)) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
238 (storage-use-with-overhead |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
239 (or (plist-get |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
240 plist |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
241 (intern (concat |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
242 symmatch |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
243 "-storage-including-overhead"))) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
244 (+ storage-use storage-use-overhead))) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
245 (storage-use-overhead |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
246 (- storage-use-with-overhead storage-use)) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
247 (non-lisp-storage |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
248 (or (plist-get |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
249 plist |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
250 (intern (concat symmatch |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
251 "-non-lisp-storage"))) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
252 0)) |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
253 (lisp-ancillary-storage |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
254 (or (plist-get |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
255 plist |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
256 (intern (concat symmatch |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
257 "-lisp-ancillary-storage"))) |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
258 0)) |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
259 (storage-count |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
260 (or (loop for str in '("s-used" "es-used" "-used") |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
261 for val = (plist-get |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
262 plist |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
263 (intern |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
264 (concat symmatch str))) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
265 if val |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
266 return val) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
267 (plist-get |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
268 plist |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
269 (intern |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
270 (concat (substring symmatch 0 -1) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
271 "ies-used"))) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
272 ))) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
273 (incf total-use storage-use) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
274 (incf total-use-overhead storage-use-overhead) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
275 (incf total-use-with-overhead storage-use-with-overhead) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
276 (incf total-non-lisp-use non-lisp-storage) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
277 (incf total-count (or storage-count 0)) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
278 (and (> storage-use-with-overhead 0) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
279 (princ (format fmt symmatch |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
280 (or storage-count "unknown") |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
281 storage-use |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
282 storage-use-overhead |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
283 non-lisp-storage |
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
284 lisp-ancillary-storage))))))) |
2775 | 285 plist) |
286 (princ "\n") | |
287 (princ (format fmt "total" | |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
288 total-count total-use total-use-overhead |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
289 total-non-lisp-use "")) |
5160
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
290 (incf grandtotal total-use-with-overhead) |
ab9ee10a53e4
fix various problems with allocation statistics, track overhead properly
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
291 (incf grandtotal total-non-lisp-use) |
4103 | 292 (when-fboundp #'sort-numeric-fields |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
293 (sort-numeric-fields -4 |
4103 | 294 (save-excursion |
295 (goto-char begin) | |
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5160
diff
changeset
|
296 (forward-line 4) |
4103 | 297 (point)) |
298 (save-excursion | |
299 (forward-line -2) | |
300 (point))))))) | |
2775 | 301 (with-output-to-temp-buffer buffer |
302 (save-excursion | |
303 (set-buffer buffer) | |
304 (setq begin (point)) | |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
305 (princ "Allocated with lisp allocator or related:\n") |
2775 | 306 (show-stats "\\(.*\\)-storage$") |
307 (princ (format "\n\ngrand total: %s\n" grandtotal))) | |
308 grandtotal)))) | |
309 | |
310 | |
2720 | 311 (defun show-mc-alloc-memory-usage () |
312 "Show statistics about memory usage of the new allocator." | |
313 (interactive) | |
314 (garbage-collect) | |
4103 | 315 (if-fboundp #'mc-alloc-memory-usage |
316 (let* ((stats (mc-alloc-memory-usage)) | |
317 (page-size (first stats)) | |
318 (heap-sects (second stats)) | |
319 (used-plhs (third stats)) | |
320 (free-plhs (fourth stats)) | |
321 (globals (fifth stats)) | |
322 (mc-malloced-bytes (sixth stats))) | |
323 (with-output-to-temp-buffer "*mc-alloc memory usage*" | |
324 (flet ((print-used-plhs (text plhs) | |
325 (let ((sum-n-pages 0) | |
326 (sum-used-n-cells 0) | |
327 (sum-used-space 0) | |
328 (sum-used-total 0) | |
329 (sum-total-n-cells 0) | |
330 (sum-total-space 0) | |
331 (sum-total-total 0) | |
332 (fmt "%7s%7s|%7s%9s%9s%4s|%7s%9s%9s%4s|%4s\n")) | |
333 (princ (format "%-14s|%-29s|%-29s|\n" | |
334 text | |
335 " currently in use" | |
336 " total available")) | |
337 (princ (format fmt "cell-sz" "#pages" | |
338 "#cells" "space" "total" "% " | |
339 "#cells" "space" "total" "% " "% ")) | |
340 (princ (make-string 79 ?-)) | |
341 (princ "\n") | |
342 (while plhs | |
343 (let* ((elem (car plhs)) | |
344 (cell-size (first elem)) | |
345 (n-pages (second elem)) | |
346 (used-n-cells (third elem)) | |
347 (used-space (fourth elem)) | |
348 (used-total (if (zerop cell-size) | |
349 (sixth elem) | |
350 (* cell-size used-n-cells))) | |
351 (used-eff (floor (if (not (zerop used-total)) | |
352 (* (/ (* used-space 1.0) | |
353 (* used-total 1.0)) | |
354 100.0) | |
355 0))) | |
356 (total-n-cells (fifth elem)) | |
357 (total-space (if (zerop cell-size) | |
358 used-space | |
359 (* cell-size total-n-cells))) | |
360 (total-total (sixth elem)) | |
361 (total-eff (floor (if (not (zerop total-total)) | |
362 (* (/ (* total-space 1.0) | |
363 (* total-total 1.0)) | |
364 100.0) | |
365 0))) | |
366 (eff (floor (if (not (zerop total-total)) | |
367 (* (/ (* used-space 1.0) | |
368 (* total-total 1.0)) | |
369 100.0) | |
370 0)))) | |
371 (princ (format fmt | |
372 cell-size n-pages used-n-cells used-space | |
373 used-total used-eff total-n-cells | |
374 total-space total-total total-eff eff)) | |
375 (incf sum-n-pages n-pages) | |
376 (incf sum-used-n-cells used-n-cells) | |
377 (incf sum-used-space used-space) | |
378 (incf sum-used-total used-total) | |
379 (incf sum-total-n-cells total-n-cells) | |
380 (incf sum-total-space total-space) | |
381 (incf sum-total-total total-total)) | |
382 (setq plhs (cdr plhs))) | |
383 (let ((avg-used-eff (floor (if (not (zerop sum-used-total)) | |
384 (* (/ (* sum-used-space 1.0) | |
385 (* sum-used-total 1.0)) | |
386 100.0) | |
387 0))) | |
388 (avg-total-eff (floor (if (not (zerop sum-total-total)) | |
389 (* (/ (* sum-total-space 1.0) | |
390 (* sum-total-total 1.0)) | |
391 100.0) | |
392 0))) | |
393 (avg-eff (floor (if (not (zerop sum-total-total)) | |
394 (* (/ (* sum-used-space 1.0) | |
395 (* sum-total-total 1.0)) | |
396 100.0) | |
397 0)))) | |
398 (princ (format fmt "sum " sum-n-pages sum-used-n-cells | |
399 sum-used-space sum-used-total avg-used-eff | |
400 sum-total-n-cells sum-total-space | |
401 sum-total-total avg-total-eff avg-eff)) | |
402 (princ "\n")))) | |
2720 | 403 |
404 | |
4103 | 405 (print-free-plhs (text plhs) |
406 (let ((sum-n-pages 0) | |
407 (sum-n-sects 0) | |
408 (sum-space 0) | |
409 (sum-total 0) | |
410 (fmt "%6s%10s |%7s%10s\n")) | |
411 (princ (format "%s\n" text)) | |
412 (princ (format fmt "#pages" "space" "#sects" "total")) | |
413 (princ (make-string 35 ?-)) | |
414 (princ "\n") | |
415 (while plhs | |
416 (let* ((elem (car plhs)) | |
417 (n-pages (first elem)) | |
418 (n-sects (second elem)) | |
419 (space (* n-pages page-size)) | |
420 (total (* n-sects space))) | |
421 (princ (format fmt n-pages space n-sects total)) | |
422 (incf sum-n-pages n-pages) | |
423 (incf sum-n-sects n-sects) | |
424 (incf sum-space space) | |
425 (incf sum-total total)) | |
426 (setq plhs (cdr plhs))) | |
427 (princ (make-string 35 ?=)) | |
428 (princ "\n") | |
429 (princ (format fmt sum-n-pages sum-space | |
430 sum-n-sects sum-total)) | |
431 (princ "\n")))) | |
2720 | 432 |
4103 | 433 (princ (format "%-12s%10s\n\n" "PAGE_SIZE" page-size)) |
2720 | 434 |
4103 | 435 (print-used-plhs "USED HEAP" used-plhs) |
436 (princ "\n\n") | |
2720 | 437 |
4103 | 438 (print-free-plhs "FREE HEAP" free-plhs) |
439 (princ "\n\n") | |
2720 | 440 |
4103 | 441 (let ((fmt "%-30s%10s\n")) |
442 (princ (format fmt "heap sections" "")) | |
443 (princ (make-string 40 ?-)) | |
444 (princ "\n") | |
445 (princ (format fmt "number of heap sects" | |
446 (first heap-sects))) | |
447 (princ (format fmt "used size" (second heap-sects))) | |
448 (princ (make-string 40 ?-)) | |
449 (princ "\n") | |
450 (princ (format fmt "real size" (third heap-sects))) | |
451 (princ (format fmt "global allocator structs" globals)) | |
452 (princ (make-string 40 ?-)) | |
453 (princ "\n") | |
454 (princ (format fmt "real size + structs" | |
455 (+ (third heap-sects) globals))) | |
456 (princ "\n") | |
457 (princ (make-string 40 ?=)) | |
458 (princ "\n") | |
459 (princ (format fmt "grand total" mc-malloced-bytes))) | |
2720 | 460 |
4103 | 461 (+ mc-malloced-bytes)))) |
462 (message "mc-alloc not used in this XEmacs."))) | |
3092 | 463 |
464 | |
465 (defun show-gc-stats () | |
466 "Show statistics about garbage collection cycles." | |
467 (interactive) | |
4103 | 468 (if-fboundp #'gc-stats |
469 (let ((buffer "*garbage collection statistics*") | |
470 (plist (gc-stats)) | |
471 (fmt "%-9s %16s %12s %12s %12s %12s\n")) | |
472 (flet ((plist-get-stat (category field) | |
473 (let ((stat (plist-get plist | |
474 (intern (concat category field))))) | |
475 (if stat | |
476 (format "%.0f" stat) | |
477 "-"))) | |
478 (show-stats (category) | |
479 (princ (format fmt category | |
480 (plist-get-stat category "-total") | |
481 (plist-get-stat category "-in-last-gc") | |
482 (plist-get-stat category "-in-this-gc") | |
483 (plist-get-stat category "-in-last-cycle") | |
484 (plist-get-stat category "-in-this-cycle"))))) | |
485 (with-output-to-temp-buffer buffer | |
486 (save-excursion | |
487 (set-buffer buffer) | |
488 (princ (format "%s %g\n" "Current phase" | |
489 (plist-get plist 'phase))) | |
490 (princ (make-string 78 ?-)) | |
491 (princ "\n") | |
492 (princ (format fmt "stat" "total" "last-gc" "this-gc" | |
5230
4c56e7c6a704
Fix a misspelling, diagnose.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5170
diff
changeset
|
493 "last-cycle" "this-cycle")) |
4103 | 494 (princ (make-string 78 ?-)) |
495 (princ "\n") | |
496 (show-stats "n-gc") | |
497 (show-stats "n-cycles") | |
498 (show-stats "enqueued") | |
499 (show-stats "dequeued") | |
500 (show-stats "repushed") | |
501 (show-stats "enqueued2") | |
502 (show-stats "dequeued2") | |
503 (show-stats "finalized") | |
504 (show-stats "freed") | |
505 (plist-get plist 'n-gc-total))))) | |
506 (error 'void-function "gc-stats not available."))) |