diff options
author | Sjoerd Mullender <sjoerd@acm.org> | 1995-08-29 09:18:14 (GMT) |
---|---|---|
committer | Sjoerd Mullender <sjoerd@acm.org> | 1995-08-29 09:18:14 (GMT) |
commit | 6ec3c653da9ffd098f522261d5592e64ff8e7889 (patch) | |
tree | 360bde69268001269a7dbd061551622b42c867e3 /Objects | |
parent | b0a2ce515b0342b96ab1bc89c588af471c0c2b0f (diff) | |
download | cpython-6ec3c653da9ffd098f522261d5592e64ff8e7889.zip cpython-6ec3c653da9ffd098f522261d5592e64ff8e7889.tar.gz cpython-6ec3c653da9ffd098f522261d5592e64ff8e7889.tar.bz2 |
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!
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c index 1643ec6..4899ef1 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -56,6 +56,33 @@ dump_counts() null_strings, one_strings); } +PyObject * +get_counts() +{ + PyTypeObject *tp; + PyObject *result; + PyObject *v; + + result = PyList_New(0); + if (result == NULL) + return NULL; + for (tp = type_list; tp; tp = tp->tp_next) { + v = Py_BuildValue("(siii)", tp->tp_name, tp->tp_alloc, + tp->tp_free, tp->tp_maxalloc); + if (v == NULL) { + Py_DECREF(result); + return NULL; + } + if (PyList_Append(result, v) < 0) { + Py_DECREF(v); + Py_DECREF(result); + return NULL; + } + Py_DECREF(v); + } + return result; +} + void inc_count(tp) typeobject *tp; @@ -513,4 +540,35 @@ printrefs(fp) } } +PyObject * +getobjects(self, args) + PyObject *self; + PyObject *args; +{ + int i, n; + PyObject *t = NULL; + PyObject *res, *op; + + if (!PyArg_ParseTuple(args, "i|O", &n, &t)) + return NULL; + op = refchain._ob_next; + res = PyList_New(0); + if (res == NULL) + return NULL; + for (i = 0; (n == 0 || i < n) && op != &refchain; i++) { + while (op == self || op == args || op == res || op == t || + t != NULL && op->ob_type != (PyTypeObject *) t) { + op = op->_ob_next; + if (op == &refchain) + return res; + } + if (PyList_Append(res, op) < 0) { + Py_DECREF(res); + return NULL; + } + op = op->_ob_next; + } + return res; +} + #endif |