@@ -105,11 +105,11 @@ def reportModulesWithMemoryGrowth(fileParser, showEvents):
105105 ret .append ((m ._label , m ._type , mem ))
106106 return ret
107107
108- def reportModuleDataProductMemory (fileParser , showEvents ):
108+ def reportModuleDataProductMemory (fileParser , showEvents , defaultRetain ):
109109 ret = []
110110 for m in fileParser .modules .values ():
111111 l = list ()
112- retained = False
112+ retained = defaultRetain
113113 sum = 0
114114 for e in m ._eventInfo :
115115 l .append (e ._dataProdAlloc )
@@ -118,16 +118,16 @@ def reportModuleDataProductMemory(fileParser, showEvents):
118118 retained = True
119119 if retained :
120120 if showEvents :
121- ret .append ((m ._label , m ._type , float (sum )/ len (l ), l ))
121+ ret .append ((m ._label , m ._type , float (sum )/ max ( 1 , len (l ) ), l ))
122122 else :
123- ret .append ((m ._label , m ._type , float (sum )/ len (l )))
123+ ret .append ((m ._label , m ._type , float (sum )/ max ( 1 , len (l ) )))
124124 return ret
125125
126- def reportModuleRetainingMemory (fileParser , showEvents ):
126+ def reportModuleRetainingMemory (fileParser , showEvents , defaultRetain ):
127127 ret = []
128128 for m in fileParser .modules .values ():
129129 l = list ()
130- retained = False
130+ retained = defaultRetain
131131 sum = 0
132132 for e in m ._eventInfo [1 :]:
133133 l .append (e ._new )
@@ -136,16 +136,16 @@ def reportModuleRetainingMemory(fileParser, showEvents):
136136 retained = True
137137 if retained :
138138 if showEvents :
139- ret .append ((m ._label , m ._type , float (sum )/ len (l ), l ))
139+ ret .append ((m ._label , m ._type , float (sum )/ max ( len (l ), 1 ), l ))
140140 else :
141- ret .append ((m ._label , m ._type , float (sum )/ len (l )))
141+ ret .append ((m ._label , m ._type , float (sum )/ max ( len (l ), 1 )))
142142 return ret
143143
144- def reportModuleTemporary (fileParser , showEvents ):
144+ def reportModuleTemporary (fileParser , showEvents , defaultRetain ):
145145 ret = []
146146 for m in fileParser .modules .values ():
147147 l = list ()
148- retained = False
148+ retained = defaultRetain
149149 sum = 0
150150 for e in m ._eventInfo :
151151 l .append (e ._temp )
@@ -154,16 +154,16 @@ def reportModuleTemporary(fileParser, showEvents):
154154 retained = True
155155 if retained :
156156 if showEvents :
157- ret .append ((m ._label , m ._type , float (sum )/ len (l ), l ))
157+ ret .append ((m ._label , m ._type , float (sum )/ max ( 1 , len (l ) ), l ))
158158 else :
159- ret .append ((m ._label , m ._type , float (sum )/ len (l )))
159+ ret .append ((m ._label , m ._type , float (sum )/ max ( 1 , len (l ) )))
160160 return ret
161161
162- def reportModuleNTemporary (fileParser , showEvents ):
162+ def reportModuleNTemporary (fileParser , showEvents , defaultRetain ):
163163 ret = []
164164 for m in fileParser .modules .values ():
165165 l = list ()
166- retained = False
166+ retained = defaultRetain
167167 sum = 0
168168 for e in m ._eventInfo :
169169 l .append (e ._nTemp )
@@ -172,9 +172,9 @@ def reportModuleNTemporary(fileParser, showEvents):
172172 retained = True
173173 if retained :
174174 if showEvents :
175- ret .append ((m ._label , m ._type , float (sum )/ len (l ), l ))
175+ ret .append ((m ._label , m ._type , float (sum )/ max ( 1 , len (l ) ), l ))
176176 else :
177- ret .append ((m ._label , m ._type , float (sum )/ len (l )))
177+ ret .append ((m ._label , m ._type , float (sum )/ max ( 1 , len (l ) )))
178178 return ret
179179
180180
@@ -192,21 +192,27 @@ def printReport(values, showEvents, summary, eventSummary, maxColumn):
192192 width = len (v [c ])
193193 if width > columnWidths [c ]:
194194 columnWidths [c ] = width
195+ elif maxColumn != - 1 :
196+ columnWidths = [maxColumn , maxColumn , maxColumn ]
197+ label = label [:maxColumn ]
198+ classType = classType [:maxColumn ]
199+ if maxColumn != - 1 :
200+ print (f"{ label :{columnWidths [0 ]}} { classType :{columnWidths [1 ]}} { summary :{columnWidths [2 ]}} " )
195201 else :
196- columnWidths = [maxColumn , maxColumn , maxColumn ]
197- label = label [:maxColumn ]
198- classType = classType [:maxColumn ]
199- print (f"{ label :{columnWidths [0 ]}} { classType :{columnWidths [1 ]}} { summary :{columnWidths [2 ]}} " )
202+ print (f"{ label } , { classType } , { summary } " )
200203 if showEvents :
201204 print (f" [{ eventSummary } ]" )
202205
203206 for v in values :
204207 label = v [0 ]
205208 classType = v [1 ]
206- if maxColumn :
209+ if maxColumn != 0 and maxColumn != - 1 :
207210 label = label [:maxColumn ]
208211 classType = classType [:maxColumn ]
209- print (f"{ label :{columnWidths [0 ]}} { classType :{columnWidths [1 ]}} { v [2 ]:{columnWidths [2 ]}.2f} " )
212+ if maxColumn != - 1 :
213+ print (f"{ label :{columnWidths [0 ]}} { classType :{columnWidths [1 ]}} { v [2 ]:{columnWidths [2 ]}.2f} " )
214+ else :
215+ print (f"{ label } , { classType } , { v [2 ]:.2f} " )
210216 if showEvents :
211217 print (f" { v [3 ]} " )
212218
@@ -225,21 +231,23 @@ def printReport(values, showEvents, summary, eventSummary, maxColumn):
225231
226232 parser .add_argument ('--eventData' , help = 'for each report, show the per event data associated to the report' , action = 'store_true' )
227233 parser .add_argument ('--maxColumn' , type = int , help = 'maximum column width for report, 0 for no constraint' , default = 0 )
234+ parser .add_argument ('--csv' , help = 'output chosen information all modules in a comma separated value format' , action = 'store_true' )
228235 args = parser .parse_args ()
229236
230237 inputfile = args .filename
231238
232239 fileParser = FileParser ()
233240 fileParser .parse (inputfile )
234-
241+ if args .csv :
242+ args .maxColumn = - 1
235243 if args .grew :
236244 printReport (reportModulesWithMemoryGrowth (fileParser , args .eventData ), args .eventData , "total memory growth" , "growth each event" , args .maxColumn )
237245 if args .retained :
238- printReport (reportModuleRetainingMemory (fileParser , args .eventData ), args .eventData , "average retained" , "retained each event" , args .maxColumn )
246+ printReport (reportModuleRetainingMemory (fileParser , args .eventData , args . csv ), args .eventData , "average retained" , "retained each event" , args .maxColumn )
239247 if args .product :
240248 printReport (reportModuleDataProductMemory (fileParser , args .eventData ), args .eventData , "average data products size" , "data products size each event" , args .maxColumn )
241249 if args .tempSize :
242- printReport (reportModuleTemporary (fileParser , args .eventData ), args .eventData , "average temporary allocation size" , "temporary allocation size each event" , args .maxColumn )
250+ printReport (reportModuleTemporary (fileParser , args .eventData , args . csv ), args .eventData , "average temporary allocation size" , "temporary allocation size each event" , args .maxColumn )
243251 if args .nTemp :
244- printReport (reportModuleNTemporary (fileParser , args .eventData ), args .eventData , "average # of temporary allocation" , "# of temporary allocations each event" , args .maxColumn )
252+ printReport (reportModuleNTemporary (fileParser , args .eventData , args . csv ), args .eventData , "average # of temporary allocation" , "# of temporary allocations each event" , args .maxColumn )
245253 #print(fileParser.modules)
0 commit comments