Bug 1464869 - Fix flake8/pep8 issue by hand in memory/
MozReview-Commit-ID: 8bkhAB4g6rv
--- a/memory/replace/dmd/block_analyzer.py
+++ b/memory/replace/dmd/block_analyzer.py
@@ -89,17 +89,18 @@ parser.add_argument('-sfl', '--max-stack
parser.add_argument('-a', '--ignore-alloc-fns', action='store_true',
help='ignore allocation functions at the start of traces')
parser.add_argument('-f', '--max-frames', type=range_1_24, default=8,
help='maximum number of frames to consider in each trace')
parser.add_argument('-c', '--chain-reports', action='store_true',
- help='if only one block is found to hold onto the object, report the next one, too')
+ help='if only one block is found to hold onto the object, report '
+ 'the next one, too')
####
class BlockData:
def __init__(self, json_block):
self.addr = json_block['addr']
@@ -117,17 +118,17 @@ class BlockData:
self.alloc_stack = json_block['alloc']
def print_trace_segment(args, stacks, block):
(traceTable, frameTable) = stacks
for l in traceTable[block.alloc_stack]:
# The 5: is to remove the bogus leading "#00: " from the stack frame.
- print ' ', frameTable[l][5:args.max_stack_frame_length]
+ print(' ', frameTable[l][5:args.max_stack_frame_length])
def show_referrers(args, blocks, stacks, block):
visited = set([])
anyFound = False
while True:
@@ -166,17 +167,17 @@ def show_referrers(args, blocks, stacks,
if block in visited:
sys.stdout.write('Found a loop.\n')
break
visited.add(block)
else:
break
if not anyFound:
- print 'No referrers found.'
+ print('No referrers found.')
def show_block_info(args, blocks, stacks, block):
b = blocks[block]
sys.stdout.write('block: 0x{}\n'.format(b.addr))
sys.stdout.write('requested size: {} bytes\n'.format(b.req_size))
sys.stdout.write('\n')
sys.stdout.write('block contents: ')
@@ -220,18 +221,16 @@ def loadGraph(options):
opener = gzip.open if isZipped else open
with opener(options.dmd_log_file_name, 'rb') as f:
j = json.load(f)
if j['version'] != outputVersion:
raise Exception("'version' property isn't '{:d}'".format(outputVersion))
- invocation = j['invocation']
-
block_list = j['blockList']
blocks = {}
for json_block in block_list:
blocks[int(json_block['addr'], 16)] = BlockData(json_block)
traceTable = j['traceTable']
frameTable = j['frameTable']
@@ -243,19 +242,19 @@ def loadGraph(options):
def analyzeLogs():
options = parser.parse_args()
(blocks, stacks) = loadGraph(options)
block = int(options.block, 16)
- if not block in blocks:
- print 'Object', block, 'not found in traces.'
- print 'It could still be the target of some nodes.'
+ if block not in blocks:
+ print('Object', block, 'not found in traces.')
+ print('It could still be the target of some nodes.')
return
if options.info:
show_block_info(options, blocks, stacks, block)
return
show_referrers(options, blocks, stacks, block)
--- a/memory/replace/dmd/dmd.py
+++ b/memory/replace/dmd/dmd.py
@@ -23,23 +23,27 @@ from bisect import bisect_right
# The DMD output version this script handles.
outputVersion = 5
# If --ignore-alloc-fns is specified, stack frames containing functions that
# match these strings will be removed from the *start* of stack traces. (Once
# we hit a non-matching frame, any subsequent frames won't be removed even if
# they do match.)
allocatorFns = [
- # Matches malloc, replace_malloc, moz_xmalloc, vpx_malloc, js_malloc, pod_malloc, malloc_zone_*, g_malloc.
+ # Matches malloc, replace_malloc, moz_xmalloc, vpx_malloc, js_malloc,
+ # pod_malloc, malloc_zone_*, g_malloc.
'malloc',
- # Matches calloc, replace_calloc, moz_xcalloc, vpx_calloc, js_calloc, pod_calloc, malloc_zone_calloc, pod_callocCanGC.
+ # Matches calloc, replace_calloc, moz_xcalloc, vpx_calloc, js_calloc,
+ # pod_calloc, malloc_zone_calloc, pod_callocCanGC.
'calloc',
- # Matches realloc, replace_realloc, moz_xrealloc, vpx_realloc, js_realloc, pod_realloc, pod_reallocCanGC.
+ # Matches realloc, replace_realloc, moz_xrealloc, vpx_realloc, js_realloc,
+ # pod_realloc, pod_reallocCanGC.
'realloc',
- # Matches memalign, posix_memalign, replace_memalign, replace_posix_memalign, moz_xmemalign, vpx_memalign, malloc_zone_memalign.
+ # Matches memalign, posix_memalign, replace_memalign, replace_posix_memalign,
+ # moz_xmemalign, vpx_memalign, malloc_zone_memalign.
'memalign',
'operator new(',
'operator new[](',
'g_slice_alloc',
# This one necessary to fully filter some sequences of allocation functions
# that happen in practice. Note that ??? entries that follow non-allocation
# functions won't be stripped, as explained above.
'???',
@@ -176,20 +180,22 @@ variable is used to find breakpad symbol
p.add_argument('-a', '--ignore-alloc-fns', action='store_true',
help='ignore allocation functions at the start of traces')
p.add_argument('--no-fix-stacks', action='store_true',
help='do not fix stacks')
p.add_argument('--clamp-contents', action='store_true',
- help='for a scan mode log, clamp addresses to the start of live blocks, or zero if not in one')
+ help='for a scan mode log, clamp addresses to the start of live blocks, '
+ 'or zero if not in one')
p.add_argument('--print-clamp-stats', action='store_true',
- help='print information about the results of pointer clamping; mostly useful for debugging clamping')
+ help='print information about the results of pointer clamping; mostly '
+ 'useful for debugging clamping')
p.add_argument('--filter-stacks-for-testing', action='store_true',
help='filter stack traces; only useful for testing purposes')
p.add_argument('input_file',
help='a file produced by DMD')
p.add_argument('input_file2', nargs='?',
@@ -285,17 +291,17 @@ def getDigestFromFile(args, inputFile):
traceTable[unrecordedTraceID] = [unrecordedFrameID]
frameTable[unrecordedFrameID] = \
'#00: (no stack trace recorded due to --stacks=partial)'
# For the purposes of this script, 'scan' behaves like 'live'.
if mode == 'scan':
mode = 'live'
- if not mode in ['live', 'dark-matter', 'cumulative']:
+ if mode not in ['live', 'dark-matter', 'cumulative']:
raise Exception("bad 'mode' property: '{:s}'".format(mode))
# Remove allocation functions at the start of traces.
if args.ignore_alloc_fns:
# Build a regexp that matches every function in allocatorFns.
escapedAllocatorFns = map(re.escape, allocatorFns)
fn_re = re.compile('|'.join(escapedAllocatorFns))
@@ -421,17 +427,17 @@ def getDigestFromFile(args, inputFile):
usableSize = reqSize + slopSize
heapUsableSize += num * usableSize
heapBlocks += num
record.numBlocks += num
record.reqSize += num * reqSize
record.slopSize += num * slopSize
record.usableSize += num * usableSize
- if record.allocatedAtDesc == None:
+ if record.allocatedAtDesc is None:
record.allocatedAtDesc = \
buildTraceDescription(traceTable, frameTable,
allocatedAtTraceKey)
if mode in ['live', 'cumulative']:
pass
elif mode == 'dark-matter':
if 'reps' in block and record.reportedAtDescs == []:
@@ -616,17 +622,17 @@ def printDigest(args, digest):
printStack(reportedAtDesc)
out(' }')
out('}\n')
return (kindUsableSize, kindBlocks)
def printInvocation(n, dmdEnvVar, mode):
out('Invocation{:} {{'.format(n))
- if dmdEnvVar == None:
+ if dmdEnvVar is None:
out(' $DMD is undefined')
else:
out(' $DMD = \'' + dmdEnvVar + '\'')
out(' Mode = \'' + mode + '\'')
out('}\n')
# Print command line. Strip dirs so the output is deterministic, which is
# needed for testing.
@@ -773,20 +779,22 @@ class ClampStats:
self.nullPtr += 1
def clampedNonBlockAddr(self):
self.nonNullNonBlockPtr += 1
def log(self):
sys.stderr.write('Results:\n')
sys.stderr.write(
- ' Number of pointers already pointing to start of blocks: ' + str(self.startBlockPtr) + '\n')
+ ' Number of pointers already pointing to start of blocks: ' +
+ str(self.startBlockPtr) + '\n')
sys.stderr.write(' Number of pointers clamped to start of blocks: ' +
str(self.midBlockPtr) + '\n')
- sys.stderr.write(' Number of non-null pointers not pointing into blocks clamped to null: ' +
+ sys.stderr.write(' Number of non-null pointers not pointing into blocks '
+ 'clamped to null: ' +
str(self.nonNullNonBlockPtr) + '\n')
sys.stderr.write(' Number of null pointers: ' + str(self.nullPtr) + '\n')
# Search the block ranges array for a block that address points into.
# The search is carried out in an array of starting addresses for each blocks
# because it is faster.
def clampAddress(blockRanges, blockStarts, clampStats, address):
@@ -839,17 +847,17 @@ def clampBlockList(args, inputFileName,
lastAddr = blockRanges[-1].end
blockStarts = []
for r in blockRanges:
blockStarts.append(r.start)
for block in blockList:
# Small blocks don't have any contents.
- if not 'contents' in block:
+ if 'contents' not in block:
continue
cont = block['contents']
for i in range(len(cont)):
address = int(cont[i], 16)
if address == 0:
clampStats.nullAddr()
--- a/memory/replace/dmd/test/scan-test.py
+++ b/memory/replace/dmd/test/scan-test.py
@@ -20,17 +20,18 @@ outputVersion = 5
def parseCommandLine():
description = '''
Ensure that DMD heap scan mode creates the correct output when run with SmokeDMD.
This is only for testing. Input files can be gzipped.
'''
p = argparse.ArgumentParser(description=description)
p.add_argument('--clamp-contents', action='store_true',
- help='expect that the contents of the JSON input file have had their addresses clamped')
+ help='expect that the contents of the JSON input file have had '
+ 'their addresses clamped')
p.add_argument('input_file',
help='a file produced by DMD')
return p.parse_args(sys.argv[1:])
def checkScanContents(contents, expected):
--- a/memory/replace/logalloc/replay/logalloc_munge.py
+++ b/memory/replace/logalloc/replay/logalloc_munge.py
@@ -77,17 +77,17 @@ def split_log_line(line):
if result[0] != '=':
raise Ignored('Malformed input')
result = result[1:]
if ' ' in func:
tid, func = func.split(' ', 1)
else:
tid = pid
return pid, tid, func, args, result
- except:
+ except Exception:
raise Ignored('Malformed input')
NUM_ARGUMENTS = {
'jemalloc_stats': 0,
'free': 1,
'malloc': 1,
'posix_memalign': 2,