Mercurial > hg > xemacs-beta
comparison src/alloc.c @ 5158:9e0b43d3095c
more cleanups to object-memory-usage stuff
-------------------- ChangeLog entries follow: --------------------
lisp/ChangeLog addition:
2010-03-19 Ben Wing <ben@xemacs.org>
* diagnose.el (show-object-memory-usage-stats):
Rewrite to take into account non-lisp-storage statistics
returned by garbage-collect-1 and friends.
src/ChangeLog addition:
2010-03-19 Ben Wing <ben@xemacs.org>
* alloc.c:
* alloc.c (struct):
* alloc.c (tick_lrecord_stats):
* alloc.c (gc_sweep_1):
* alloc.c (finish_object_memory_usage_stats):
* alloc.c (object_memory_usage_stats):
* alloc.c (compute_memusage_stats_length):
Call new memory-usage mechanism at sweep time to compute extra
memory utilization for all objects. Add up the values element-by-
element to get an aggregrate set of statistics, where each is the
sum of the values of a single statistic across different objects
of the same type. At end of sweep time, call
finish_object_memory_usage_stats() to add up all the aggreggrate
stats that are related to non-Lisp memory storage to compute
a single value, and add it to the list of values returned by
`garbage-collect' and `object-memory-usage-stats'.
* buffer.c (compute_buffer_text_usage):
Don't crash on buffers without text (killed buffers?) and don't
double-count indirect buffers.
* elhash.c:
* elhash.c (hash_table_objects_create):
* elhash.c (vars_of_elhash):
* symsinit.h:
Add memory-usage method to count the size of `hentries'.
* emacs.c (main_1):
Call new functions in elhash.c, frame.c at init.
* frame.c:
* frame.c (compute_frame_usage):
* frame.c (frame_memory_usage):
* frame.c (frame_objects_create):
* symsinit.h:
Add memory-usage method to count gutter display structures,
subwindow exposures.
* gc.c (gc_finish):
* lisp.h:
Declare finish_object_memory_usage_stats(), call it in gc_finish().
* lrecord.h (struct lrecord_implementation):
* lrecord.h (INIT_MEMORY_USAGE_STATS):
New value in implementation struct to track number of non-Lisp-memory
statistics. Computed in alloc.c.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Fri, 19 Mar 2010 14:47:44 -0500 |
parents | 1fae11d56ad2 |
children | cb303ff63e76 |
comparison
equal
deleted
inserted
replaced
5157:1fae11d56ad2 | 5158:9e0b43d3095c |
---|---|
3622 int bytes_in_use; | 3622 int bytes_in_use; |
3623 int instances_freed; | 3623 int instances_freed; |
3624 int bytes_freed; | 3624 int bytes_freed; |
3625 int instances_on_free_list; | 3625 int instances_on_free_list; |
3626 int bytes_on_free_list; | 3626 int bytes_on_free_list; |
3627 #ifdef MEMORY_USAGE_STATS | |
3628 Bytecount nonlisp_bytes_in_use; | |
3629 struct generic_usage_stats stats; | |
3630 #endif | |
3627 } lrecord_stats [countof (lrecord_implementations_table)]; | 3631 } lrecord_stats [countof (lrecord_implementations_table)]; |
3628 | 3632 |
3629 void | 3633 void |
3630 tick_lrecord_stats (const struct lrecord_header *h, | 3634 tick_lrecord_stats (const struct lrecord_header *h, |
3631 enum lrecord_alloc_status status) | 3635 enum lrecord_alloc_status status) |
3636 switch (status) | 3640 switch (status) |
3637 { | 3641 { |
3638 case ALLOC_IN_USE: | 3642 case ALLOC_IN_USE: |
3639 lrecord_stats[type_index].instances_in_use++; | 3643 lrecord_stats[type_index].instances_in_use++; |
3640 lrecord_stats[type_index].bytes_in_use += sz; | 3644 lrecord_stats[type_index].bytes_in_use += sz; |
3645 #ifdef MEMORY_USAGE_STATS | |
3646 { | |
3647 struct generic_usage_stats stats; | |
3648 Lisp_Object obj = wrap_pointer_1 (h); | |
3649 if (HAS_OBJECT_METH_P (obj, memory_usage)) | |
3650 { | |
3651 int i; | |
3652 int total_stats = OBJECT_PROPERTY (obj, num_extra_memusage_stats); | |
3653 xzero (stats); | |
3654 OBJECT_METH (obj, memory_usage, (obj, &stats)); | |
3655 for (i = 0; i < total_stats; i++) | |
3656 lrecord_stats[type_index].stats.othervals[i] += | |
3657 stats.othervals[i]; | |
3658 } | |
3659 } | |
3660 #endif | |
3641 break; | 3661 break; |
3642 case ALLOC_FREE: | 3662 case ALLOC_FREE: |
3643 lrecord_stats[type_index].instances_freed++; | 3663 lrecord_stats[type_index].instances_freed++; |
3644 lrecord_stats[type_index].bytes_freed += sz; | 3664 lrecord_stats[type_index].bytes_freed += sz; |
3645 break; | 3665 break; |
4515 sweep_magic_data (); | 4535 sweep_magic_data (); |
4516 sweep_magic_eval_data (); | 4536 sweep_magic_eval_data (); |
4517 sweep_eval_data (); | 4537 sweep_eval_data (); |
4518 sweep_misc_user_data (); | 4538 sweep_misc_user_data (); |
4519 #endif /* EVENT_DATA_AS_OBJECTS */ | 4539 #endif /* EVENT_DATA_AS_OBJECTS */ |
4520 #endif /* not NEW_GC */ | 4540 |
4521 | |
4522 #ifndef NEW_GC | |
4523 #ifdef PDUMP | 4541 #ifdef PDUMP |
4524 pdump_objects_unmark (); | 4542 pdump_objects_unmark (); |
4525 #endif | 4543 #endif |
4526 } | 4544 } |
4527 #endif /* not NEW_GC */ | 4545 #endif /* not NEW_GC */ |
4657 strcpy (buf, name); | 4675 strcpy (buf, name); |
4658 pluralize_word (buf); | 4676 pluralize_word (buf); |
4659 strcat (buf, suffix); | 4677 strcat (buf, suffix); |
4660 } | 4678 } |
4661 | 4679 |
4680 void | |
4681 finish_object_memory_usage_stats (void) | |
4682 { | |
4683 #ifdef MEMORY_USAGE_STATS | |
4684 int i; | |
4685 for (i = 0; i < countof (lrecord_implementations_table); i++) | |
4686 { | |
4687 struct lrecord_implementation *imp = lrecord_implementations_table[i]; | |
4688 if (imp && imp->num_extra_nonlisp_memusage_stats) | |
4689 { | |
4690 int j; | |
4691 for (j = 0; j < imp->num_extra_nonlisp_memusage_stats; j++) | |
4692 lrecord_stats[i].nonlisp_bytes_in_use += | |
4693 lrecord_stats[i].stats.othervals[j]; | |
4694 } | |
4695 } | |
4696 #endif /* MEMORY_USAGE_STATS */ | |
4697 } | |
4698 | |
4662 static Lisp_Object | 4699 static Lisp_Object |
4663 object_memory_usage_stats (int set_total_gc_usage) | 4700 object_memory_usage_stats (int set_total_gc_usage) |
4664 { | 4701 { |
4665 Lisp_Object pl = Qnil; | 4702 Lisp_Object pl = Qnil; |
4666 int i; | 4703 int i; |
4667 EMACS_INT tgu_val = 0; | 4704 EMACS_INT tgu_val = 0; |
4668 | 4705 |
4669 #ifdef NEW_GC | 4706 #ifdef NEW_GC |
4670 | |
4671 for (i = 0; i < countof (lrecord_implementations_table); i++) | 4707 for (i = 0; i < countof (lrecord_implementations_table); i++) |
4672 { | 4708 { |
4673 if (lrecord_stats[i].instances_in_use != 0) | 4709 if (lrecord_stats[i].instances_in_use != 0) |
4674 { | 4710 { |
4675 Ascbyte buf[255]; | 4711 Ascbyte buf[255]; |
4740 const Ascbyte *name = lrecord_implementations_table[i]->name; | 4776 const Ascbyte *name = lrecord_implementations_table[i]->name; |
4741 | 4777 |
4742 sprintf (buf, "%s-storage", name); | 4778 sprintf (buf, "%s-storage", name); |
4743 pl = gc_plist_hack (buf, lrecord_stats[i].bytes_in_use, pl); | 4779 pl = gc_plist_hack (buf, lrecord_stats[i].bytes_in_use, pl); |
4744 tgu_val += lrecord_stats[i].bytes_in_use; | 4780 tgu_val += lrecord_stats[i].bytes_in_use; |
4781 if (lrecord_stats[i].nonlisp_bytes_in_use) | |
4782 { | |
4783 sprintf (buf, "%s-non-lisp-storage", name); | |
4784 pl = gc_plist_hack (buf, lrecord_stats[i].nonlisp_bytes_in_use, | |
4785 pl); | |
4786 tgu_val += lrecord_stats[i].nonlisp_bytes_in_use; | |
4787 } | |
4745 pluralize_and_append (buf, name, "-freed"); | 4788 pluralize_and_append (buf, name, "-freed"); |
4746 if (lrecord_stats[i].instances_freed != 0) | 4789 if (lrecord_stats[i].instances_freed != 0) |
4747 pl = gc_plist_hack (buf, lrecord_stats[i].instances_freed, pl); | 4790 pl = gc_plist_hack (buf, lrecord_stats[i].instances_freed, pl); |
4748 pluralize_and_append (buf, name, "-on-free-list"); | 4791 pluralize_and_append (buf, name, "-on-free-list"); |
4749 if (lrecord_stats[i].instances_on_free_list != 0) | 4792 if (lrecord_stats[i].instances_on_free_list != 0) |
4805 int i; | 4848 int i; |
4806 | 4849 |
4807 for (i = 0; i < countof (lrecord_implementations_table); i++) | 4850 for (i = 0; i < countof (lrecord_implementations_table); i++) |
4808 { | 4851 { |
4809 int len = 0; | 4852 int len = 0; |
4853 int nonlisp_len = 0; | |
4854 int seen_break = 0; | |
4855 | |
4810 struct lrecord_implementation *imp = lrecord_implementations_table[i]; | 4856 struct lrecord_implementation *imp = lrecord_implementations_table[i]; |
4811 | 4857 |
4812 if (!imp) | 4858 if (!imp) |
4813 continue; | 4859 continue; |
4814 /* For some of the early objects, Qnil was not yet initialized at | 4860 /* For some of the early objects, Qnil was not yet initialized at |
4818 imp->memusage_stats_list = Qnil; | 4864 imp->memusage_stats_list = Qnil; |
4819 { | 4865 { |
4820 LIST_LOOP_2 (item, imp->memusage_stats_list) | 4866 LIST_LOOP_2 (item, imp->memusage_stats_list) |
4821 { | 4867 { |
4822 if (!NILP (item) && !EQ (item, Qt)) | 4868 if (!NILP (item) && !EQ (item, Qt)) |
4823 len++; | 4869 { |
4870 len++; | |
4871 if (!seen_break) | |
4872 nonlisp_len++; | |
4873 } | |
4874 else | |
4875 seen_break++; | |
4824 } | 4876 } |
4825 } | 4877 } |
4826 | 4878 |
4827 imp->num_extra_memusage_stats = len; | 4879 imp->num_extra_memusage_stats = len; |
4880 imp->num_extra_nonlisp_memusage_stats = nonlisp_len; | |
4828 } | 4881 } |
4829 } | 4882 } |
4830 | 4883 |
4831 DEFUN ("object-memory-usage", Fobject_memory_usage, 1, 1, 0, /* | 4884 DEFUN ("object-memory-usage", Fobject_memory_usage, 1, 1, 0, /* |
4832 Return stats about the memory usage of OBJECT. | 4885 Return stats about the memory usage of OBJECT. |