Mercurial > hg > xemacs-beta
annotate lisp/diagnose.el @ 5157:1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
-------------------- ChangeLog entries follow: --------------------
lisp/ChangeLog addition:
2010-03-18 Ben Wing <ben@xemacs.org>
* diagnose.el (show-memory-usage):
Rewrite to take into account API changes in memory-usage functions.
src/ChangeLog addition:
2010-03-18 Ben Wing <ben@xemacs.org>
* alloc.c:
* alloc.c (disksave_object_finalization_1):
* alloc.c (lisp_object_storage_size):
* alloc.c (listu):
* alloc.c (listn):
* alloc.c (Fobject_memory_usage_stats):
* alloc.c (compute_memusage_stats_length):
* alloc.c (Fobject_memory_usage):
* alloc.c (Ftotal_object_memory_usage):
* alloc.c (malloced_storage_size):
* alloc.c (common_init_alloc_early):
* alloc.c (reinit_alloc_objects_early):
* alloc.c (reinit_alloc_early):
* alloc.c (init_alloc_once_early):
* alloc.c (syms_of_alloc):
* alloc.c (reinit_vars_of_alloc):
* buffer.c:
* buffer.c (struct buffer_stats):
* buffer.c (compute_buffer_text_usage):
* buffer.c (compute_buffer_usage):
* buffer.c (buffer_memory_usage):
* buffer.c (buffer_objects_create):
* buffer.c (syms_of_buffer):
* buffer.c (vars_of_buffer):
* console-impl.h (struct console_methods):
* dynarr.c (Dynarr_memory_usage):
* emacs.c (main_1):
* events.c (clear_event_resource):
* extents.c:
* extents.c (compute_buffer_extent_usage):
* extents.c (extent_objects_create):
* extents.h:
* faces.c:
* faces.c (compute_face_cachel_usage):
* faces.c (face_objects_create):
* faces.h:
* general-slots.h:
* glyphs.c:
* glyphs.c (compute_glyph_cachel_usage):
* glyphs.c (glyph_objects_create):
* glyphs.h:
* lisp.h:
* lisp.h (struct usage_stats):
* lrecord.h:
* lrecord.h (enum lrecord_type):
* lrecord.h (struct lrecord_implementation):
* lrecord.h (MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE):
* lrecord.h (DEFINE_DUMPABLE_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_SIZABLE_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_FROB_BLOCK_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_FROB_BLOCK_SIZABLE_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_SIZABLE_INTERNAL_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_SIZABLE_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_FROB_BLOCK_SIZABLE_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_INTERNAL_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_SIZABLE_INTERNAL_LISP_OBJECT):
* lrecord.h (MAKE_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_MODULE_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_MODULE_SIZABLE_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_MODULE_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_MODULE_SIZABLE_LISP_OBJECT):
* lrecord.h (MAKE_MODULE_LISP_OBJECT):
* lrecord.h (INIT_LISP_OBJECT):
* lrecord.h (INIT_MODULE_LISP_OBJECT):
* lrecord.h (UNDEF_LISP_OBJECT):
* lrecord.h (UNDEF_MODULE_LISP_OBJECT):
* lrecord.h (DECLARE_LISP_OBJECT):
* lrecord.h (DECLARE_MODULE_API_LISP_OBJECT):
* lrecord.h (DECLARE_MODULE_LISP_OBJECT):
* lstream.c:
* lstream.c (syms_of_lstream):
* lstream.c (vars_of_lstream):
* marker.c:
* marker.c (compute_buffer_marker_usage):
* mc-alloc.c (mc_alloced_storage_size):
* mc-alloc.h:
* mule-charset.c:
* mule-charset.c (struct charset_stats):
* mule-charset.c (compute_charset_usage):
* mule-charset.c (charset_memory_usage):
* mule-charset.c (mule_charset_objects_create):
* mule-charset.c (syms_of_mule_charset):
* mule-charset.c (vars_of_mule_charset):
* redisplay.c:
* redisplay.c (compute_rune_dynarr_usage):
* redisplay.c (compute_display_block_dynarr_usage):
* redisplay.c (compute_glyph_block_dynarr_usage):
* redisplay.c (compute_display_line_dynarr_usage):
* redisplay.c (compute_line_start_cache_dynarr_usage):
* redisplay.h:
* scrollbar-gtk.c (gtk_compute_scrollbar_instance_usage):
* scrollbar-msw.c (mswindows_compute_scrollbar_instance_usage):
* scrollbar-x.c (x_compute_scrollbar_instance_usage):
* scrollbar.c (compute_scrollbar_instance_usage):
* scrollbar.h:
* symbols.c:
* symbols.c (reinit_symbol_objects_early):
* symbols.c (init_symbols_once_early):
* symbols.c (reinit_symbols_early):
* symbols.c (defsymbol_massage_name_1):
* symsinit.h:
* ui-gtk.c:
* ui-gtk.c (emacs_gtk_object_getprop):
* ui-gtk.c (emacs_gtk_object_putprop):
* ui-gtk.c (ui_gtk_objects_create):
* unicode.c (compute_from_unicode_table_size_1):
* unicode.c (compute_to_unicode_table_size_1):
* unicode.c (compute_from_unicode_table_size):
* unicode.c (compute_to_unicode_table_size):
* window.c:
* window.c (struct window_stats):
* window.c (compute_window_mirror_usage):
* window.c (compute_window_usage):
* window.c (window_memory_usage):
* window.c (window_objects_create):
* window.c (syms_of_window):
* window.c (vars_of_window):
* window.h:
Redo memory-usage mechanism, make it general; add way of dynamically
initializing Lisp object types -- OBJECT_HAS_METHOD(), similar to
CONSOLE_HAS_METHOD().
(1) Create OBJECT_HAS_METHOD(), OBJECT_HAS_PROPERTY() etc. for
specifying that a Lisp object type has a particular method or
property. Call such methods with OBJECT_METH, MAYBE_OBJECT_METH,
OBJECT_METH_OR_GIVEN; retrieve properties with OBJECT_PROPERTY.
Methods that formerly required a DEFINE_*GENERAL_LISP_OBJECT() to
specify them (getprop, putprop, remprop, plist, disksave) now
instead use the dynamic-method mechanism. The main benefit of
this is that new methods or properties can be added without
requiring that the declaration statements of all existing methods
be modified. We have to make the `struct lrecord_implementation'
non-const, but I don't think this should have any effect on speed --
the only possible method that's really speed-critical is the
mark method, and we already extract those out into a separate
(non-const) array for increased cache locality.
Object methods need to be reinitialized after pdump, so we put
them in separate functions such as face_objects_create(),
extent_objects_create() and call them appropriately from emacs.c
The only current object property (`memusage_stats_list') that
objects can specify is a Lisp object and gets staticpro()ed so it
only needs to be set during dump time, but because it references
symbols that might not exist in a syms_of_() function, we
initialize it in vars_of_(). There is also an object property
(`num_extra_memusage_stats') that is automatically initialized based
on `memusage_stats_list'; we do that in reinit_vars_of_alloc(),
which is called after all vars_of_() functions are called.
`disksaver' method was renamed `disksave' to correspond with the
name normally given to the function (e.g. disksave_lstream()).
(2) Generalize the memory-usage mechanism in `buffer-memory-usage',
`window-memory-usage', `charset-memory-usage' into an object-type-
specific mechanism called by a single function
`object-memory-usage'. (Former function `object-memory-usage'
renamed to `total-object-memory-usage'). Generalize the mechanism
of different "slices" so that we can have different "classes" of
memory described and different "slices" onto each class; `t'
separates classes, `nil' separates slices. Currently we have
three classes defined: the memory of an object itself,
non-Lisp-object memory associated with the object (e.g. arrays or
dynarrs stored as fields in the object), and Lisp-object memory
associated with the object (other internal Lisp objects stored in
the object). This isn't completely finished yet and we might need
to further separate the "other internal Lisp objects" class into
two classes.
The memory-usage mechanism uses a `struct usage_stats' (renamed
from `struct overhead_stats') to describe a malloc-view onto a set
of allocated memory (listing how much was requested and various
types of overhead) and a more general `struct generic_usage_stats'
(with a `struct usage_stats' in it) to hold all statistics about
object memory. `struct generic_usage_stats' contains an array of
32 Bytecounts, which are statistics of unspecified semantics. The
intention is that individual types declare a corresponding struct
(e.g. `struct window_stats') with the same structure but with
specific fields in place of the array, corresponding to specific
statistics. The number of such statistics is an object property
computed from the list of tags (Lisp symbols describing the
statistics) stored in `memusage_stats_list'. The idea here is to
allow particular object types to customize the number and
semantics of the statistics where completely avoiding consing.
This doesn't matter so much yet, but the intention is to have the
memory usage of all objects computed at the end of GC, at the same
time as other statistics are currently computed. The values for
all statistics for a single type would be added up to compute
aggregate values for all objects of a specific type. To make this
efficient, we can't allow any memory allocation at all.
(3) Create some additional functions for creating lists that
specify the elements directly as args rather than indirectly through
an array: listn() (number of args given), listu() (list terminated
by Qunbound).
(4) Delete a bit of remaining unused C window_config stuff, also
unused lrecord_type_popup_data.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Thu, 18 Mar 2010 10:50:06 -0500 |
parents | c8f90d61dcf3 |
children | 9e0b43d3095c |
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) | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
38 (flet ((show-foo-stats (objtypename cleanfun objlist) |
787 | 39 (let* ((hash (make-hash-table)) |
40 (first t) | |
41 types fmt | |
42 (objnamelen 25) | |
43 (linelen objnamelen) | |
44 (totaltotal 0)) | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
45 (loop for obj in objlist do |
787 | 46 (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
|
47 (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
|
48 ;; 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
|
49 ;; memory |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
50 (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
|
51 ;; 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
|
52 ;; 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
|
53 ;; 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
|
54 ;; 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
|
55 (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
|
56 |
787 | 57 (loop for (type . num) in stats while type do |
58 (puthash type (+ num (or (gethash type hash) 0)) hash) | |
59 (incf total num) | |
60 (if first (push type types))) | |
61 (incf totaltotal total) | |
62 (when first | |
63 (setq types (nreverse types)) | |
64 (setq fmt (concat | |
65 (format "%%-%ds" objnamelen) | |
66 (mapconcat | |
67 #'(lambda (type) | |
68 (let ((fieldlen | |
69 (max 8 (+ 2 (length | |
70 (symbol-name type)))))) | |
71 (incf linelen fieldlen) | |
72 (format "%%%ds" fieldlen))) | |
73 types "") | |
2618 | 74 (progn (incf linelen 9) "%9s\n"))) |
787 | 75 (princ "\n") |
76 (princ (apply 'format fmt objtypename | |
77 (append types (list 'total)))) | |
78 (princ (make-string linelen ?-)) | |
79 (princ "\n")) | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
80 (let ((objname (format "%s" (funcall cleanfun obj)))) |
787 | 81 (princ (apply 'format fmt (substring objname 0 |
82 (min (length objname) | |
83 (1- objnamelen))) | |
84 (nconc (mapcar #'(lambda (type) | |
85 (cdr (assq type stats))) | |
86 types) | |
87 (list total))))) | |
88 (setq first nil))) | |
89 (princ "\n") | |
90 (princ (apply 'format fmt "total" | |
91 (nconc (mapcar #'(lambda (type) | |
92 (gethash type hash)) | |
93 types) | |
94 (list totaltotal)))) | |
95 totaltotal))) | |
96 | |
2618 | 97 (let ((grandtotal 0) |
98 (buffer "*memory usage*") | |
99 begin) | |
100 (with-output-to-temp-buffer buffer | |
101 (save-excursion | |
102 (set-buffer buffer) | |
103 (when-fboundp 'charset-list | |
104 (setq begin (point)) | |
105 (incf grandtotal | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
106 (show-foo-stats 'charset 'charset-name |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
107 (mapcar 'get-charset (charset-list)))) |
3066 | 108 (when-fboundp 'sort-numeric-fields |
109 (sort-numeric-fields -1 | |
110 (save-excursion | |
111 (goto-char begin) | |
112 (forward-line 2) | |
113 (point)) | |
114 (save-excursion | |
115 (forward-line -2) | |
116 (point)))) | |
2618 | 117 (princ "\n")) |
118 (setq begin (point)) | |
119 (incf grandtotal | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
120 (show-foo-stats 'buffer 'buffer-name (buffer-list))) |
3066 | 121 (when-fboundp 'sort-numeric-fields |
122 (sort-numeric-fields -1 | |
123 (save-excursion | |
124 (goto-char begin) | |
125 (forward-line 3) | |
126 (point)) | |
127 (save-excursion | |
128 (forward-line -2) | |
129 (point)))) | |
2618 | 130 (princ "\n") |
131 (setq begin (point)) | |
787 | 132 (incf grandtotal |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
133 (show-foo-stats 'window #'(lambda (x) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
134 (buffer-name (window-buffer x))) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
135 (mapcan #'(lambda (fr) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
136 (window-list fr t)) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5059
diff
changeset
|
137 (frame-list)))) |
4103 | 138 (when-fboundp #'sort-numeric-fields |
139 (sort-numeric-fields -1 | |
140 (save-excursion | |
141 (goto-char begin) | |
142 (forward-line 3) | |
143 (point)) | |
144 (save-excursion | |
145 (forward-line -2) | |
146 (point)))) | |
787 | 147 (princ "\n") |
2618 | 148 (let ((total 0) |
149 (fmt "%-30s%10s\n")) | |
150 (setq begin (point)) | |
151 (princ (format fmt "object" "storage")) | |
152 (princ (make-string 40 ?-)) | |
153 (princ "\n") | |
154 (map-plist #'(lambda (stat num) | |
2775 | 155 (when (string-match |
3278 | 156 "\\(.*\\)-storage$" |
2775 | 157 (symbol-name stat)) |
2618 | 158 (incf total num) |
159 (princ (format fmt | |
160 (match-string 1 (symbol-name stat)) | |
161 num))) | |
162 (when (eq stat 'long-strings-total-length) | |
163 (incf total num) | |
164 (princ (format fmt stat num)))) | |
165 (sixth (garbage-collect))) | |
166 (princ "\n") | |
167 (princ (format fmt "total" total)) | |
168 (incf grandtotal total)) | |
4103 | 169 (when-fboundp #'sort-numeric-fields |
170 (sort-numeric-fields -1 | |
171 (save-excursion | |
172 (goto-char begin) | |
173 (forward-line 2) | |
174 (point)) | |
175 (save-excursion | |
176 (forward-line -2) | |
177 (point)))) | |
787 | 178 |
2618 | 179 (princ (format "\n\ngrand total: %s\n" grandtotal))) |
787 | 180 grandtotal)))) |
2720 | 181 |
182 | |
3041 | 183 (defun show-object-memory-usage-stats () |
3888 | 184 "Show statistics about object memory usage in XEmacs." |
2775 | 185 (interactive) |
186 (garbage-collect) | |
3041 | 187 (let ((buffer "*object memory usage statistics*") |
188 (plist (object-memory-usage-stats)) | |
2775 | 189 (fmt "%-30s%10s%10s\n") |
190 (grandtotal 0) | |
191 begin) | |
192 (flet ((show-stats (match-string) | |
193 (princ (format fmt "object" "count" "storage")) | |
194 (princ (make-string 50 ?-)) | |
195 (princ "\n") | |
196 (let ((total-use 0) | |
197 (total-use-overhead 0) | |
198 (total-count 0)) | |
199 (map-plist | |
200 #'(lambda (stat num) | |
201 (when (string-match match-string | |
202 (symbol-name stat)) | |
203 (let ((storage-use num) | |
204 (storage-use-overhead | |
205 (plist-get | |
206 plist | |
207 (intern (concat (match-string 1 (symbol-name stat)) | |
208 "-storage-including-overhead")))) | |
209 (storage-count | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
210 (or (loop for str in '("s-used" "es-used" "-used") |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
211 for val = (plist-get |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
212 plist |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
213 (intern |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
214 (concat (match-string |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
215 1 (symbol-name stat)) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
216 str))) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
217 if val |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
218 return val) |
2775 | 219 (plist-get |
220 plist | |
221 (intern | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
222 (concat (substring |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
223 (match-string 1 (symbol-name stat)) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
224 0 -1) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
225 "ies-used"))) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
226 ))) |
2775 | 227 (incf total-use storage-use) |
228 (incf total-use-overhead (if storage-use-overhead | |
229 storage-use-overhead | |
230 storage-use)) | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
231 (incf total-count (or storage-count 0)) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
232 (and (> storage-use 0) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
233 (princ (format fmt |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
234 (match-string 1 (symbol-name stat)) |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
235 (or storage-count "unknown") |
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
236 storage-use)))))) |
2775 | 237 plist) |
238 (princ "\n") | |
239 (princ (format fmt "total" | |
240 total-count total-use-overhead)) | |
241 (incf grandtotal total-use-overhead) | |
4103 | 242 (when-fboundp #'sort-numeric-fields |
243 (sort-numeric-fields -1 | |
244 (save-excursion | |
245 (goto-char begin) | |
5059
c8f90d61dcf3
fix memory usage stats to include pdumped objects
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
246 (forward-line 3) |
4103 | 247 (point)) |
248 (save-excursion | |
249 (forward-line -2) | |
250 (point))))))) | |
2775 | 251 (with-output-to-temp-buffer buffer |
252 (save-excursion | |
253 (set-buffer buffer) | |
254 (setq begin (point)) | |
3041 | 255 (princ "Allocated with lisp allocator:\n") |
2775 | 256 (show-stats "\\(.*\\)-storage$") |
257 (princ (format "\n\ngrand total: %s\n" grandtotal))) | |
258 grandtotal)))) | |
259 | |
260 | |
2720 | 261 (defun show-mc-alloc-memory-usage () |
262 "Show statistics about memory usage of the new allocator." | |
263 (interactive) | |
264 (garbage-collect) | |
4103 | 265 (if-fboundp #'mc-alloc-memory-usage |
266 (let* ((stats (mc-alloc-memory-usage)) | |
267 (page-size (first stats)) | |
268 (heap-sects (second stats)) | |
269 (used-plhs (third stats)) | |
270 (free-plhs (fourth stats)) | |
271 (globals (fifth stats)) | |
272 (mc-malloced-bytes (sixth stats))) | |
273 (with-output-to-temp-buffer "*mc-alloc memory usage*" | |
274 (flet ((print-used-plhs (text plhs) | |
275 (let ((sum-n-pages 0) | |
276 (sum-used-n-cells 0) | |
277 (sum-used-space 0) | |
278 (sum-used-total 0) | |
279 (sum-total-n-cells 0) | |
280 (sum-total-space 0) | |
281 (sum-total-total 0) | |
282 (fmt "%7s%7s|%7s%9s%9s%4s|%7s%9s%9s%4s|%4s\n")) | |
283 (princ (format "%-14s|%-29s|%-29s|\n" | |
284 text | |
285 " currently in use" | |
286 " total available")) | |
287 (princ (format fmt "cell-sz" "#pages" | |
288 "#cells" "space" "total" "% " | |
289 "#cells" "space" "total" "% " "% ")) | |
290 (princ (make-string 79 ?-)) | |
291 (princ "\n") | |
292 (while plhs | |
293 (let* ((elem (car plhs)) | |
294 (cell-size (first elem)) | |
295 (n-pages (second elem)) | |
296 (used-n-cells (third elem)) | |
297 (used-space (fourth elem)) | |
298 (used-total (if (zerop cell-size) | |
299 (sixth elem) | |
300 (* cell-size used-n-cells))) | |
301 (used-eff (floor (if (not (zerop used-total)) | |
302 (* (/ (* used-space 1.0) | |
303 (* used-total 1.0)) | |
304 100.0) | |
305 0))) | |
306 (total-n-cells (fifth elem)) | |
307 (total-space (if (zerop cell-size) | |
308 used-space | |
309 (* cell-size total-n-cells))) | |
310 (total-total (sixth elem)) | |
311 (total-eff (floor (if (not (zerop total-total)) | |
312 (* (/ (* total-space 1.0) | |
313 (* total-total 1.0)) | |
314 100.0) | |
315 0))) | |
316 (eff (floor (if (not (zerop total-total)) | |
317 (* (/ (* used-space 1.0) | |
318 (* total-total 1.0)) | |
319 100.0) | |
320 0)))) | |
321 (princ (format fmt | |
322 cell-size n-pages used-n-cells used-space | |
323 used-total used-eff total-n-cells | |
324 total-space total-total total-eff eff)) | |
325 (incf sum-n-pages n-pages) | |
326 (incf sum-used-n-cells used-n-cells) | |
327 (incf sum-used-space used-space) | |
328 (incf sum-used-total used-total) | |
329 (incf sum-total-n-cells total-n-cells) | |
330 (incf sum-total-space total-space) | |
331 (incf sum-total-total total-total)) | |
332 (setq plhs (cdr plhs))) | |
333 (let ((avg-used-eff (floor (if (not (zerop sum-used-total)) | |
334 (* (/ (* sum-used-space 1.0) | |
335 (* sum-used-total 1.0)) | |
336 100.0) | |
337 0))) | |
338 (avg-total-eff (floor (if (not (zerop sum-total-total)) | |
339 (* (/ (* sum-total-space 1.0) | |
340 (* sum-total-total 1.0)) | |
341 100.0) | |
342 0))) | |
343 (avg-eff (floor (if (not (zerop sum-total-total)) | |
344 (* (/ (* sum-used-space 1.0) | |
345 (* sum-total-total 1.0)) | |
346 100.0) | |
347 0)))) | |
348 (princ (format fmt "sum " sum-n-pages sum-used-n-cells | |
349 sum-used-space sum-used-total avg-used-eff | |
350 sum-total-n-cells sum-total-space | |
351 sum-total-total avg-total-eff avg-eff)) | |
352 (princ "\n")))) | |
2720 | 353 |
354 | |
4103 | 355 (print-free-plhs (text plhs) |
356 (let ((sum-n-pages 0) | |
357 (sum-n-sects 0) | |
358 (sum-space 0) | |
359 (sum-total 0) | |
360 (fmt "%6s%10s |%7s%10s\n")) | |
361 (princ (format "%s\n" text)) | |
362 (princ (format fmt "#pages" "space" "#sects" "total")) | |
363 (princ (make-string 35 ?-)) | |
364 (princ "\n") | |
365 (while plhs | |
366 (let* ((elem (car plhs)) | |
367 (n-pages (first elem)) | |
368 (n-sects (second elem)) | |
369 (space (* n-pages page-size)) | |
370 (total (* n-sects space))) | |
371 (princ (format fmt n-pages space n-sects total)) | |
372 (incf sum-n-pages n-pages) | |
373 (incf sum-n-sects n-sects) | |
374 (incf sum-space space) | |
375 (incf sum-total total)) | |
376 (setq plhs (cdr plhs))) | |
377 (princ (make-string 35 ?=)) | |
378 (princ "\n") | |
379 (princ (format fmt sum-n-pages sum-space | |
380 sum-n-sects sum-total)) | |
381 (princ "\n")))) | |
2720 | 382 |
4103 | 383 (princ (format "%-12s%10s\n\n" "PAGE_SIZE" page-size)) |
2720 | 384 |
4103 | 385 (print-used-plhs "USED HEAP" used-plhs) |
386 (princ "\n\n") | |
2720 | 387 |
4103 | 388 (print-free-plhs "FREE HEAP" free-plhs) |
389 (princ "\n\n") | |
2720 | 390 |
4103 | 391 (let ((fmt "%-30s%10s\n")) |
392 (princ (format fmt "heap sections" "")) | |
393 (princ (make-string 40 ?-)) | |
394 (princ "\n") | |
395 (princ (format fmt "number of heap sects" | |
396 (first heap-sects))) | |
397 (princ (format fmt "used size" (second heap-sects))) | |
398 (princ (make-string 40 ?-)) | |
399 (princ "\n") | |
400 (princ (format fmt "real size" (third heap-sects))) | |
401 (princ (format fmt "global allocator structs" globals)) | |
402 (princ (make-string 40 ?-)) | |
403 (princ "\n") | |
404 (princ (format fmt "real size + structs" | |
405 (+ (third heap-sects) globals))) | |
406 (princ "\n") | |
407 (princ (make-string 40 ?=)) | |
408 (princ "\n") | |
409 (princ (format fmt "grand total" mc-malloced-bytes))) | |
2720 | 410 |
4103 | 411 (+ mc-malloced-bytes)))) |
412 (message "mc-alloc not used in this XEmacs."))) | |
3092 | 413 |
414 | |
415 (defun show-gc-stats () | |
416 "Show statistics about garbage collection cycles." | |
417 (interactive) | |
4103 | 418 (if-fboundp #'gc-stats |
419 (let ((buffer "*garbage collection statistics*") | |
420 (plist (gc-stats)) | |
421 (fmt "%-9s %16s %12s %12s %12s %12s\n")) | |
422 (flet ((plist-get-stat (category field) | |
423 (let ((stat (plist-get plist | |
424 (intern (concat category field))))) | |
425 (if stat | |
426 (format "%.0f" stat) | |
427 "-"))) | |
428 (show-stats (category) | |
429 (princ (format fmt category | |
430 (plist-get-stat category "-total") | |
431 (plist-get-stat category "-in-last-gc") | |
432 (plist-get-stat category "-in-this-gc") | |
433 (plist-get-stat category "-in-last-cycle") | |
434 (plist-get-stat category "-in-this-cycle"))))) | |
435 (with-output-to-temp-buffer buffer | |
436 (save-excursion | |
437 (set-buffer buffer) | |
438 (princ (format "%s %g\n" "Current phase" | |
439 (plist-get plist 'phase))) | |
440 (princ (make-string 78 ?-)) | |
441 (princ "\n") | |
442 (princ (format fmt "stat" "total" "last-gc" "this-gc" | |
443 "last-cycle" "this-cylce")) | |
444 (princ (make-string 78 ?-)) | |
445 (princ "\n") | |
446 (show-stats "n-gc") | |
447 (show-stats "n-cycles") | |
448 (show-stats "enqueued") | |
449 (show-stats "dequeued") | |
450 (show-stats "repushed") | |
451 (show-stats "enqueued2") | |
452 (show-stats "dequeued2") | |
453 (show-stats "finalized") | |
454 (show-stats "freed") | |
455 (plist-get plist 'n-gc-total))))) | |
456 (error 'void-function "gc-stats not available."))) |