Author: Carl Friedrich Bolz <[email protected]>
Branch: dict-strategies
Changeset: r44471:e8dde724d3cf
Date: 2011-05-25 17:46 +0200
http://bitbucket.org/pypy/pypy/changeset/e8dde724d3cf/
Log: the whole MeasuringDictImplementation is broken since ages, kill it.
can be ressurected later if necessary
diff --git a/pypy/objspace/std/dictmultiobject.py
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -482,179 +482,6 @@
return None, None
-
-# XXX fix this thing
-import time
-
-class DictInfo(object):
- _dict_infos = []
- def __init__(self):
- self.id = len(self._dict_infos)
-
- self.setitem_strs = 0; self.setitems = 0; self.delitems = 0
- self.lengths = 0; self.gets = 0
- self.iteritems = 0; self.iterkeys = 0; self.itervalues = 0
- self.keys = 0; self.values = 0; self.items = 0
-
- self.maxcontents = 0
-
- self.reads = 0
- self.hits = self.misses = 0
- self.writes = 0
- self.iterations = 0
- self.listings = 0
-
- self.seen_non_string_in_write = 0
- self.seen_non_string_in_read_first = 0
- self.size_on_non_string_seen_in_read = -1
- self.size_on_non_string_seen_in_write = -1
-
- self.createtime = time.time()
- self.lifetime = -1.0
-
- if not we_are_translated():
- # very probable stack from here:
- # 0 - us
- # 1 - MeasuringDictImplementation.__init__
- # 2 - W_DictMultiObject.__init__
- # 3 - space.newdict
- # 4 - newdict's caller. let's look at that
- try:
- frame = sys._getframe(4)
- except ValueError:
- pass # might be at import time
- else:
- self.sig = '(%s:%s)%s'%(frame.f_code.co_filename,
frame.f_lineno, frame.f_code.co_name)
-
- self._dict_infos.append(self)
- def __repr__(self):
- args = []
- for k in sorted(self.__dict__):
- v = self.__dict__[k]
- if v != 0:
- args.append('%s=%r'%(k, v))
- return '<DictInfo %s>'%(', '.join(args),)
-
-class OnTheWayOut:
- def __init__(self, info):
- self.info = info
- def __del__(self):
- self.info.lifetime = time.time() - self.info.createtime
-
-class MeasuringDictImplementation(W_DictMultiObject):
- def __init__(self, space):
- self.space = space
- self.content = r_dict(space.eq_w, space.hash_w)
- self.info = DictInfo()
- self.thing_with_del = OnTheWayOut(self.info)
-
- def __repr__(self):
- return "%s<%s>" % (self.__class__.__name__, self.content)
-
- def _is_str(self, w_key):
- space = self.space
- return space.is_true(space.isinstance(w_key, space.w_str))
- def _read(self, w_key):
- self.info.reads += 1
- if not self.info.seen_non_string_in_write \
- and not self.info.seen_non_string_in_read_first \
- and not self._is_str(w_key):
- self.info.seen_non_string_in_read_first = True
- self.info.size_on_non_string_seen_in_read = len(self.content)
- hit = w_key in self.content
- if hit:
- self.info.hits += 1
- else:
- self.info.misses += 1
-
- def impl_setitem(self, w_dict, w_key, w_value):
- if not self.info.seen_non_string_in_write and not self._is_str(w_key):
- self.info.seen_non_string_in_write = True
- self.info.size_on_non_string_seen_in_write = len(self.content)
- self.info.setitems += 1
- self.info.writes += 1
- self.content[w_key] = w_value
- self.info.maxcontents = max(self.info.maxcontents, len(self.content))
- def impl_setitem_str(self, w_dict, key, w_value):
- self.info.setitem_strs += 1
- self.impl_setitem(self.space.wrap(key), w_value)
- def impl_delitem(self, w_dict, w_key):
- if not self.info.seen_non_string_in_write \
- and not self.info.seen_non_string_in_read_first \
- and not self._is_str(w_key):
- self.info.seen_non_string_in_read_first = True
- self.info.size_on_non_string_seen_in_read = len(self.content)
- self.info.delitems += 1
- self.info.writes += 1
- del self.content[w_key]
-
- def impl_length(self, w_dict):
- self.info.lengths += 1
- return len(self.content)
- def impl_getitem_str(self, w_dict, key):
- return self.impl_getitem(self.space.wrap(key))
- def impl_getitem(self, w_dict, w_key):
- self.info.gets += 1
- self._read(w_key)
- return self.content.get(w_key, None)
-
- def impl_iteritems(self, w_dict):
- self.info.iteritems += 1
- self.info.iterations += 1
- return RDictItemIteratorImplementation(self.space, self)
- def impl_iterkeys(self, w_dict):
- self.info.iterkeys += 1
- self.info.iterations += 1
- return RDictKeyIteratorImplementation(self.space, self)
- def impl_itervalues(self, w_dict):
- self.info.itervalues += 1
- self.info.iterations += 1
- return RDictValueIteratorImplementation(self.space, self)
-
- def impl_keys(self, w_dict):
- self.info.keys += 1
- self.info.listings += 1
- return self.content.keys()
- def impl_values(self, w_dict):
- self.info.values += 1
- self.info.listings += 1
- return self.content.values()
- def impl_items(self, w_dict):
- self.info.items += 1
- self.info.listings += 1
- return [self.space.newtuple([w_key, w_val])
- for w_key, w_val in self.content.iteritems()]
-
-
-_example = DictInfo()
-del DictInfo._dict_infos[-1]
-tmpl = 'os.write(fd, "%(attr)s" + ": " + str(info.%(attr)s) + "\\n")'
-bodySrc = []
-for attr in sorted(_example.__dict__):
- if attr == 'sig':
- continue
- bodySrc.append(tmpl%locals())
-exec py.code.Source('''
-from pypy.rlib.objectmodel import current_object_addr_as_int
-def _report_one(fd, info):
- os.write(fd, "_address" + ": " + str(current_object_addr_as_int(info))
- + "\\n")
- %s
-'''%'\n '.join(bodySrc)).compile()
-
-def report():
- if not DictInfo._dict_infos:
- return
- os.write(2, "Starting multidict report.\n")
- fd = os.open('dictinfo.txt', os.O_CREAT|os.O_WRONLY|os.O_TRUNC, 0644)
- for info in DictInfo._dict_infos:
- os.write(fd, '------------------\n')
- _report_one(fd, info)
- os.close(fd)
- os.write(2, "Reporting done.\n")
-
-
-
init_signature = Signature(['seq_or_map'], None, 'kwargs')
init_defaults = [None]
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit