Back to index

plone3  3.1.7
testProfiling.py
Go to the documentation of this file.
00001 from common import Dummy
00002 import os
00003 import sys
00004 from os.path import realpath
00005 import hotshot, hotshot.stats
00006 
00007 epi_path = '/'.join(realpath(os.getcwd()).split('/')[:-1])
00008 sys.path.insert(0, epi_path)
00009 from ExtendedPathIndex import ExtendedPathIndex
00010 
00011 index = ExtendedPathIndex( 'path' )
00012 
00013 
00014 def profile(prof_name, method, args=(), kwargs={}, times=100):
00015         def run_multiple(method, args, kwargs):
00016             for i in range(times):
00017                r = method(*args, **kwargs)
00018             return r
00019         prof = hotshot.Profile(prof_name)
00020         result = prof.runcall(run_multiple, method, args, kwargs)
00021         prof.close()
00022         print prof_name
00023         stats = hotshot.stats.load(prof_name)
00024         # Print calls ordered by time
00025         stats.strip_dirs()
00026         stats.sort_stats('time', 'calls')
00027         stats.print_stats(15)
00028         return result
00029 
00030 def createContent(index, f1=9, f2=50, f3=10):
00031     count = 0
00032     for i in range(f1):
00033         meth1 = index.search
00034         args = ()
00035         kwargs = {"path": '/plone/f-0/f-0-0/f-0-0-0',
00036                   "navtree": 1,
00037                   "depth": 1}
00038         prof_id = 'profile_EPI_%s.prof'%count
00039         result = profile(prof_id, meth1, args, kwargs)
00040         print 'num of results: %s'%len(result.keys())
00041         f1id = 'f-%d' % i
00042         folder1 = Dummy("/plone/%s" % f1id)
00043         count += 1
00044         index.index_object(count, folder1)
00045 
00046         for j in range(f2):
00047             f2id = 'f-%d-%d' % (i, j)
00048             folder2 = Dummy("/plone/%s/%s" % (f1id, f2id))
00049             count += 1
00050             index.index_object(count, folder2)
00051 
00052             for k in range(f3):
00053                 f3id = 'f-%d-%d-%d' % (i, j, k)
00054                 folder3 = Dummy("/plone/%s/%s/%s" % (f1id, f2id, f3id))
00055                 count += 1
00056                 index.index_object(count, folder3)
00057 
00058                 for m in range(100):
00059                     docid = 'f-%d-%d-%d-%d' % (i, j, k, m)
00060                     doc = Dummy("/plone/%s/%s/%s/%s" % (f1id, f2id, f3id, docid))
00061                     count += 1
00062                     index.index_object(count, doc)
00063     prof_id = 'profile_EPI_%s.prof'%count
00064     result = profile(prof_id, meth1, args, kwargs)
00065     print 'num of results: %s'%len(result.keys())
00066     print 'Created %s entries' % count
00067 
00068 createContent(index)