diff options
| author | Tomohiro Matsuyama | 2012-08-22 21:38:39 +0900 |
|---|---|---|
| committer | Tomohiro Matsuyama | 2012-08-22 21:38:39 +0900 |
| commit | 12b3895d742e06ba3999773f0f02328ae7d9880f (patch) | |
| tree | 892a7d66df4967c2682804bac5fa7df5cea0581f /src/alloc.c | |
| parent | ce56157e5f8ab1b244a63faf2e09ab8cd7c5ee23 (diff) | |
| download | emacs-12b3895d742e06ba3999773f0f02328ae7d9880f.tar.gz emacs-12b3895d742e06ba3999773f0f02328ae7d9880f.zip | |
Add GC profiler.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/src/alloc.c b/src/alloc.c index 3a4a8de90f5..389da29a533 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -5380,6 +5380,23 @@ bounded_number (EMACS_INT number) | |||
| 5380 | return make_number (min (MOST_POSITIVE_FIXNUM, number)); | 5380 | return make_number (min (MOST_POSITIVE_FIXNUM, number)); |
| 5381 | } | 5381 | } |
| 5382 | 5382 | ||
| 5383 | /* Calculate total bytes of live objects. */ | ||
| 5384 | |||
| 5385 | static size_t | ||
| 5386 | total_bytes_of_live_objects (void) | ||
| 5387 | { | ||
| 5388 | size_t tot = 0; | ||
| 5389 | tot += total_conses * sizeof (struct Lisp_Cons); | ||
| 5390 | tot += total_symbols * sizeof (struct Lisp_Symbol); | ||
| 5391 | tot += total_markers * sizeof (union Lisp_Misc); | ||
| 5392 | tot += total_string_bytes; | ||
| 5393 | tot += total_vector_slots * word_size; | ||
| 5394 | tot += total_floats * sizeof (struct Lisp_Float); | ||
| 5395 | tot += total_intervals * sizeof (struct interval); | ||
| 5396 | tot += total_strings * sizeof (struct Lisp_String); | ||
| 5397 | return tot; | ||
| 5398 | } | ||
| 5399 | |||
| 5383 | DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "", | 5400 | DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "", |
| 5384 | doc: /* Reclaim storage for Lisp objects no longer needed. | 5401 | doc: /* Reclaim storage for Lisp objects no longer needed. |
| 5385 | Garbage collection happens automatically if you cons more than | 5402 | Garbage collection happens automatically if you cons more than |
| @@ -5405,6 +5422,7 @@ See Info node `(elisp)Garbage Collection'. */) | |||
| 5405 | ptrdiff_t count = SPECPDL_INDEX (); | 5422 | ptrdiff_t count = SPECPDL_INDEX (); |
| 5406 | EMACS_TIME start; | 5423 | EMACS_TIME start; |
| 5407 | Lisp_Object retval = Qnil; | 5424 | Lisp_Object retval = Qnil; |
| 5425 | size_t tot_before = 0; | ||
| 5408 | 5426 | ||
| 5409 | if (abort_on_gc) | 5427 | if (abort_on_gc) |
| 5410 | abort (); | 5428 | abort (); |
| @@ -5421,6 +5439,9 @@ See Info node `(elisp)Garbage Collection'. */) | |||
| 5421 | FOR_EACH_BUFFER (nextb) | 5439 | FOR_EACH_BUFFER (nextb) |
| 5422 | compact_buffer (nextb); | 5440 | compact_buffer (nextb); |
| 5423 | 5441 | ||
| 5442 | if (memory_profiler_running) | ||
| 5443 | tot_before = total_bytes_of_live_objects (); | ||
| 5444 | |||
| 5424 | start = current_emacs_time (); | 5445 | start = current_emacs_time (); |
| 5425 | 5446 | ||
| 5426 | /* In case user calls debug_print during GC, | 5447 | /* In case user calls debug_print during GC, |
| @@ -5467,6 +5488,7 @@ See Info node `(elisp)Garbage Collection'. */) | |||
| 5467 | shrink_regexp_cache (); | 5488 | shrink_regexp_cache (); |
| 5468 | 5489 | ||
| 5469 | gc_in_progress = 1; | 5490 | gc_in_progress = 1; |
| 5491 | is_in_trace = 1; | ||
| 5470 | 5492 | ||
| 5471 | /* Mark all the special slots that serve as the roots of accessibility. */ | 5493 | /* Mark all the special slots that serve as the roots of accessibility. */ |
| 5472 | 5494 | ||
| @@ -5587,6 +5609,7 @@ See Info node `(elisp)Garbage Collection'. */) | |||
| 5587 | check_cons_list (); | 5609 | check_cons_list (); |
| 5588 | 5610 | ||
| 5589 | gc_in_progress = 0; | 5611 | gc_in_progress = 0; |
| 5612 | is_in_trace = 0; | ||
| 5590 | 5613 | ||
| 5591 | consing_since_gc = 0; | 5614 | consing_since_gc = 0; |
| 5592 | if (gc_cons_threshold < GC_DEFAULT_THRESHOLD / 10) | 5615 | if (gc_cons_threshold < GC_DEFAULT_THRESHOLD / 10) |
| @@ -5595,16 +5618,7 @@ See Info node `(elisp)Garbage Collection'. */) | |||
| 5595 | gc_relative_threshold = 0; | 5618 | gc_relative_threshold = 0; |
| 5596 | if (FLOATP (Vgc_cons_percentage)) | 5619 | if (FLOATP (Vgc_cons_percentage)) |
| 5597 | { /* Set gc_cons_combined_threshold. */ | 5620 | { /* Set gc_cons_combined_threshold. */ |
| 5598 | double tot = 0; | 5621 | double tot = total_bytes_of_live_objects (); |
| 5599 | |||
| 5600 | tot += total_conses * sizeof (struct Lisp_Cons); | ||
| 5601 | tot += total_symbols * sizeof (struct Lisp_Symbol); | ||
| 5602 | tot += total_markers * sizeof (union Lisp_Misc); | ||
| 5603 | tot += total_string_bytes; | ||
| 5604 | tot += total_vector_slots * word_size; | ||
| 5605 | tot += total_floats * sizeof (struct Lisp_Float); | ||
| 5606 | tot += total_intervals * sizeof (struct interval); | ||
| 5607 | tot += total_strings * sizeof (struct Lisp_String); | ||
| 5608 | 5622 | ||
| 5609 | tot *= XFLOAT_DATA (Vgc_cons_percentage); | 5623 | tot *= XFLOAT_DATA (Vgc_cons_percentage); |
| 5610 | if (0 < tot) | 5624 | if (0 < tot) |
| @@ -5707,6 +5721,25 @@ See Info node `(elisp)Garbage Collection'. */) | |||
| 5707 | 5721 | ||
| 5708 | gcs_done++; | 5722 | gcs_done++; |
| 5709 | 5723 | ||
| 5724 | /* Collect profiling data. */ | ||
| 5725 | if (sample_profiler_running || memory_profiler_running) | ||
| 5726 | { | ||
| 5727 | size_t swept = 0; | ||
| 5728 | size_t elapsed = 0; | ||
| 5729 | if (memory_profiler_running) | ||
| 5730 | { | ||
| 5731 | size_t tot_after = total_bytes_of_live_objects (); | ||
| 5732 | if (tot_before > tot_after) | ||
| 5733 | swept = tot_before - tot_after; | ||
| 5734 | } | ||
| 5735 | if (sample_profiler_running) | ||
| 5736 | { | ||
| 5737 | EMACS_TIME since_start = sub_emacs_time (current_emacs_time (), start); | ||
| 5738 | elapsed = EMACS_TIME_TO_DOUBLE (since_start) * 1000; | ||
| 5739 | } | ||
| 5740 | gc_probe (swept, elapsed); | ||
| 5741 | } | ||
| 5742 | |||
| 5710 | return retval; | 5743 | return retval; |
| 5711 | } | 5744 | } |
| 5712 | 5745 | ||