From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.devel Subject: simple GC instrumentation Date: Fri, 23 Oct 2009 10:03:11 -0700 (PDT) Message-ID: <200910231703.n9NH3BGa029942@godzilla.ics.uci.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1256317534 13382 80.91.229.12 (23 Oct 2009 17:05:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 Oct 2009 17:05:34 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Oct 23 19:05:26 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1N1NZu-0006nJ-01 for ged-emacs-devel@m.gmane.org; Fri, 23 Oct 2009 19:05:26 +0200 Original-Received: from localhost ([127.0.0.1]:57123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1NZt-0005GU-JV for ged-emacs-devel@m.gmane.org; Fri, 23 Oct 2009 13:05:25 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N1NZQ-0004jc-Ph for emacs-devel@gnu.org; Fri, 23 Oct 2009 13:04:56 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N1NZM-0004f8-T8 for emacs-devel@gnu.org; Fri, 23 Oct 2009 13:04:56 -0400 Original-Received: from [199.232.76.173] (port=55640 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1NZM-0004en-Mp for emacs-devel@gnu.org; Fri, 23 Oct 2009 13:04:52 -0400 Original-Received: from paul-mcgann-v0.ics.uci.edu ([128.195.1.147]:38153) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N1NZM-0007kk-0c for emacs-devel@gnu.org; Fri, 23 Oct 2009 13:04:52 -0400 Original-Received: from godzilla.ics.uci.edu (godzilla.ics.uci.edu [128.195.10.101]) by paul-mcgann-v0.ics.uci.edu (8.13.8/8.13.8) with ESMTP id n9NH3B04007075 for ; Fri, 23 Oct 2009 10:03:11 -0700 Original-Received: (from dann@localhost) by godzilla.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id n9NH3BGa029942; Fri, 23 Oct 2009 10:03:11 -0700 (PDT) Original-Lines: 134 X-ICS-MailScanner-Information: Please send mail to helpdesk@ics.uci.edu or more information X-ICS-MailScanner-ID: n9NH3B04007075 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=1.359, required 5, autolearn=disabled, ALL_TRUSTED -1.44, FF_IHOPE_YOU_SINK 1.70, FM_MULTI_ODD2 1.10) X-ICS-MailScanner-SpamScore: s X-ICS-MailScanner-From: dann@godzilla.ics.uci.edu X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:116336 Archived-At: I have a small patch that prints the GC statistics, this is interesting during dumping, it shows which files allocate memory/generate garbage, etc. There's also a counter for the number of calls to "mark_object", we want to keep that low to speed up GC. There's also a new command garbage-collect-with-print that prints all the strings found during GC Use: emacs -batch -f garbage-collect-with-print |& more to see what strings are there, and move as many as possible to pure memory. Maybe someone here will find this stuff useful... Index: alloc.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/alloc.c,v retrieving revision 1.450 diff -u -3 -p -u -p -r1.450 alloc.c --- alloc.c 19 Oct 2009 04:27:11 -0000 1.450 +++ alloc.c 23 Oct 2009 16:52:52 -0000 @@ -2051,6 +2049,7 @@ allocate_string_data (s, nchars, nbytes) consing_since_gc += needed; } +static int enable_gc_print=0; /* Sweep and compact strings. */ @@ -2089,6 +2088,14 @@ sweep_strings () ++total_strings; total_string_size += STRING_BYTES (s); + + if (enable_gc_print) + { + Lisp_Object string; + XSETSTRING (string, s); + Fprin1 (string, Qnil); + } + } else { @@ -4957,6 +4964,7 @@ inhibit_garbage_collection () return count; } +int call_count_mark_object = 0; DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "", doc: /* Reclaim storage for Lisp objects no longer needed. @@ -4980,6 +4988,9 @@ returns nil, because real GC can't be do Lisp_Object total[8]; int count = SPECPDL_INDEX (); EMACS_TIME t1, t2, t3; + int bef = call_count_mark_object; + + /* fprintf (stderr, "bef gc mark_object count = %d\n", call_count_mark_object); */ if (abort_on_gc) abort (); @@ -5272,9 +5283,20 @@ returns nil, because real GC can't be do EMACS_USECS (t3) * 1.0e-6); gcs_done++; + fprintf (stderr, "after gc mark_object delta==%d conses=%d free_conses=%d symbols=%d free_symbols=%d markers=%d free_markers=%d string_ssize=%d vectors=%d floats=%d free_floats=%d interv=%d free_interv=%d strings=%d free_strings=%d pure-bytes-nonlisp=%d pure-bytes=%d\n", call_count_mark_object - bef, total_conses, total_free_conses, total_symbols, total_free_symbols, total_markers, total_free_markers, total_string_size, total_vector_size, total_floats, total_free_floats, total_intervals, total_free_intervals, total_strings, total_free_strings, pure_bytes_used_non_lisp, pure_bytes_used); + return Flist (sizeof total / sizeof *total, total); } +DEFUN ("garbage-collect-with-print", Fgarbage_collect_with_print, Sgarbage_collect_with_print, 0, 0, "", + doc: /* */) + () +{ + enable_gc_print=1; + Fgarbage_collect(); + enable_gc_print=0; + return Qnil; +} /* Mark Lisp objects in glyph matrix MATRIX. Currently the only interesting objects referenced from glyphs are strings. */ @@ -5404,6 +5426,8 @@ mark_object (arg) #endif int cdr_count = 0; + call_count_mark_object++; + loop: if (PURE_POINTER_P (XPNTR (obj))) @@ -5902,6 +5926,7 @@ gc_sweep () cons_free_list = cblk->conses[0].u.chain; lisp_align_free (cblk); n_cons_blocks--; + fprintf(stderr, "deallocate block\n"); } else { @@ -6047,6 +6073,12 @@ gc_sweep () if (!pure_p) UNMARK_STRING (XSTRING (sym->xname)); sym->gcmarkbit = 0; + if (enable_gc_print) + { + Lisp_Object string; + XSETSTRING (string, s); + Fprin1 (string, Qnil); + } } } @@ -6343,6 +6375,9 @@ If this portion is smaller than `gc-cons DEFVAR_INT ("pure-bytes-used", &pure_bytes_used, doc: /* Number of bytes of sharable Lisp data allocated so far. */); + DEFVAR_INT ("pure-bytes-used-nonlisp", &pure_bytes_used_non_lisp, + doc: /* Number of bytes of sharable non Lisp data allocated so far. */); + DEFVAR_INT ("cons-cells-consed", &cons_cells_consed, doc: /* Number of cons cells that have been consed so far. */); @@ -6417,6 +6452,7 @@ The time is in seconds as a floating poi defsubr (&Smake_marker); defsubr (&Spurecopy); defsubr (&Sgarbage_collect); + defsubr (&Sgarbage_collect_with_print); defsubr (&Smemory_limit); defsubr (&Smemory_use_counts);