# this is for use with a pypy-c build with multidicts and using the# MeasuringDictImplementation -- it will create a file called# 'dictinfo.txt' in the local directory and this file will turn the# contents back into DictInfo objects.# run with python -i !importsysif__name__=='__main__':infile=open(sys.argv[1])curr=Noneslots=[]forlineininfile:ifline=='------------------\n':ifcurr:breakcurr=1else:attr,val=[s.strip()forsinline.split(':')]slots.append(attr)classDictInfo(object):__slots__=slotsinfile=open(sys.argv[1])infos=[]forlineininfile:ifline=='------------------\n':curr=object.__new__(DictInfo)infos.append(curr)else:attr,val=[s.strip()forsinline.split(':')]if'.'inval:val=float(val)else:val=int(val)setattr(curr,attr,val)defhistogram(infos,keyattr,*attrs):r={}forinfoininfos:v=getattr(info,keyattr)l=r.setdefault(v,[0,{}])l[0]+=1forainattrs:d2=l[1].setdefault(a,{})v2=getattr(info,a)d2[v2]=d2.get(v2,0)+1returnsorted(r.items())defreportDictInfos():d={}stillAlive=0totLifetime=0.0forinfoininfos:forattrinslots:ifattr=='maxcontents':continuev=getattr(info,attr)ifnotisinstance(v,int):continued[attr]=d.get(attr,0)+vifinfo.lifetime!=-1.0:totLifetime+=info.lifetimeelse:stillAlive+=1print'read info on',len(infos),'dictionaries'ifstillAlive!=len(infos):print'average lifetime',totLifetime/(len(infos)-stillAlive),print'('+str(stillAlive),'still alive at exit)'printddefRify(fname,*attributes):output=open(fname,'w')forattrinattributes:print>>output,attr,print>>outputforinfoininfos:forattrinattributes:print>>output,getattr(info,attr),print>>outputif__name__=='__main__':# reportDictInfos()# interactive stuff:import__builtin__defdisplayhook(v):ifvisnotNone:__builtin__._=vpprint.pprint(v)sys.displayhook=displayhookimportpprinttry:importreadlineexceptImportError:passelse:importrlcompleterreadline.parse_and_bind('tab: complete')iflen(sys.argv)>2:attrs=sys.argv[2].split(',')ifattrs==['all']:attrs=slotsRify("R.txt",*attrs)