Rev 90: A few more tweaks. in http://bazaar.launchpad.net/~meliae-dev/meliae/trunk
John Arbash Meinel
john at arbash-meinel.com
Wed Oct 7 22:40:10 BST 2009
At http://bazaar.launchpad.net/~meliae-dev/meliae/trunk
------------------------------------------------------------
revno: 90
revision-id: john at arbash-meinel.com-20091007213953-s7byaxh7adrfeaja
parent: john at arbash-meinel.com-20091007205438-ptdk6k1k2rohfjpd
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Wed 2009-10-07 16:39:53 -0500
message:
A few more tweaks.
Fix up the regex string so that values don't preserve the "" quoting from json.
This should shrink memory slightly as then all the 'value' entries are 2 bytes
shorter. A minor thing, but it also allows us to directly check foo.value
against what we expect it to be.
Add Summary.by_count() so you can change the sort order.
Some minor tweaks in the scanner code. We now track the object we just dumped,
and don't dump it a second time.
This mostly effects dumping things like the string interned dict, since that
references each string 2x for each entry. Minor, but helpful.
-------------- next part --------------
=== modified file 'meliae/_scanner.pyx'
--- a/meliae/_scanner.pyx 2009-09-30 15:52:21 +0000
+++ b/meliae/_scanner.pyx 2009-10-07 21:39:53 +0000
@@ -34,6 +34,7 @@
Py_ssize_t _size_of(object c_obj)
ctypedef void (*write_callback)(void *callee_data, char *bytes, size_t len)
+ void _clear_last_dumped()
void _dump_object_info(write_callback write, void *callee_data,
object c_obj, object nodump, int recurse)
object _get_referents(object c_obj)
@@ -98,6 +99,7 @@
else:
_dump_object_info(<write_callback>_callable_callback, <void *>out, obj,
nodump, recurse_depth)
+ _clear_last_dumped()
def get_referents(object obj):
=== modified file 'meliae/_scanner_core.c'
--- a/meliae/_scanner_core.c 2009-10-07 20:54:38 +0000
+++ b/meliae/_scanner_core.c 2009-10-07 21:39:53 +0000
@@ -61,6 +61,18 @@
static void _write_to_ref_info(struct ref_info *info, const char *fmt_string, ...);
#endif
+/* The address of the last thing we dumped. Stuff like dumping the string
+ * interned dictionary will dump the same string 2x in a row. This helps
+ * prevent that.
+ */
+static PyObject *_last_dumped = NULL;
+
+void
+_clear_last_dumped()
+{
+ _last_dumped = NULL;
+}
+
Py_ssize_t
_basic_object_size(PyObject *c_obj)
{
@@ -367,6 +379,11 @@
}
}
+ if (c_obj == _last_dumped) {
+ /* We just dumped this object, no need to do it again. */
+ return;
+ }
+ _last_dumped = c_obj;
size = _size_of(c_obj);
_write_to_ref_info(info, "{\"address\": %lu, \"type\": ",
(unsigned long)c_obj);
=== modified file 'meliae/_scanner_core.h'
--- a/meliae/_scanner_core.h 2009-09-11 16:51:39 +0000
+++ b/meliae/_scanner_core.h 2009-10-07 21:39:53 +0000
@@ -32,7 +32,7 @@
* number of bytes for the basic list object. Note that lists over-allocate, so
* this is not strictly sizeof(pointer) * num_items.
*/
-Py_ssize_t _size_of(PyObject *c_obj);
+extern Py_ssize_t _size_of(PyObject *c_obj);
/**
* This callback will be used to dump more info to the user.
@@ -42,13 +42,18 @@
/**
* Write the information about this object to the file.
*/
-void _dump_object_info(write_callback write, void *callee_data,
- PyObject *c_obj, PyObject *nodump, int recurse);
+extern void _dump_object_info(write_callback write, void *callee_data,
+ PyObject *c_obj, PyObject *nodump, int recurse);
+
+/**
+ * Clear out what the last object we dumped was.
+ */
+extern void _clear_last_dumped();
/**
* Return a PyList of all objects referenced via tp_traverse.
*/
-PyObject *_get_referents(PyObject *c_obj);
+extern PyObject *_get_referents(PyObject *c_obj);
#endif // _SCANNER_CORE_H_
=== modified file 'meliae/loader.py'
--- a/meliae/loader.py 2009-09-18 17:00:34 +0000
+++ b/meliae/loader.py 2009-10-07 21:39:53 +0000
@@ -42,7 +42,7 @@
r', "size": (?P<size>\d+)'
r'(, "name": "(?P<name>.*)")?'
r'(, "len": (?P<len>\d+))?'
- r'(, "value": (?P<value>.*))?'
+ r'(, "value": "?(?P<value>.*?)"?)?'
r', "refs": \[(?P<refs>[^]]*)\]'
r'\}')
@@ -178,6 +178,12 @@
reverse=True)
self.summaries = summaries
+ def by_count(self):
+ summaries = sorted(self.type_summaries.itervalues(),
+ key=lambda x: (x.count, x.total_size),
+ reverse=True)
+ self.summaries = summaries
+
class ObjManager(object):
"""Manage the collection of MemObjects.
More information about the bazaar-commits
mailing list