CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Profiling.py
Go to the documentation of this file.
1 import sys
2 import os
3 try:
4  import cProfile
5 except Exception:
6  import profile as cProfile
7 import pstats
8 
9 from Vispa.Main.Directories import logDirectory
10 
11 def analyze(function,filename,filter=None):
12  profilename=os.path.join(logDirectory,os.path.splitext(os.path.basename(filename))[0]+"_profile")
13  cProfile.run(function,profilename)
14  p = pstats.Stats(profilename)
15  p.strip_dirs()
16  p.sort_stats("cumulative")
17  f="^(?!unittest.py)"
18  if filter!=None:
19  f+=filter
20  p.print_stats(f,30)