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)
|
|
142 (when (string-match "\\(.*\\)-storage$"
|
|
143 (symbol-name stat))
|
|
144 (incf total num)
|
|
145 (princ (format fmt
|
|
146 (match-string 1 (symbol-name stat))
|
|
147 num)))
|
|
148 (when (eq stat 'long-strings-total-length)
|
|
149 (incf total num)
|
|
150 (princ (format fmt stat num))))
|
|
151 (sixth (garbage-collect)))
|
|
152 (princ "\n")
|
|
153 (princ (format fmt "total" total))
|
|
154 (incf grandtotal total))
|
|
155 (sort-numeric-fields -1
|
|
156 (save-excursion
|
|
157 (goto-char begin)
|
|
158 (forward-line 2)
|
|
159 (point))
|
|
160 (save-excursion
|
|
161 (forward-line -2)
|
|
162 (point)))
|
787
|
163
|
2618
|
164 (princ (format "\n\ngrand total: %s\n" grandtotal)))
|
787
|
165 grandtotal))))
|