CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/FWCore/GuiBrowsers/python/Vispa/Share/Profiling.py

Go to the documentation of this file.
00001 import sys
00002 import os
00003 try:
00004     import cProfile
00005 except Exception:
00006     import profile as cProfile
00007 import pstats
00008 
00009 from Vispa.Main.Directories import logDirectory
00010 
00011 def analyze(function,filename,filter=None):
00012     profilename=os.path.join(logDirectory,os.path.splitext(os.path.basename(filename))[0]+"_profile")
00013     cProfile.run(function,profilename)
00014     p = pstats.Stats(profilename)
00015     p.strip_dirs()
00016     p.sort_stats("cumulative")
00017     f="^(?!unittest.py)"
00018     if filter!=None:
00019         f+=filter
00020     p.print_stats(f,30)