Mercurial > hg > xemacs-beta
comparison src/alloc.c @ 5058:eb17f0c176ac
clean up a bit the object-memory-usage-stats after gc
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-02-21 Ben Wing <ben@xemacs.org>
* alloc.c:
* alloc.c (pluralize_word):
New function to pluralize a word.
* alloc.c (pluralize_and_append): New function.
* alloc.c (object_memory_usage_stats):
Clean up duplication.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Sun, 21 Feb 2010 05:19:08 -0600 |
parents | d4f666cda5e6 |
children | c8f90d61dcf3 |
comparison
equal
deleted
inserted
replaced
5052:92dc90c0bb40 | 5058:eb17f0c176ac |
---|---|
4464 or portable numeric datatypes, or bit-vectors, or characters, or | 4464 or portable numeric datatypes, or bit-vectors, or characters, or |
4465 arrays, or exceptions, or ...) */ | 4465 arrays, or exceptions, or ...) */ |
4466 return cons3 (intern (name), make_int (value), tail); | 4466 return cons3 (intern (name), make_int (value), tail); |
4467 } | 4467 } |
4468 | 4468 |
4469 /* Pluralize a lowercase English word stored in BUF, assuming BUF has | |
4470 enough space to hold the extra letters (at most 2). */ | |
4471 static void | |
4472 pluralize_word (Ascbyte *buf) | |
4473 { | |
4474 Bytecount len = strlen (buf); | |
4475 int upper = 0; | |
4476 Ascbyte d, e; | |
4477 | |
4478 if (len == 0 || len == 1) | |
4479 goto pluralize_apostrophe_s; | |
4480 e = buf[len - 1]; | |
4481 d = buf[len - 2]; | |
4482 upper = isupper (e); | |
4483 e = tolower (e); | |
4484 d = tolower (d); | |
4485 if (e == 'y') | |
4486 { | |
4487 switch (d) | |
4488 { | |
4489 case 'a': | |
4490 case 'e': | |
4491 case 'i': | |
4492 case 'o': | |
4493 case 'u': | |
4494 goto pluralize_s; | |
4495 default: | |
4496 buf[len - 1] = (upper ? 'I' : 'i'); | |
4497 goto pluralize_es; | |
4498 } | |
4499 } | |
4500 else if (e == 's' || e == 'x' || (e == 'h' && (d == 's' || d == 'c'))) | |
4501 { | |
4502 pluralize_es: | |
4503 buf[len++] = (upper ? 'E' : 'e'); | |
4504 } | |
4505 pluralize_s: | |
4506 buf[len++] = (upper ? 'S' : 's'); | |
4507 buf[len] = '\0'; | |
4508 return; | |
4509 | |
4510 pluralize_apostrophe_s: | |
4511 buf[len++] = '\''; | |
4512 goto pluralize_s; | |
4513 } | |
4514 | |
4515 static void | |
4516 pluralize_and_append (Ascbyte *buf, const Ascbyte *name, const Ascbyte *suffix) | |
4517 { | |
4518 strcpy (buf, name); | |
4519 pluralize_word (buf); | |
4520 strcat (buf, suffix); | |
4521 } | |
4522 | |
4469 static Lisp_Object | 4523 static Lisp_Object |
4470 object_memory_usage_stats (int set_total_gc_usage) | 4524 object_memory_usage_stats (int set_total_gc_usage) |
4471 { | 4525 { |
4472 Lisp_Object pl = Qnil; | 4526 Lisp_Object pl = Qnil; |
4473 int i; | 4527 int i; |
4496 sprintf (buf, "%s-storage", name); | 4550 sprintf (buf, "%s-storage", name); |
4497 pl = gc_plist_hack (buf, | 4551 pl = gc_plist_hack (buf, |
4498 lrecord_stats[i].bytes_in_use, | 4552 lrecord_stats[i].bytes_in_use, |
4499 pl); | 4553 pl); |
4500 tgu_val += lrecord_stats[i].bytes_in_use_including_overhead; | 4554 tgu_val += lrecord_stats[i].bytes_in_use_including_overhead; |
4501 | 4555 |
4502 if (name[len-1] == 's') | 4556 pluralize_and_append (buf, name, "-used"); |
4503 sprintf (buf, "%ses-used", name); | |
4504 else | |
4505 sprintf (buf, "%ss-used", name); | |
4506 pl = gc_plist_hack (buf, lrecord_stats[i].instances_in_use, pl); | 4557 pl = gc_plist_hack (buf, lrecord_stats[i].instances_in_use, pl); |
4507 } | 4558 } |
4508 } | 4559 } |
4509 | 4560 |
4510 #else /* not NEW_GC */ | 4561 #else /* not NEW_GC */ |
4523 || lcrecord_stats[i].bytes_freed != 0 | 4574 || lcrecord_stats[i].bytes_freed != 0 |
4524 || lcrecord_stats[i].instances_on_free_list != 0) | 4575 || lcrecord_stats[i].instances_on_free_list != 0) |
4525 { | 4576 { |
4526 Ascbyte buf[255]; | 4577 Ascbyte buf[255]; |
4527 const Ascbyte *name = lrecord_implementations_table[i]->name; | 4578 const Ascbyte *name = lrecord_implementations_table[i]->name; |
4528 int len = strlen (name); | |
4529 | 4579 |
4530 sprintf (buf, "%s-storage", name); | 4580 sprintf (buf, "%s-storage", name); |
4531 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl); | 4581 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl); |
4532 tgu_val += lcrecord_stats[i].bytes_in_use; | 4582 tgu_val += lcrecord_stats[i].bytes_in_use; |
4533 /* Okay, simple pluralization check for `symbol-value-varalias' */ | 4583 pluralize_and_append (buf, name, "-freed"); |
4534 if (name[len-1] == 's') | |
4535 sprintf (buf, "%ses-freed", name); | |
4536 else | |
4537 sprintf (buf, "%ss-freed", name); | |
4538 if (lcrecord_stats[i].instances_freed != 0) | 4584 if (lcrecord_stats[i].instances_freed != 0) |
4539 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_freed, pl); | 4585 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_freed, pl); |
4540 if (name[len-1] == 's') | 4586 pluralize_and_append (buf, name, "-on-free-list"); |
4541 sprintf (buf, "%ses-on-free-list", name); | |
4542 else | |
4543 sprintf (buf, "%ss-on-free-list", name); | |
4544 if (lcrecord_stats[i].instances_on_free_list != 0) | 4587 if (lcrecord_stats[i].instances_on_free_list != 0) |
4545 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_on_free_list, | 4588 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_on_free_list, |
4546 pl); | 4589 pl); |
4547 if (name[len-1] == 's') | 4590 pluralize_and_append (buf, name, "-used"); |
4548 sprintf (buf, "%ses-used", name); | |
4549 else | |
4550 sprintf (buf, "%ss-used", name); | |
4551 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_in_use, pl); | 4591 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_in_use, pl); |
4552 } | 4592 } |
4553 } | 4593 } |
4554 | 4594 |
4555 HACK_O_MATIC (extent, "extent-storage", pl); | 4595 /* The most general version -- handle TYPE, with strings using ENGTYPE |
4556 pl = gc_plist_hack ("extents-free", gc_count_num_extent_freelist, pl); | 4596 instead (generally the same, but with hyphen in place of underscore) |
4557 pl = gc_plist_hack ("extents-used", gc_count_num_extent_in_use, pl); | 4597 and ENGTYPES as the plural of ENGTYPE. */ |
4558 HACK_O_MATIC (event, "event-storage", pl); | 4598 #define FROB3(type, engtype, engtypes) \ |
4559 pl = gc_plist_hack ("events-free", gc_count_num_event_freelist, pl); | 4599 HACK_O_MATIC (type, engtype "-storage", pl); \ |
4560 pl = gc_plist_hack ("events-used", gc_count_num_event_in_use, pl); | 4600 pl = gc_plist_hack (engtypes "-free", gc_count_num_##type##_freelist, pl); \ |
4561 HACK_O_MATIC (marker, "marker-storage", pl); | 4601 pl = gc_plist_hack (engtypes "-used", gc_count_num_##type##_in_use, pl) |
4562 pl = gc_plist_hack ("markers-free", gc_count_num_marker_freelist, pl); | 4602 |
4563 pl = gc_plist_hack ("markers-used", gc_count_num_marker_in_use, pl); | 4603 #define FROB(type) FROB3(type, #type, #type "s") |
4564 HACK_O_MATIC (float, "float-storage", pl); | 4604 |
4565 pl = gc_plist_hack ("floats-free", gc_count_num_float_freelist, pl); | 4605 FROB (extent); |
4566 pl = gc_plist_hack ("floats-used", gc_count_num_float_in_use, pl); | 4606 FROB (event); |
4607 FROB (marker); | |
4608 FROB (float); | |
4567 #ifdef HAVE_BIGNUM | 4609 #ifdef HAVE_BIGNUM |
4568 HACK_O_MATIC (bignum, "bignum-storage", pl); | 4610 FROB (bignum); |
4569 pl = gc_plist_hack ("bignums-free", gc_count_num_bignum_freelist, pl); | |
4570 pl = gc_plist_hack ("bignums-used", gc_count_num_bignum_in_use, pl); | |
4571 #endif /* HAVE_BIGNUM */ | 4611 #endif /* HAVE_BIGNUM */ |
4572 #ifdef HAVE_RATIO | 4612 #ifdef HAVE_RATIO |
4573 HACK_O_MATIC (ratio, "ratio-storage", pl); | 4613 FROB (ratio); |
4574 pl = gc_plist_hack ("ratios-free", gc_count_num_ratio_freelist, pl); | |
4575 pl = gc_plist_hack ("ratios-used", gc_count_num_ratio_in_use, pl); | |
4576 #endif /* HAVE_RATIO */ | 4614 #endif /* HAVE_RATIO */ |
4577 #ifdef HAVE_BIGFLOAT | 4615 #ifdef HAVE_BIGFLOAT |
4578 HACK_O_MATIC (bigfloat, "bigfloat-storage", pl); | 4616 FROB (bigfloat); |
4579 pl = gc_plist_hack ("bigfloats-free", gc_count_num_bigfloat_freelist, pl); | |
4580 pl = gc_plist_hack ("bigfloats-used", gc_count_num_bigfloat_in_use, pl); | |
4581 #endif /* HAVE_BIGFLOAT */ | 4617 #endif /* HAVE_BIGFLOAT */ |
4582 HACK_O_MATIC (string, "string-header-storage", pl); | 4618 HACK_O_MATIC (string, "string-header-storage", pl); |
4583 pl = gc_plist_hack ("long-strings-total-length", | 4619 pl = gc_plist_hack ("long-strings-total-length", |
4584 gc_count_string_total_size | 4620 gc_count_string_total_size |
4585 - gc_count_short_string_total_size, pl); | 4621 - gc_count_short_string_total_size, pl); |
4591 gc_count_num_string_in_use | 4627 gc_count_num_string_in_use |
4592 - gc_count_num_short_string_in_use, pl); | 4628 - gc_count_num_short_string_in_use, pl); |
4593 pl = gc_plist_hack ("short-strings-used", | 4629 pl = gc_plist_hack ("short-strings-used", |
4594 gc_count_num_short_string_in_use, pl); | 4630 gc_count_num_short_string_in_use, pl); |
4595 | 4631 |
4596 HACK_O_MATIC (compiled_function, "compiled-function-storage", pl); | 4632 FROB3 (compiled_function, "compiled-function", "compiled-functions"); |
4597 pl = gc_plist_hack ("compiled-functions-free", | 4633 FROB (symbol); |
4598 gc_count_num_compiled_function_freelist, pl); | 4634 FROB3 (cons, "cons", "conses"); |
4599 pl = gc_plist_hack ("compiled-functions-used", | |
4600 gc_count_num_compiled_function_in_use, pl); | |
4601 | |
4602 HACK_O_MATIC (symbol, "symbol-storage", pl); | |
4603 pl = gc_plist_hack ("symbols-free", gc_count_num_symbol_freelist, pl); | |
4604 pl = gc_plist_hack ("symbols-used", gc_count_num_symbol_in_use, pl); | |
4605 | |
4606 HACK_O_MATIC (cons, "cons-storage", pl); | |
4607 pl = gc_plist_hack ("conses-free", gc_count_num_cons_freelist, pl); | |
4608 pl = gc_plist_hack ("conses-used", gc_count_num_cons_in_use, pl); | |
4609 | 4635 |
4610 #undef HACK_O_MATIC | 4636 #undef HACK_O_MATIC |
4611 | 4637 |
4612 #endif /* NEW_GC */ | 4638 #endif /* NEW_GC */ |
4613 | 4639 |