Merge commit 'b5be6201e00421a59e574a07b3d28cde5defff84'
[foam-extend-4.0.git] / bin / listProfileInformation.py
blob1b772cf1ab453aa7463dd2eb0891274bb3891833
1 #! /usr/bin/env python
3 # Lists the profiling information in time directories (uniform/profilingInfo)
4 # in a human readable form
6 from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile
7 import sys
9 pf=ParsedParameterFile(sys.argv[1],
10 treatBinaryAsASCII=True)
12 data={}
13 children={}
14 root=None
16 for p in pf["profilingInfo"]:
17 if p["id"] in data:
18 print "Duplicate definition of",p["id"]
19 sys.exit(-1)
20 if p["description"][0]=='"':
21 p["description"]=p["description"][1:]
22 if p["description"][-1]=='"':
23 p["description"]=p["description"][:-1]
25 data[p["id"]]=p
26 if "parentId" in p:
27 if p["parentId"] in children:
28 children[p["parentId"]].append(p["id"])
29 else:
30 children[p["parentId"]]=[p["id"]]
31 else:
32 if root!=None:
33 print "Two root elements"
34 sys-exit(-1)
35 else:
36 root=p["id"]
38 def depth(i):
39 if i in children:
40 return max([depth(j) for j in children[i]])+1
41 else:
42 return 0
44 #make sure that children are printed in the correct order
45 for i in children:
46 children[i].sort()
48 maxdepth=depth(root)
50 depths={}
52 def nameLen(i,d=0):
53 depths[i]=d
54 maxi=len(data[i]["description"])
55 if i in children:
56 maxi=max(maxi,max([nameLen(j,d+1) for j in children[i]]))
57 return maxi+3
59 maxLen=nameLen(root)
61 format=" %5.1f%% (%5.1f%%) - %5.1f%% | %8d %9.4gs %9.4gs"
62 totalTime=data[root]["totalTime"]
64 header=" "*(maxLen)+" | parent (total ) - self | calls total self "
65 print header
66 print "-"*len(header)
68 def printItem(i):
69 result=""
70 if depths[i]>1:
71 result+=" "*(depths[i]-1)
72 if depths[i]>0:
73 result+="|- "
74 result+=data[i]["description"]
75 result+=" "*(maxLen-len(result)+1)+"| "
77 parentTime=data[i]["totalTime"]
78 if "parentId" in data[i]:
79 parentTime=data[data[i]["parentId"]]["totalTime"]
81 tt=data[i]["totalTime"]
82 ct=data[i]["childTime"]
84 result+=format % (100*tt/parentTime,
85 100*(tt-ct)/totalTime,
86 100*(tt-ct)/tt,
87 data[i]["calls"],
88 tt,
89 tt-ct)
90 print result
91 if i in children:
92 for c in children[i]:
93 printItem(c)
95 printItem(root)