[前][次][番号順一覧][スレッド一覧]

ruby-changes:46750

From: ko1 <ko1@a...>
Date: Wed, 24 May 2017 15:46:50 +0900 (JST)
Subject: [ruby-changes:46750] ko1:r58865 (trunk): Add debug counters.

ko1	2017-05-24 15:46:44 +0900 (Wed, 24 May 2017)

  New Revision: 58865

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58865

  Log:
    Add debug counters.
    
    * debug_counter.h: add the following counters to measure object types.
      obj_free: freed count
      obj_str_ptr: freed count of Strings they have extra buff.
      obj_str_embed: freed count of Strings they don't have extra buff.
      obj_str_shared: freed count of Strings they have shared extra buff.
      obj_str_nofree: freed count of Strings they are marked as nofree.
      obj_str_fstr: freed count of Strings they are marked as fstr.
      obj_ary_ptr: freed count of Arrays they have extra buff.
      obj_ary_embed: freed count of Arrays they don't have extra buff.
      obj_obj_ptr: freed count of Objects (T_OBJECT) they have extra buff.
      obj_obj_embed: freed count of Objects they don't have extra buff.

  Modified files:
    trunk/array.c
    trunk/common.mk
    trunk/debug_counter.h
    trunk/gc.c
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 58864)
+++ string.c	(revision 58865)
@@ -18,6 +18,7 @@ https://github.com/ruby/ruby/blob/trunk/string.c#L18
 #include "gc.h"
 #include "ruby_assert.h"
 #include "id.h"
+#include "debug_counter.h"
 
 #define BEG(no) (regs->beg[(no)])
 #define END(no) (regs->end[(no)])
