aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorRichard M. Stallman1995-08-02 18:30:53 +0000
committerRichard M. Stallman1995-08-02 18:30:53 +0000
commit310ea200baee353174485b6822acb94fd214f722 (patch)
treea34917b042cd5e25d93daf08d893e6d3b1215677 /src/alloc.c
parentffcb5a51277228aaab4fedcf587be15224ef245b (diff)
downloademacs-310ea200baee353174485b6822acb94fd214f722.tar.gz
emacs-310ea200baee353174485b6822acb94fd214f722.zip
(cons_cells_consed, floats_consed, vector_cells_consed)
(symbols_consed, string_chars_consed, misc_objects_consed) (intervals_consed): New vars. (make_float, Fcons, make_interval, allocate_vectorlike, Fmake_symbol) (allocate_misc, make_uninit_string): Increment them. (Fmemory_use_counts): New function. (syms_of_alloc): defsubr it.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 9d7a5dc4066..f372847ba55 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -71,6 +71,15 @@ static __malloc_size_t bytes_used_when_full;
71/* Number of bytes of consing done since the last gc */ 71/* Number of bytes of consing done since the last gc */
72int consing_since_gc; 72int consing_since_gc;
73 73
74/* Count the amount of consing of various sorts of space. */
75int cons_cells_consed;
76int floats_consed;
77int vector_cells_consed;
78int symbols_consed;
79int string_chars_consed;
80int misc_objects_consed;
81int intervals_consed;
82
74/* Number of bytes of consing since gc before another gc should be done. */ 83/* Number of bytes of consing since gc before another gc should be done. */
75int gc_cons_threshold; 84int gc_cons_threshold;
76 85
@@ -445,6 +454,7 @@ make_interval ()
445 val = &interval_block->intervals[interval_block_index++]; 454 val = &interval_block->intervals[interval_block_index++];
446 } 455 }
447 consing_since_gc += sizeof (struct interval); 456 consing_since_gc += sizeof (struct interval);
457 intervals_consed++;
448 RESET_INTERVAL (val); 458 RESET_INTERVAL (val);
449 return val; 459 return val;
450} 460}
@@ -584,6 +594,7 @@ make_float (float_value)
584 XFLOAT (val)->data = float_value; 594 XFLOAT (val)->data = float_value;
585 XSETFASTINT (XFLOAT (val)->type, 0); /* bug chasing -wsr */ 595 XSETFASTINT (XFLOAT (val)->type, 0); /* bug chasing -wsr */
586 consing_since_gc += sizeof (struct Lisp_Float); 596 consing_since_gc += sizeof (struct Lisp_Float);
597 floats_consed++;
587 return val; 598 return val;
588} 599}
589 600
@@ -663,6 +674,7 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
663 XCONS (val)->car = car; 674 XCONS (val)->car = car;
664 XCONS (val)->cdr = cdr; 675 XCONS (val)->cdr = cdr;
665 consing_since_gc += sizeof (struct Lisp_Cons); 676 consing_since_gc += sizeof (struct Lisp_Cons);
677 cons_cells_consed++;
666 return val; 678 return val;
667} 679}
668 680
@@ -714,6 +726,7 @@ allocate_vectorlike (len)
714 VALIDATE_LISP_STORAGE (p, 0); 726 VALIDATE_LISP_STORAGE (p, 0);
715 consing_since_gc += (sizeof (struct Lisp_Vector) 727 consing_since_gc += (sizeof (struct Lisp_Vector)
716 + (len - 1) * sizeof (Lisp_Object)); 728 + (len - 1) * sizeof (Lisp_Object));
729 vector_cells_consed += len;
717 730
718 p->next = all_vectors; 731 p->next = all_vectors;
719 all_vectors = p; 732 all_vectors = p;
@@ -863,6 +876,7 @@ Its value and function definition are void, and its property list is nil.")
863 p->function = Qunbound; 876 p->function = Qunbound;
864 p->next = 0; 877 p->next = 0;
865 consing_since_gc += sizeof (struct Lisp_Symbol); 878 consing_since_gc += sizeof (struct Lisp_Symbol);
879 symbols_consed++;
866 return val; 880 return val;
867} 881}
868 882
@@ -922,6 +936,7 @@ allocate_misc ()
922 XSETMISC (val, &marker_block->markers[marker_block_index++]); 936 XSETMISC (val, &marker_block->markers[marker_block_index++]);
923 } 937 }
924 consing_since_gc += sizeof (union Lisp_Misc); 938 consing_since_gc += sizeof (union Lisp_Misc);
939 misc_objects_consed++;
925 return val; 940 return val;
926} 941}
927 942
@@ -1106,6 +1121,7 @@ make_uninit_string (length)
1106 (struct Lisp_String *) current_string_block->chars); 1121 (struct Lisp_String *) current_string_block->chars);
1107 } 1122 }
1108 1123
1124 string_chars_consed += fullsize;
1109 XSTRING (val)->size = length; 1125 XSTRING (val)->size = length;
1110 XSTRING (val)->data[length] = 0; 1126 XSTRING (val)->data[length] = 0;
1111 INITIALIZE_INTERVAL (XSTRING (val), NULL_INTERVAL); 1127 INITIALIZE_INTERVAL (XSTRING (val), NULL_INTERVAL);
@@ -2395,6 +2411,53 @@ We divide the value by 1024 to make sure it fits in a Lisp integer.")
2395 return end; 2411 return end;
2396} 2412}
2397 2413
2414DEFUN ("memory-use-counts", Fmemory_use_counts, Smemory_use_counts, 0, 0, 0,
2415 "Return a list of counters that measure how much consing there has been.\n\
2416Each of these counters increments for a certain kind of object.\n\
2417The counters wrap around from the largest positive integer to zero.\n\
2418Garbage collection does not decrease them.\n\
2419The elements of the value are as follows:\n\
2420 (CONSES FLOATS VECTOR-CELLS SYMBOLS STRING-CHARS MISCS INTERVALS)\n\
2421All are in units of 1 = one object consed\n\
2422except for VECTOR-CELLS and STRING-CHARS, which count the total length of\n\
2423objects consed.\n\
2424MISCS include overlays, markers, and some internal types.\n\
2425Frames, windows, buffers, and subprocesses count as vectors\n\
2426 (but the contents of a buffer's text do not count here).")
2427 ()
2428{
2429 Lisp_Object lisp_cons_cells_consed;
2430 Lisp_Object lisp_floats_consed;
2431 Lisp_Object lisp_vector_cells_consed;
2432 Lisp_Object lisp_symbols_consed;
2433 Lisp_Object lisp_string_chars_consed;
2434 Lisp_Object lisp_misc_objects_consed;
2435 Lisp_Object lisp_intervals_consed;
2436
2437 XSETINT (lisp_cons_cells_consed,
2438 cons_cells_consed & ~(1 << (VALBITS - 1)));
2439 XSETINT (lisp_floats_consed,
2440 floats_consed & ~(1 << (VALBITS - 1)));
2441 XSETINT (lisp_vector_cells_consed,
2442 vector_cells_consed & ~(1 << (VALBITS - 1)));
2443 XSETINT (lisp_symbols_consed,
2444 symbols_consed & ~(1 << (VALBITS - 1)));
2445 XSETINT (lisp_string_chars_consed,
2446 string_chars_consed & ~(1 << (VALBITS - 1)));
2447 XSETINT (lisp_misc_objects_consed,
2448 misc_objects_consed & ~(1 << (VALBITS - 1)));
2449 XSETINT (lisp_intervals_consed,
2450 intervals_consed & ~(1 << (VALBITS - 1)));
2451
2452 return Fcons (lisp_cons_cells_consed,
2453 Fcons (lisp_floats_consed,
2454 Fcons (lisp_vector_cells_consed,
2455 Fcons (lisp_symbols_consed,
2456 Fcons (lisp_string_chars_consed,
2457 Fcons (lisp_misc_objects_consed,
2458 Fcons (lisp_intervals_consed,
2459 Qnil)))))));
2460}
2398 2461
2399/* Initialization */ 2462/* Initialization */
2400 2463
@@ -2502,4 +2565,5 @@ which includes both saved text and other data.");
2502 defsubr (&Spurecopy); 2565 defsubr (&Spurecopy);
2503 defsubr (&Sgarbage_collect); 2566 defsubr (&Sgarbage_collect);
2504 defsubr (&Smemory_limit); 2567 defsubr (&Smemory_limit);
2568 defsubr (&Smemory_use_counts);
2505} 2569}