Commit cf24a7aa authored by Samuel Huang's avatar Samuel Huang Committed by Commit Bot

[SuperSize] Modernize syntax for int divisions and exception variable assignments.

To aid in porting SuperSize to Python 3, this CL does the following:
* Sort out int vs. float divisions.
  * Add "'from __future__ import division" to each python file
    (except mock files for testing).
  * For int division: Use "//" (was "/")
  * For float division: Ensure this can be inferred, by using
    float(), or float constants (e.g., 1024.0).
* Change "except" variable assignment style.
  * Use "except Exception as e" (was "except Exception, e").

Bug: 1054018
Change-Id: I25925196fe33fc7f4ca28f126f180eb4060fa2b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2094544
Commit-Queue: Samuel Huang <huangs@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748375}
parent 064eb2e8
......@@ -7,6 +7,8 @@
Assumes that apk_path.mapping and apk_path.jar.info is available.
"""
from __future__ import division
import logging
import os
import subprocess
......
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import division
import unittest
import apkanalyzer
......
......@@ -5,6 +5,7 @@
"""Logic for reading .a files."""
from __future__ import division
from __future__ import print_function
import argparse
......
......@@ -4,6 +4,8 @@
"""Main Python API for analyzing binary size."""
from __future__ import division
import argparse
import bisect
import calendar
......
......@@ -20,6 +20,7 @@ This file can also be run stand-alone in order to test out the logic on smaller
sample sizes.
"""
from __future__ import division
from __future__ import print_function
import argparse
......@@ -225,7 +226,8 @@ class _BcTypeInfo:
[size, item_type_id] = list(_ParseOpItems(line, attrib_pos)) # op0, op1.
bits = self.int_types.get(item_type_id)
if bits is not None: # |bits| can be None for non-int arrays.
self.int_array_types[self.cur_type_id] = _BcIntArrayType(size, bits / 8)
self.int_array_types[self.cur_type_id] = _BcIntArrayType(
size, bits // 8)
self.cur_type_id += 1
def GetArrayType(self, idx):
......
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import division
import ast
import os
import unittest
......@@ -31,7 +33,7 @@ def _MakeString(bits, toks):
the result of concatanating tokens.
"""
s = ''.join(tok if isinstance(tok, basestring) else chr(tok) for tok in toks)
padding = '\x00' * ((bits - 8) / 8)
padding = '\x00' * ((bits - 8) // 8)
return ''.join(ch + padding for ch in s)
......
......@@ -4,6 +4,8 @@
"""Contains a set of Chrome-specific size queries."""
from __future__ import division
import logging
import models
......
......@@ -4,6 +4,8 @@
"""Helpers related to multiprocessing."""
from __future__ import division
import __builtin__ # __builtins__ does not have exception types.
import atexit
import itertools
......@@ -68,7 +70,7 @@ class _FuncWrapper(object):
def __call__(self, index, _=None):
try:
return self._func(*_fork_params[index], **_fork_kwargs)
except Exception, e:
except Exception as e:
# Only keep the exception type for builtin exception types or else risk
# further marshalling exceptions.
exception_type = None
......
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import division
import os
import threading
import unittest
......
......@@ -4,6 +4,7 @@
"""An interactive console for looking analyzing .size files."""
from __future__ import division
from __future__ import print_function
import argparse
......
......@@ -4,6 +4,8 @@
"""Utilities for demangling C++ symbols."""
from __future__ import division
import collections
import itertools
import logging
......
......@@ -3,6 +3,8 @@
# found in the LICENSE file.
"""Methods for converting model objects to human-readable formats."""
from __future__ import division
import abc
import cStringIO
import collections
......@@ -109,7 +111,7 @@ class Histogram(object):
bucket_values = [str(self.data[k]) for k in keys]
num_items = len(keys)
num_cols = 6
num_rows = (num_items + num_cols - 1) / num_cols # Divide and round up.
num_rows = (num_items + num_cols - 1) // num_cols # Divide and round up.
# Needed for xrange to not throw due to step by 0.
if num_rows == 0:
return
......@@ -287,7 +289,7 @@ class DescriberText(Describer):
# * Accounts for < .5% of PSS
# * Symbols are smaller than 1.0 byte (by PSS)
# * Always show at least 50 symbols.
min_remaining_pss_to_show = max(1024, total / 1000 * 5)
min_remaining_pss_to_show = max(1024.0, total / 1000.0 * 5)
min_symbol_pss_to_show = 1.0
min_symbols_to_show = 50
......
......@@ -3,6 +3,8 @@
# found in the LICENSE file.
"""Logic for diffing two SizeInfo objects."""
from __future__ import division
import collections
import logging
import re
......
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import division
import unittest
import diff
......
......@@ -101,6 +101,8 @@ All remaining bytes are a valid gzipped sparse .size file containing the
"after" snapshot.
"""
from __future__ import division
import cStringIO
import contextlib
import gzip
......
......@@ -7,6 +7,8 @@
Much of this logic is duplicated at
tools/binary_size/libsupersize/caspian/function_signature.cc."""
from __future__ import division
def _FindParameterListParen(name):
"""Finds index of the "(" that denotes the start of a parameter list."""
......
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import division
import logging
import re
import unittest
......
......@@ -4,6 +4,7 @@
"""Creates an html report that allows you to view binary size by component."""
from __future__ import division
from __future__ import print_function
import codecs
......
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import division
import cStringIO
import contextlib
import copy
......
......@@ -18,6 +18,7 @@ The |linker_name| parameter in various functions must take one of the above
coded linker name values.
"""
from __future__ import division
from __future__ import print_function
import argparse
......
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import division
import glob
import os
import sys
......
......@@ -5,6 +5,8 @@
"""Collect, archive, and analyze Chrome's binary size."""
from __future__ import division
import argparse
import atexit
import collections
......@@ -26,7 +28,7 @@ import start_server
def _LogPeakRamUsage():
peak_ram_usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
peak_ram_usage += resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss
logging.info('Peak RAM usage was %d MB.', peak_ram_usage / 1024)
logging.info('Peak RAM usage was %d MB.', peak_ram_usage // 1024)
def _AddCommonArguments(parser):
......
......@@ -4,6 +4,8 @@
"""Regular expression helpers."""
from __future__ import division
import re
......
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import division
import re
import unittest
......
......@@ -28,6 +28,8 @@ Description of common properties:
Never None, but will be '' when no component exists.
"""
from __future__ import division
import collections
import logging
import os
......
......@@ -4,6 +4,7 @@
# found in the LICENSE file.
"""Extract source file information from .ninja files."""
from __future__ import division
from __future__ import print_function
import argparse
......
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import division
import unittest
import ninja_parser
......
......@@ -17,6 +17,8 @@ RunNmOnIntermediates():
offset information.
"""
from __future__ import division
import collections
import subprocess
......
......@@ -35,6 +35,7 @@ This file can also be run stand-alone in order to test out the logic on smaller
sample sizes.
"""
from __future__ import division
from __future__ import print_function
import argparse
......@@ -389,7 +390,7 @@ class _BulkObjectFileAnalyzerSlave(object):
self._HandleMessage(self._pipe.recv())
except EOFError:
pass
except EnvironmentError, e:
except EnvironmentError as e:
# Parent process exited so don't log.
if e.errno in (errno.EPIPE, errno.ECONNRESET):
sys.exit(1)
......
......@@ -4,6 +4,8 @@
"""Functions for dealing with determining --tool-prefix."""
from __future__ import division
import abc
import distutils.spawn
import logging
......
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import division
import logging
import os
import sys
......
......@@ -4,6 +4,8 @@
"""Runs a server to let the user interact with supersize using a web UI."""
from __future__ import division
import BaseHTTPServer
import logging
import os
......
......@@ -31,6 +31,8 @@ ResolveStringPieces():
- Returns [{path: [string_ranges]} for each string_section].
"""
from __future__ import division
import ast
import collections
import itertools
......
......@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import division
import difflib
import logging
......
......@@ -5,6 +5,8 @@
"""Update the Google Cloud Storage bucket hosting the Super Size UI."""
from __future__ import division
import argparse
import os
import subprocess
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment