comparison Python/sysmodule.c @ 3024:54aa87b1ccee legacy-trunk

Implemented two new functions in sys: getcounts() returns a list of counts of allocations and deallocations for all different object types. getobjects(n [, type ]) returns a list of recently allocated and not-yet-freed objects of the given type (all objects if no type given). Only the n most recent (all if n==0) objects are returned. getcounts is only available if compiled with -DCOUNT_ALLOCS, getobjects is only available if compiled with -DTRACE_REFS. Note that everything must be compiled with these options!
author Sjoerd Mullender <sjoerd@acm.org>
date Tue, 29 Aug 1995 09:18:14 +0000
parents fc2190ec1bea
children 1eab8495462f
comparison
equal deleted inserted replaced
3023:87847228b158 3024:54aa87b1ccee
152 INCREF(None); 152 INCREF(None);
153 return None; 153 return None;
154 } 154 }
155 #endif /* USE_MALLOPT */ 155 #endif /* USE_MALLOPT */
156 156
157 static object *
158 sys_getrefcount(self, args)
159 object *self;
160 object *args;
161 {
162 object *arg;
163 if (!getargs(args, "O", &arg))
164 return NULL;
165 return newintobject((long) arg->ob_refcnt);
166 }
167
168 #ifdef COUNT_ALLOCS
169 static PyObject *
170 sys_getcounts(self, args)
171 PyObject *self, *args;
172 {
173 extern PyObject *get_counts Py_PROTO((void));
174
175 if (!PyArg_Parse(args, ""))
176 return NULL;
177 return get_counts();
178 }
179 #endif
180
181 #ifdef TRACE_REFS
182 extern PyObject *getobjects Py_PROTO((PyObject *, PyObject *));
183 #endif
157 static struct methodlist sys_methods[] = { 184 static struct methodlist sys_methods[] = {
158 {"exit", sys_exit, 0}, 185 {"exit", sys_exit, 0},
186 {"getrefcount", sys_getrefcount, 0},
187 #ifdef COUNT_ALLOCS
188 {"getcounts", sys_getcounts, 0},
189 #endif
190 #ifdef TRACE_REFS
191 {"getobjects", getobjects, 1},
192 #endif
159 #ifdef USE_MALLOPT 193 #ifdef USE_MALLOPT
160 {"mdebug", sys_mdebug, 0}, 194 {"mdebug", sys_mdebug, 0},
161 #endif 195 #endif
162 {"setprofile", sys_setprofile, 0}, 196 {"setprofile", sys_setprofile, 0},
163 {"settrace", sys_settrace, 0}, 197 {"settrace", sys_settrace, 0},