CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Utilities/StaticAnalyzers/scripts/accesses.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 import re
00003 warning = re.compile("warning: function")
00004 tab = re.compile("\s+")
00005 topfunc = re.compile("::produce$|::analyze$|::filter$")
00006 paths = re.compile(".*?\s*src/([A-Z].*?/[A-z].*?)(/.*?):(.*?):(.*?)")
00007 from collections import defaultdict
00008 
00009 gets = defaultdict(list)
00010 calls = defaultdict(list)
00011 
00012 f = open('log.txt')
00013 lines=[]
00014 
00015 for line in f:
00016         if warning.search(line):
00017                 line = line.strip();
00018 #               print line
00019                 fields = line.split("\'")
00020 #               print fields
00021                 if fields[2] == ' calls ' :
00022 #                       print fields[3]+" here\n"
00023                         if fields[3].strip() not in calls[fields[1]]:
00024                                 calls[fields[1]].append(fields[3].strip())
00025                 else : 
00026 #                       print fields[3]+" not\n"
00027                         if fields[3].strip() not in gets[fields[1]]:
00028                                 gets[fields[1]].append(fields[3].strip())
00029                 if topfunc.search(fields[1]):
00030                         dirs = paths.match(fields[0])
00031                         filename = dirs.group(1)+dirs.group(2)
00032                         line = filename+";"+fields[1]
00033                         if line not in lines:
00034                                 lines.append(line)
00035 
00036 f.close()
00037 
00038 
00039 lines.sort()
00040 
00041 import pprint
00042 #pprint.pprint(gets)
00043 #pprint.pprint(calls)
00044         
00045 def funcprint(str,nspaces):
00046         "This prints out the get and calls of a function"
00047         print "".join((nspaces * "\t")+"function:\t"+str) 
00048         for l in gets[str]:
00049 #               print l
00050                 lf = l.split(" edm::Handle ")
00051 #               print lf
00052                 if len(lf) == 2 :
00053                         print "".join(((nspaces+1) * "\t")+"acceses:\t"+lf[1].strip())
00054                         print "".join(((nspaces+2) * "\t")+"label:\t"+lf[0].strip())
00055                 else :
00056                         print "".join(((nspaces+1) * "\t")+"acceses:\t"+l.strip())
00057         for call in calls[str]:
00058                 print "".join(((nspaces+1) * "\t")+"calls:\t"+call.strip())
00059                 if call != str: funcprint(call,(nspaces+2))
00060         return
00061 
00062 for line in lines:
00063         fields = line.split(";")
00064 #       print fields
00065         print "Package and filename: "+fields[0]
00066 #       print fields[1]
00067         funcprint(fields[1],1)
00068         print "\n"