dash/contrib/auto_gdb/log_size.py
Wladimir J. van der Laan d1200755f1 Merge #13448: Add linter: Make sure we explicitly open all text files using UTF-8 encoding in Python
c8176b3cc7556d7bcec39a55ae4d6ba16453baaa Add linter: Make sure we explicitly open all text files using UTF-8 or ASCII encoding in Python (practicalswift)
634bd970013eca90f4b4c1f9044eec8c97ba62c2 Explicitly specify encoding when opening text files in Python code (practicalswift)

Pull request description:

  Add linter: Make sure we explicitly open all text files using UTF-8 encoding in Python.

  As requested by @laanwj in #13440.

Tree-SHA512: 1651c00fe220ceb273324abd6703aee504029b96c7ef0e3029145901762c733c9b9d24927da281394fd4681a5bff774336c04eed01fafea997bb32192c334c06
Signed-off-by: pasta <pasta@dashboost.org>

# Conflicts:
#	contrib/devtools/circular-dependencies.py
#	contrib/linearize/linearize-data.py
#	contrib/linearize/linearize-hashes.py
#	contrib/seeds/generate-seeds.py
#	contrib/verify-commits/verify-commits.py
#	test/functional/multiwallet.py
#	test/functional/notifications.py
#	test/functional/test_runner.py
#	test/util/rpcauth-test.py
2020-07-07 11:50:56 -05:00

35 lines
939 B
Python

#!/usr/bin/env python3
#
try:
import gdb
except ImportError as e:
raise ImportError("This script must be run in GDB: ", str(e))
import traceback
import datetime
import sys
import os
sys.path.append(os.getcwd())
import common_helpers
class LogSizeCommand (gdb.Command):
"""calc size of the memory used by the object and write it to file"""
def __init__ (self):
super (LogSizeCommand, self).__init__ ("logsize", gdb.COMMAND_USER)
def invoke(self, arg, from_tty):
try:
args = gdb.string_to_argv(arg)
obj = gdb.parse_and_eval(args[0])
logfile = open(args[1], 'a', encoding="utf8")
size = common_helpers.get_instance_size(obj)
logfile.write("%s %s: %d\n" % (str(datetime.datetime.now()), args[0], size))
logfile.close()
except Exception as e:
print(traceback.format_exc())
raise e
LogSizeCommand()