2618
|
1 ;;; diagnose.el --- routines for debugging problems in XEmacs
|
787
|
2
|
|
3 ;; Copyright (C) 2002 Ben Wing.
|
|
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)
|
|
38 (flet ((show-foo-stats (objtypename objlist memfun)
|
|
39 (let* ((hash (make-hash-table))
|
|
40 (first t)
|
|
41 types fmt
|
|
42 (objnamelen 25)
|
|
43 (linelen objnamelen)
|
|
44 (totaltotal 0))
|
|
45 (dolist (obj objlist)
|
|
46 (let ((total 0)
|
|
47 (stats (funcall memfun obj)))
|
|
48 (loop for (type . num) in stats while type do
|
|
49 (puthash type (+ num (or (gethash type hash) 0)) hash)
|
|
50 (incf total num)
|
|
51 (if first (push type types)))
|
|
52 (incf totaltotal total)
|
|
53 (when first
|
|
54 (setq types (nreverse types))
|
|
55 (setq fmt (concat
|
|
56 (format "%%-%ds" objnamelen)
|
|
57 (mapconcat
|
|
58 #'(lambda (type)
|
|
59 (let ((fieldlen
|
|
60 (max 8 (+ 2 (length
|
|
61 (symbol-name type))))))
|
|
62 (incf linelen fieldlen)
|
|
63 (format "%%%ds" fieldlen)))
|
|
64 types "")
|
2618
|
65 (progn (incf linelen 9) "%9s\n")))
|
787
|
66 (princ "\n")
|
|
67 (princ (apply 'format fmt objtypename
|
|
68 (append types (list 'total))))
|
|
69 (princ (make-string linelen ?-))
|
|
70 (princ "\n"))
|
|
71 (let ((objname (format "%s" obj)))
|
|
72 (princ (apply 'format fmt (substring objname 0
|
|
73 (min (length objname)
|
|
74 (1- objnamelen)))
|
|
75 (nconc (mapcar #'(lambda (type)
|
|
76 (cdr (assq type stats)))
|
|
77 types)
|
|
78 (list total)))))
|
|
79 (setq first nil)))
|
|
80 (princ "\n")
|
|
81 (princ (apply 'format fmt "total"
|
|
82 (nconc (mapcar #'(lambda (type)
|
|
83 (gethash type hash))
|
|
84 types)
|
|
85 (list totaltotal))))
|
|
86 totaltotal)))
|
|
87
|
2618
|
88 (let ((grandtotal 0)
|
|
89 (buffer "*memory usage*")
|
|
90 begin)
|
|
91 (with-output-to-temp-buffer buffer
|
|
92 (save-excursion
|
|
93 (set-buffer buffer)
|
|
94 (when-fboundp 'charset-list
|
|
95 (setq begin (point))
|
|
96 (incf grandtotal
|
|
97 (show-foo-stats 'charset (charset-list)
|
|
98 #'charset-memory-usage))
|
|
99 (sort-numeric-fields -1
|
|
100 (save-excursion
|
|
101 (goto-char begin)
|
|
102 (forward-line 2)
|
|
103 (point))
|
|
104 (save-excursion
|
|
105 (forward-line -2)
|
|
106 (point)))
|
|
107 (princ "\n"))
|
|
108 (setq begin (point))
|
|
109 (incf grandtotal
|
|
110 (show-foo-stats 'buffer (buffer-list) #'buffer-memory-usage))
|
|
111 (sort-numeric-fields -1
|
|
112 (save-excursion
|
|
113 (goto-char begin)
|
|
114 (forward-line 3)
|
|
115 (point))
|
|
116 (save-excursion
|
|
117 (forward-line -2)
|
|
118 (point)))
|
|
119 (princ "\n")
|
|
120 (setq begin (point))
|
787
|
121 (incf grandtotal
|
2618
|
122 (show-foo-stats 'window (mapcan #'(lambda (fr)
|
|
123 (window-list fr t))
|
|
124 (frame-list))
|
|
125 #'window-memory-usage))
|
|
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)))
|
787
|
134 (princ "\n")
|
2618
|
135 (let ((total 0)
|
|
136 (fmt "%-30s%10s\n"))
|
|
137 (setq begin (point))
|
|
138 (princ (format fmt "object" "storage"))
|
|
139 (princ (make-string 40 ?-))
|
|
140 (princ "\n")
|
|
141 (map-plist #'(lambda (stat num)
|
2775
|
142 (when (string-match
|
|
143 "\\(.*\\)-storage\\(-additional\\)?$"
|
|
144 (symbol-name stat))
|
2618
|
145 (incf total num)
|
|
146 (princ (format fmt
|
|
147 (match-string 1 (symbol-name stat))
|
|
148 num)))
|
|
149 (when (eq stat 'long-strings-total-length)
|
|
150 (incf total num)
|
|
151 (princ (format fmt stat num))))
|
|
152 (sixth (garbage-collect)))
|
|
153 (princ "\n")
|
|
154 (princ (format fmt "total" total))
|
|
155 (incf grandtotal total))
|
|
156 (sort-numeric-fields -1
|
|
157 (save-excursion
|
|
158 (goto-char begin)
|
|
159 (forward-line 2)
|
|
160 (point))
|
|
161 (save-excursion
|
|
162 (forward-line -2)
|
|
163 (point)))
|
787
|
164
|
2618
|
165 (princ (format "\n\ngrand total: %s\n" grandtotal)))
|
787
|
166 grandtotal))))
|
2720
|
167
|
|
168
|
2775
|
169 (defun show-lrecord-stats ()
|
|
170 "Show statistics about lrecord usage in XEmacs."
|
|
171 (interactive)
|
|
172 (garbage-collect)
|
|
173 (let ((buffer "*lrecord statistics*")
|
|
174 (plist (lrecord-stats))
|
|
175 (fmt "%-30s%10s%10s\n")
|
|
176 (grandtotal 0)
|
|
177 begin)
|
|
178 (flet ((show-stats (match-string)
|
|
179 (princ (format fmt "object" "count" "storage"))
|
|
180 (princ (make-string 50 ?-))
|
|
181 (princ "\n")
|
|
182 (let ((total-use 0)
|
|
183 (total-use-overhead 0)
|
|
184 (total-count 0))
|
|
185 (map-plist
|
|
186 #'(lambda (stat num)
|
|
187 (when (string-match match-string
|
|
188 (symbol-name stat))
|
|
189 (let ((storage-use num)
|
|
190 (storage-use-overhead
|
|
191 (plist-get
|
|
192 plist
|
|
193 (intern (concat (match-string 1 (symbol-name stat))
|
|
194 "-storage-including-overhead"))))
|
|
195 (storage-count
|
|
196 (or (plist-get
|
|
197 plist
|
|
198 (intern
|
|
199 (concat (match-string 1 (symbol-name stat))
|
|
200 "s-used")))
|
|
201 (plist-get
|
|
202 plist
|
|
203 (intern
|
|
204 (concat (match-string 1 (symbol-name stat))
|
|
205 "es-used")))
|
|
206 (plist-get
|
|
207 plist
|
|
208 (intern
|
|
209 (concat (match-string 1 (symbol-name stat))
|
|
210 "-used"))))))
|
|
211 (incf total-use storage-use)
|
|
212 (incf total-use-overhead (if storage-use-overhead
|
|
213 storage-use-overhead
|
|
214 storage-use))
|
|
215 (incf total-count storage-count)
|
|
216 (princ (format fmt
|
|
217 (match-string 1 (symbol-name stat))
|
|
218 storage-count storage-use)))))
|
|
219 plist)
|
|
220 (princ "\n")
|
|
221 (princ (format fmt "total"
|
|
222 total-count total-use-overhead))
|
|
223 (incf grandtotal total-use-overhead)
|
|
224 (sort-numeric-fields -1
|
|
225 (save-excursion
|
|
226 (goto-char begin)
|
|
227 (forward-line 2)
|
|
228 (point))
|
|
229 (save-excursion
|
|
230 (forward-line -2)
|
|
231 (point))))))
|
|
232 (with-output-to-temp-buffer buffer
|
|
233 (save-excursion
|
|
234 (set-buffer buffer)
|
|
235 (setq begin (point))
|
|
236 (princ "Allocated with new allocator:\n")
|
|
237 (show-stats "\\(.*\\)-storage$")
|
|
238 (princ "\n\n")
|
|
239 (setq begin (point))
|
|
240 (princ "Allocated additionally:\n")
|
|
241 (show-stats "\\(.*\\)-storage-additional$")
|
|
242 (princ (format "\n\ngrand total: %s\n" grandtotal)))
|
|
243 grandtotal))))
|
|
244
|
|
245
|
2720
|
246 (defun show-mc-alloc-memory-usage ()
|
|
247 "Show statistics about memory usage of the new allocator."
|
|
248 (interactive)
|
|
249 (garbage-collect)
|
|
250 (let* ((stats (mc-alloc-memory-usage))
|
|
251 (page-size (first stats))
|
|
252 (heap-sects (second stats))
|
|
253 (used-plhs (third stats))
|
|
254 (unmanaged-plhs (fourth stats))
|
|
255 (free-plhs (fifth stats))
|
|
256 (globals (sixth stats))
|
|
257 (mc-malloced-bytes (seventh stats)))
|
|
258 (with-output-to-temp-buffer "*memory usage*"
|
|
259 (flet ((print-used-plhs (text plhs)
|
|
260 (let ((sum-n-pages 0)
|
|
261 (sum-used-n-cells 0)
|
|
262 (sum-used-space 0)
|
|
263 (sum-used-total 0)
|
|
264 (sum-total-n-cells 0)
|
|
265 (sum-total-space 0)
|
|
266 (sum-total-total 0)
|
|
267 (fmt "%7s%7s|%7s%9s%9s%4s|%7s%9s%9s%4s|%4s\n"))
|
|
268 (princ (format "%-14s|%-29s|%-29s|\n"
|
|
269 text
|
|
270 " currently in use"
|
|
271 " total available"))
|
|
272 (princ (format fmt "cell-sz" "#pages"
|
|
273 "#cells" "space" "total" "% "
|
|
274 "#cells" "space" "total" "% " "% "))
|
|
275 (princ (make-string 79 ?-))
|
|
276 (princ "\n")
|
|
277 (while plhs
|
|
278 (let* ((elem (car plhs))
|
|
279 (cell-size (first elem))
|
|
280 (n-pages (second elem))
|
|
281 (used-n-cells (third elem))
|
|
282 (used-space (fourth elem))
|
|
283 (used-total (if (zerop cell-size)
|
|
284 (sixth elem)
|
|
285 (* cell-size used-n-cells)))
|
|
286 (used-eff (floor (if (not (zerop used-total))
|
|
287 (* (/ (* used-space 1.0)
|
|
288 (* used-total 1.0))
|
|
289 100.0)
|
|
290 0)))
|
|
291 (total-n-cells (fifth elem))
|
|
292 (total-space (if (zerop cell-size)
|
|
293 used-space
|
|
294 (* cell-size total-n-cells)))
|
|
295 (total-total (sixth elem))
|
|
296 (total-eff (floor (if (not (zerop total-total))
|
|
297 (* (/ (* total-space 1.0)
|
|
298 (* total-total 1.0))
|
|
299 100.0)
|
|
300 0)))
|
|
301 (eff (floor (if (not (zerop total-total))
|
|
302 (* (/ (* used-space 1.0)
|
|
303 (* total-total 1.0))
|
|
304 100.0)
|
|
305 0))))
|
|
306 (princ (format fmt
|
|
307 cell-size n-pages used-n-cells used-space
|
|
308 used-total used-eff total-n-cells
|
|
309 total-space total-total total-eff eff))
|
|
310 (incf sum-n-pages n-pages)
|
|
311 (incf sum-used-n-cells used-n-cells)
|
|
312 (incf sum-used-space used-space)
|
|
313 (incf sum-used-total used-total)
|
|
314 (incf sum-total-n-cells total-n-cells)
|
|
315 (incf sum-total-space total-space)
|
|
316 (incf sum-total-total total-total))
|
|
317 (setq plhs (cdr plhs)))
|
|
318 (let ((avg-used-eff (floor (if (not (zerop sum-used-total))
|
|
319 (* (/ (* sum-used-space 1.0)
|
|
320 (* sum-used-total 1.0))
|
|
321 100.0)
|
|
322 0)))
|
|
323 (avg-total-eff (floor (if (not (zerop sum-total-total))
|
|
324 (* (/ (* sum-total-space 1.0)
|
|
325 (* sum-total-total 1.0))
|
|
326 100.0)
|
|
327 0)))
|
|
328 (avg-eff (floor (if (not (zerop sum-total-total))
|
|
329 (* (/ (* sum-used-space 1.0)
|
|
330 (* sum-total-total 1.0))
|
|
331 100.0)
|
|
332 0))))
|
|
333 (princ (format fmt "sum " sum-n-pages sum-used-n-cells
|
|
334 sum-used-space sum-used-total avg-used-eff
|
|
335 sum-total-n-cells sum-total-space
|
|
336 sum-total-total avg-total-eff avg-eff))
|
|
337 (princ "\n"))))
|
|
338
|
|
339
|
|
340 (print-free-plhs (text plhs)
|
|
341 (let ((sum-n-pages 0)
|
|
342 (sum-n-sects 0)
|
|
343 (sum-space 0)
|
|
344 (sum-total 0)
|
|
345 (fmt "%6s%10s |%7s%10s\n"))
|
|
346 (princ (format "%s\n" text))
|
|
347 (princ (format fmt "#pages" "space" "#sects" "total"))
|
|
348 (princ (make-string 35 ?-))
|
|
349 (princ "\n")
|
|
350 (while plhs
|
|
351 (let* ((elem (car plhs))
|
|
352 (n-pages (first elem))
|
|
353 (n-sects (second elem))
|
|
354 (space (* n-pages page-size))
|
|
355 (total (* n-sects space)))
|
|
356 (princ (format fmt n-pages space n-sects total))
|
|
357 (incf sum-n-pages n-pages)
|
|
358 (incf sum-n-sects n-sects)
|
|
359 (incf sum-space space)
|
|
360 (incf sum-total total))
|
|
361 (setq plhs (cdr plhs)))
|
|
362 (princ (make-string 35 ?=))
|
|
363 (princ "\n")
|
|
364 (princ (format fmt sum-n-pages sum-space
|
|
365 sum-n-sects sum-total))
|
|
366 (princ "\n"))))
|
|
367
|
|
368 (princ (format "%-12s%10s\n\n" "PAGE_SIZE" page-size))
|
|
369
|
|
370 (print-used-plhs "USED HEAP" used-plhs)
|
|
371 (princ "\n\n")
|
|
372
|
|
373 (print-used-plhs "UNMANAGED HEAP" unmanaged-plhs)
|
|
374 (princ "\n\n")
|
|
375
|
|
376 (print-free-plhs "FREE HEAP" free-plhs)
|
|
377 (princ "\n\n")
|
|
378
|
|
379 (let ((fmt "%-30s%10s\n"))
|
|
380 (princ (format fmt "heap sections" ""))
|
|
381 (princ (make-string 40 ?-))
|
|
382 (princ "\n")
|
|
383 (princ (format fmt "number of heap sects"
|
|
384 (first heap-sects)))
|
|
385 (princ (format fmt "used size" (second heap-sects)))
|
|
386 (princ (make-string 40 ?-))
|
|
387 (princ "\n")
|
|
388 (princ (format fmt "real size" (third heap-sects)))
|
|
389 (princ (format fmt "global allocator structs" globals))
|
|
390 (princ (make-string 40 ?-))
|
|
391 (princ "\n")
|
|
392 (princ (format fmt "real size + structs"
|
|
393 (+ (third heap-sects) globals)))
|
|
394 (princ "\n")
|
|
395 (princ (make-string 40 ?=))
|
|
396 (princ "\n")
|
|
397 (princ (format fmt "grand total" mc-malloced-bytes)))
|
|
398
|
|
399 (+ mc-malloced-bytes)))))
|