@@ -497,14 +497,14 @@ def resolve(self, hprof_data):
497
497
merged_fields_builder [name ][clazz .name ] = value
498
498
clazz = clazz .super_class
499
499
500
- for key , value in merged_fields_builder .items ():
500
+ for key , value in list ( merged_fields_builder .items () ):
501
501
# Avoid over-writing python internals, like __dict__
502
502
if key in self .fields .__dict__ :
503
503
key = "__hprof_" + key
504
504
assert key not in self .fields .__dict__
505
505
506
506
if len (value ) == 1 :
507
- setattr (self .fields , key , next (iter (value .values ())))
507
+ setattr (self .fields , key , next (iter (list ( value .values () ))))
508
508
else :
509
509
# There is a conflict in the class hierarchy (e.g. privates with the
510
510
# same name), so we need to store a dictionary.
@@ -522,8 +522,8 @@ def outgoing_references(self, filter_function=lambda x: True):
522
522
# and attribute weight the wrong way.
523
523
# Classes should be walked explicitly
524
524
refs = []
525
- for class_name , fields in self .class_fields .items ():
526
- for name , value in fields .items ():
525
+ for class_name , fields in list ( self .class_fields .items () ):
526
+ for name , value in list ( fields .items () ):
527
527
if isinstance (value , HprofObject ) and filter_function (value ):
528
528
refs .append (FieldReference (self , value , class_name , name ))
529
529
return refs
@@ -959,11 +959,11 @@ def add_root(self, hprof_root):
959
959
960
960
def resolve (self ):
961
961
# First resolve heaps
962
- for heap in self .heap_dict .values ():
962
+ for heap in list ( self .heap_dict .values () ):
963
963
heap .resolve (self )
964
964
965
965
# Then resolve classes
966
- for obj in self .object_id_dict .values ():
966
+ for obj in list ( self .object_id_dict .values () ):
967
967
if isinstance (obj , HprofClass ):
968
968
clazz = obj
969
969
clazz .resolve (self )
@@ -976,18 +976,18 @@ def resolve(self):
976
976
self .class_name_dict [clazz .name ]
977
977
)
978
978
self .dupe_class_dict [clazz .name ].append (clazz )
979
- print ("Warning: duplicate class: %s" % clazz .name )
979
+ print (( "Warning: duplicate class: %s" % clazz .name ) )
980
980
else :
981
981
self .class_name_dict [clazz .name ] = clazz
982
982
# Fix up all classes to derive from java.lang.Class
983
983
# at the time we create every HprofClass 'java.lang.Class' may have
984
984
# not be parsed yet and thus unavailable
985
985
clsCls = self .class_name_dict ["java.lang.Class" ]
986
- for cls in self .class_name_dict .values ():
986
+ for cls in list ( self .class_name_dict .values () ):
987
987
cls .clazz = clsCls
988
988
989
989
# Then other objects
990
- for obj in self .object_id_dict .values ():
990
+ for obj in list ( self .object_id_dict .values () ):
991
991
if not isinstance (obj , HprofClass ):
992
992
obj .resolve (self )
993
993
obj .is_root = False # Fixed up for root objects below
@@ -1019,15 +1019,15 @@ def lookup_load_class_record(self, class_object_id):
1019
1019
def lookup_instances_of_class (self , class_name ):
1020
1020
return [
1021
1021
obj
1022
- for obj in self .object_id_dict .values ()
1022
+ for obj in list ( self .object_id_dict .values () )
1023
1023
if isinstance (obj , HprofInstance ) and obj .clazz .name == class_name
1024
1024
]
1025
1025
1026
1026
def load_inverted_references (self ):
1027
1027
if self .inverted_references is None :
1028
1028
# Will be much faster for later invocations
1029
1029
self .inverted_references = defaultdict (list )
1030
- for heap_obj in self .object_id_dict .values ():
1030
+ for heap_obj in list ( self .object_id_dict .values () ):
1031
1031
for ref in heap_obj .outgoing_references ():
1032
1032
self .inverted_references [ref .referee ].append (ref )
1033
1033
@@ -1121,7 +1121,7 @@ def roots_of_obj(hprof_data, obj):
1121
1121
1122
1122
def zygote_references_to_app_objects (hprof_data ):
1123
1123
references = []
1124
- for obj in hprof_data .object_id_dict .values ():
1124
+ for obj in list ( hprof_data .object_id_dict .values () ):
1125
1125
if obj .heap .name == "zygote" :
1126
1126
for reference in obj .outgoing_references ():
1127
1127
if reference .referee .heap .name != "zygote" :
@@ -1154,7 +1154,7 @@ def write_bitmap(bitmap_instance, filename):
1154
1154
def open_bitmaps (bitmap_instances ):
1155
1155
tmp_dir = tempfile .mkdtemp (suffix = "bitmaps" )
1156
1156
subprocess .call (["open" , tmp_dir ]) # this only works in Mac - sorry!
1157
- print ("Writing %d bitmaps to %s." % (len (bitmap_instances ), tmp_dir ))
1157
+ print (( "Writing %d bitmaps to %s." % (len (bitmap_instances ), tmp_dir ) ))
1158
1158
for i , bitmap in enumerate (bitmap_instances ):
1159
1159
write_bitmap (bitmap , os .path .join (tmp_dir , "bitmap_%s.png" % bitmap .object_id ))
1160
1160
sys .stdout .write ("\r %d of %d complete" % (i + 1 , len (bitmap_instances )))
@@ -1174,12 +1174,12 @@ def print_view_tree(view_root=None):
1174
1174
else :
1175
1175
view_root = all_view_roots [0 ]
1176
1176
else :
1177
- print ("not an hprofdata: %s" % view_root .__class__ )
1177
+ print (( "not an hprofdata: %s" % view_root .__class__ ) )
1178
1178
1179
- print ("%s" % view_root )
1179
+ print (( "%s" % view_root ) )
1180
1180
1181
1181
def print_view_node (view_node , indent ):
1182
- print ("%s%s" % (indent , view_node ))
1182
+ print (( "%s%s" % (indent , view_node ) ))
1183
1183
if "android.view.ViewGroup" in view_node .class_fields :
1184
1184
children = view_node .class_fields ["android.view.ViewGroup" ]["mChildren" ]
1185
1185
for child in children .array_values :
@@ -1364,25 +1364,30 @@ def forward_comparator(x, y):
1364
1364
# substring can result in wasted char arrays
1365
1365
# This isn't exact - need to figure out way of determining unused chars in the middle
1366
1366
def wasted_string_char_arrays (hprof_data ):
1367
- char_arrays = filter (
1368
- lambda v : isinstance (v , HprofPrimitiveArray ) and v .prim_type is HprofBasic .CHAR ,
1369
- hprof_data .object_id_dict .values (),
1367
+ char_arrays = list (
1368
+ filter (
1369
+ lambda v : isinstance (v , HprofPrimitiveArray )
1370
+ and v .prim_type is HprofBasic .CHAR ,
1371
+ list (hprof_data .object_id_dict .values ()),
1372
+ )
1370
1373
)
1371
- with_wasted = map ( lambda x : ( x , wasted_segments (x )), char_arrays )
1372
- return filter ( lambda x : len (x [1 ]) > 0 , with_wasted )
1374
+ with_wasted = [( x , wasted_segments (x )) for x in char_arrays ]
1375
+ return [ x for x in with_wasted if len (x [1 ]) > 0 ]
1373
1376
1374
1377
1375
1378
def wasted_string_char_count (hprof_data ):
1376
1379
wasted_char_array_info = wasted_string_char_arrays (hprof_data )
1377
1380
1378
1381
def segment_length (segments ):
1379
- return sum (map ( lambda x : x [1 ] - x [0 ], segments ) )
1382
+ return sum ([ x [1 ] - x [0 ] for x in segments ] )
1380
1383
1381
- return sum (map ( lambda x : segment_length (x [1 ]), wasted_char_array_info ) )
1384
+ return sum ([ segment_length (x [1 ]) for x in wasted_char_array_info ] )
1382
1385
1383
1386
1384
1387
def app_heap_objects (hprof_data ):
1385
- return [o for o in hprof_data .object_id_dict .values () if o .heap .name != "zygote" ]
1388
+ return [
1389
+ o for o in list (hprof_data .object_id_dict .values ()) if o .heap .name != "zygote"
1390
+ ]
1386
1391
1387
1392
1388
1393
# return a set of containing 'clazz' and all its subclasses
@@ -1410,7 +1415,9 @@ def instances_in(hprof_data, classes):
1410
1415
classes = set (classes )
1411
1416
else :
1412
1417
classes = {classes }
1413
- return {obj for obj in hprof_data .object_id_dict .values () if obj .clazz in classes }
1418
+ return {
1419
+ obj for obj in list (hprof_data .object_id_dict .values ()) if obj .clazz in classes
1420
+ }
1414
1421
1415
1422
1416
1423
# return a map of class => {instances} for the given sequence of instances
@@ -1436,7 +1443,7 @@ def java_locals(hprof_data):
1436
1443
for root in hprof_data .roots
1437
1444
if root .heap_tag == HeapTag .ROOT_THREAD_OBJECT
1438
1445
}
1439
- thread_locals = {thread : set () for thread in threads .values ()}
1446
+ thread_locals = {thread : set () for thread in list ( threads .values () )}
1440
1447
for loc in locs :
1441
1448
thread_locals [threads [loc .thread_serial ]].add (loc .obj )
1442
1449
return thread_locals
@@ -1458,7 +1465,7 @@ def java_locals(hprof_data):
1458
1465
allow_missing_ids = args .allow_missing_ids
1459
1466
hp = parse_filename (args .hprof )
1460
1467
classes = []
1461
- for cls_name , cls in hp .class_name_dict .items ():
1468
+ for cls_name , cls in list ( hp .class_name_dict .items () ):
1462
1469
classes .append (
1463
1470
(
1464
1471
cls_name ,
0 commit comments