@@ -1310,9 +1311,18 @@ rb_str_free(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L1311
     if (FL_TEST(str, RSTRING_FSTR)) {
 	st_data_t fstr = (st_data_t)str;
 	st_delete(rb_vm_fstring_table(), &fstr, NULL);
+	RB_DEBUG_COUNTER_INC(obj_str_fstr);
     }
 
-    if (!STR_EMBED_P(str) && !FL_TEST(str, STR_SHARED|STR_NOFREE)) {
+    if (STR_EMBED_P(str)) {
+	RB_DEBUG_COUNTER_INC(obj_str_embed);
+    }
+    else if (FL_TEST(str, STR_SHARED | STR_NOFREE)) {
+	(void)RB_DEBUG_COUNTER_INC_IF(obj_str_shared, FL_TEST(str, STR_SHARED));
+	(void)RB_DEBUG_COUNTER_INC_IF(obj_str_shared, FL_TEST(str, STR_NOFREE));
+    }
+    else {
+	RB_DEBUG_COUNTER_INC(obj_str_ptr);
 	ruby_sized_xfree(STR_HEAP_PTR(str), STR_HEAP_SIZE(str));
     }
 }
Index: gc.c
===================================================================
--- gc.c	(revision 58864)
+++ gc.c	(revision 58865)
@@ -33,6 +33,7 @@ https://github.com/ruby/ruby/blob/trunk/gc.c#L33
 #include <setjmp.h>
 #include <sys/types.h>
 #include "ruby_assert.h"
+#include "debug_counter.h"
 
 #undef rb_data_object_wrap
 
@@ -2103,6 +2104,8 @@ make_io_zombie(rb_objspace_t *objspace, https://github.com/ruby/ruby/blob/trunk/gc.c#L2104
 static int
 obj_free(rb_objspace_t *objspace, VALUE obj)
 {
+    RB_DEBUG_COUNTER_INC(obj_free);
+
     gc_event_hook(objspace, RUBY_INTERNAL_EVENT_FREEOBJ, obj);
 
     switch (BUILTIN_TYPE(obj)) {
@@ -2137,6 +2140,10 @@ obj_free(rb_objspace_t *objspace, VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L2140
 	if (!(RANY(obj)->as.basic.flags & ROBJECT_EMBED) &&
             RANY(obj)->as.object.as.heap.ivptr) {
 	    xfree(RANY(obj)->as.object.as.heap.ivptr);
+	    RB_DEBUG_COUNTER_INC(obj_obj_ptr);
+	}
+	else {
+	    RB_DEBUG_COUNTER_INC(obj_obj_embed);
 	}
 	break;
       case T_MODULE:
Index: array.c
===================================================================
--- array.c	(revision 58864)
+++ array.c	(revision 58865)
@@ -16,6 +16,7 @@ https://github.com/ruby/ruby/blob/trunk/array.c#L16
 #include "ruby/st.h"
 #include "probes.h"
 #include "id.h"
+#include "debug_counter.h"
 
 #ifndef ARRAY_DEBUG
 # define NDEBUG
@@ -553,8 +554,12 @@ void https://github.com/ruby/ruby/blob/trunk/array.c#L554
 rb_ary_free(VALUE ary)
 {
     if (ARY_OWNS_HEAP_P(ary)) {
+	RB_DEBUG_COUNTER_INC(obj_ary_ptr);
 	ruby_sized_xfree((void *)ARY_HEAP_PTR(ary), ARY_HEAP_SIZE(ary));
     }
+    else {
+	RB_DEBUG_COUNTER_INC(obj_ary_embed);
+    }
 }
 
 RUBY_FUNC_EXPORTED size_t
Index: debug_counter.h
===================================================================
--- debug_counter.h	(revision 58864)
+++ debug_counter.h	(revision 58865)
@@ -22,6 +22,7 @@ RB_DEBUG_COUNTER(mc_class_serial_miss) https://github.com/ruby/ruby/blob/trunk/debug_counter.h#L22
 RB_DEBUG_COUNTER(mc_cme_complement)
 RB_DEBUG_COUNTER(mc_cme_complement_hit)
 RB_DEBUG_COUNTER(mc_search_super)
+
 RB_DEBUG_COUNTER(ivar_get_ic_hit)
 RB_DEBUG_COUNTER(ivar_get_ic_miss)
 RB_DEBUG_COUNTER(ivar_get_ic_miss_serial)
@@ -35,6 +36,21 @@ RB_DEBUG_COUNTER(ivar_set_ic_miss_oorang https://github.com/ruby/ruby/blob/trunk/debug_counter.h#L36
 RB_DEBUG_COUNTER(ivar_set_ic_miss_noobject)
 RB_DEBUG_COUNTER(ivar_get_base)
 RB_DEBUG_COUNTER(ivar_set_base)
+
+/* object counts */
+RB_DEBUG_COUNTER(obj_free)
+
+RB_DEBUG_COUNTER(obj_str_ptr)
+RB_DEBUG_COUNTER(obj_str_embed)
+RB_DEBUG_COUNTER(obj_str_shared)
+RB_DEBUG_COUNTER(obj_str_nofree)
+RB_DEBUG_COUNTER(obj_str_fstr)
+
+RB_DEBUG_COUNTER(obj_ary_ptr)
+RB_DEBUG_COUNTER(obj_ary_embed)
+
+RB_DEBUG_COUNTER(obj_obj_ptr)
+RB_DEBUG_COUNTER(obj_obj_embed)
 #endif
 
 #ifndef RUBY_DEBUG_COUNTER_H
Index: common.mk
===================================================================
--- common.mk	(revision 58864)
+++ common.mk	(revision 58865)
@@ -1303,6 +1303,7 @@ array.$(OBJEXT): $(hdrdir)/ruby/ruby.h https://github.com/ruby/ruby/blob/trunk/common.mk#L1303
 array.$(OBJEXT): $(top_srcdir)/include/ruby.h
 array.$(OBJEXT): {$(VPATH)}array.c
 array.$(OBJEXT): {$(VPATH)}config.h
+array.$(OBJEXT): {$(VPATH)}debug_counter.h
 array.$(OBJEXT): {$(VPATH)}defines.h
 array.$(OBJEXT): {$(VPATH)}encoding.h
 array.$(OBJEXT): {$(VPATH)}id.h
@@ -1735,6 +1736,7 @@ gc.$(OBJEXT): $(top_srcdir)/include/ruby https://github.com/ruby/ruby/blob/trunk/common.mk#L1736
 gc.$(OBJEXT): {$(VPATH)}config.h
 gc.$(OBJEXT): {$(VPATH)}constant.h
 gc.$(OBJEXT): {$(VPATH)}debug.h
+gc.$(OBJEXT): {$(VPATH)}debug_counter.h
 gc.$(OBJEXT): {$(VPATH)}defines.h
 gc.$(OBJEXT): {$(VPATH)}encoding.h
 gc.$(OBJEXT): {$(VPATH)}eval_intern.h
@@ -2505,6 +2507,7 @@ string.$(OBJEXT): $(top_srcdir)/include/ https://github.com/ruby/ruby/blob/trunk/common.mk#L2507
 string.$(OBJEXT): {$(VPATH)}config.h
 string.$(OBJEXT): {$(VPATH)}crypt.h
 string.$(OBJEXT): {$(VPATH)}defines.h
+string.$(OBJEXT): {$(VPATH)}debug_counter.h
 string.$(OBJEXT): {$(VPATH)}encindex.h
 string.$(OBJEXT): {$(VPATH)}encoding.h
 string.$(OBJEXT): {$(VPATH)}gc.h

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]