forked from zeroonecoin/zeroonecoin
-
Notifications
You must be signed in to change notification settings - Fork 12
/
log_size.py
executable file
·34 lines (28 loc) · 917 Bytes
/
log_size.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
#
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')
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()