@@ -105,11 +105,11 @@ def reportModulesWithMemoryGrowth(fileParser, showEvents):
105
105
ret .append ((m ._label , m ._type , mem ))
106
106
return ret
107
107
108
- def reportModuleDataProductMemory (fileParser , showEvents ):
108
+ def reportModuleDataProductMemory (fileParser , showEvents , defaultRetain ):
109
109
ret = []
110
110
for m in fileParser .modules .values ():
111
111
l = list ()
112
- retained = False
112
+ retained = defaultRetain
113
113
sum = 0
114
114
for e in m ._eventInfo :
115
115
l .append (e ._dataProdAlloc )
@@ -118,16 +118,16 @@ def reportModuleDataProductMemory(fileParser, showEvents):
118
118
retained = True
119
119
if retained :
120
120
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 ))
122
122
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 ) )))
124
124
return ret
125
125
126
- def reportModuleRetainingMemory (fileParser , showEvents ):
126
+ def reportModuleRetainingMemory (fileParser , showEvents , defaultRetain ):
127
127
ret = []
128
128
for m in fileParser .modules .values ():
129
129
l = list ()
130
- retained = False
130
+ retained = defaultRetain
131
131
sum = 0
132
132
for e in m ._eventInfo [1 :]:
133
133
l .append (e ._new )
@@ -136,16 +136,16 @@ def reportModuleRetainingMemory(fileParser, showEvents):
136
136
retained = True
137
137
if retained :
138
138
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 ))
140
140
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 )))
142
142
return ret
143
143
144
- def reportModuleTemporary (fileParser , showEvents ):
144
+ def reportModuleTemporary (fileParser , showEvents , defaultRetain ):
145
145
ret = []
146
146
for m in fileParser .modules .values ():
147
147
l = list ()
148
- retained = False
148
+ retained = defaultRetain
149
149
sum = 0
150
150
for e in m ._eventInfo :
151
151
l .append (e ._temp )
@@ -154,16 +154,16 @@ def reportModuleTemporary(fileParser, showEvents):
154
154
retained = True
155
155
if retained :
156
156
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 ))
158
158
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 ) )))
160
160
return ret
161
161
162
- def reportModuleNTemporary (fileParser , showEvents ):
162
+ def reportModuleNTemporary (fileParser , showEvents , defaultRetain ):
163
163
ret = []
164
164
for m in fileParser .modules .values ():
165
165
l = list ()
166
- retained = False
166
+ retained = defaultRetain
167
167
sum = 0
168
168
for e in m ._eventInfo :
169
169
l .append (e ._nTemp )
@@ -172,9 +172,9 @@ def reportModuleNTemporary(fileParser, showEvents):
172
172
retained = True
173
173
if retained :
174
174
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 ))
176
176
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 ) )))
178
178
return ret
179
179
180
180
@@ -192,21 +192,27 @@ def printReport(values, showEvents, summary, eventSummary, maxColumn):
192
192
width = len (v [c ])
193
193
if width > columnWidths [c ]:
194
194
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 ]}} " )
195
201
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 } " )
200
203
if showEvents :
201
204
print (f" [{ eventSummary } ]" )
202
205
203
206
for v in values :
204
207
label = v [0 ]
205
208
classType = v [1 ]
206
- if maxColumn :
209
+ if maxColumn != 0 and maxColumn != - 1 :
207
210
label = label [:maxColumn ]
208
211
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} " )
210
216
if showEvents :
211
217
print (f" { v [3 ]} " )
212
218
@@ -225,21 +231,23 @@ def printReport(values, showEvents, summary, eventSummary, maxColumn):
225
231
226
232
parser .add_argument ('--eventData' , help = 'for each report, show the per event data associated to the report' , action = 'store_true' )
227
233
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' )
228
235
args = parser .parse_args ()
229
236
230
237
inputfile = args .filename
231
238
232
239
fileParser = FileParser ()
233
240
fileParser .parse (inputfile )
234
-
241
+ if args .csv :
242
+ args .maxColumn = - 1
235
243
if args .grew :
236
244
printReport (reportModulesWithMemoryGrowth (fileParser , args .eventData ), args .eventData , "total memory growth" , "growth each event" , args .maxColumn )
237
245
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 )
239
247
if args .product :
240
248
printReport (reportModuleDataProductMemory (fileParser , args .eventData ), args .eventData , "average data products size" , "data products size each event" , args .maxColumn )
241
249
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 )
243
251
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 )
245
253
#print(fileParser.modules)
0 commit comments