Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # contrib/README.md # contrib/devtools/check-doc.py # contrib/devtools/clang-format-diff.py # contrib/devtools/gen-manpages.sh # contrib/devtools/security-check.py # contrib/gitian-descriptors/gitian-linux.yml # contrib/macdeploy/background.png # contrib/macdeploy/background.psd # contrib/macdeploy/background.svg # contrib/macdeploy/background.tiff # contrib/macdeploy/background@2x.png # contrib/macdeploy/custom_dsstore.py # contrib/macdeploy/macdeployqtplus # contrib/seeds/generate-seeds.py # contrib/seeds/nodes_main.txt # contrib/seeds/nodes_test.txt # src/chainparams.cpp # src/chainparamsseeds.h # src/clientversion.cpp
- Loading branch information
Showing
212 changed files
with
8,419 additions
and
5,023 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
*.tar.gz | ||
*.psd | ||
|
||
*.exe | ||
src/fartcoin | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Contents | ||
This directory contains tools to automatically get data about the memory consumption by some objects in fartcoind process with the help of GDB debugger. | ||
|
||
## fartcoin_dbg.sh | ||
This shell script attaches GDB to the running fartcoind process (should be built with debug info), executes debug.gdb script and detaches. | ||
By default it uses testnet settings, see script comments to attach it to mainnet fartcoind. | ||
|
||
## debug.gdb | ||
Contains debugger instructions to execute during attach: loads python code and executes it for the objects we want to investigate. | ||
|
||
## log_size.py | ||
Contains definition of the gdb command log_size. After this script loads it can be called from gdb command line or other gdb scripts. | ||
Command params: | ||
`log_size arg0 arg1` | ||
`arg0` - name of object whose memory will be written in log file | ||
`arg1` - name of the log file | ||
Example: | ||
``` | ||
log_size mnodeman "memlog.txt" | ||
``` | ||
|
||
## used_size.py | ||
Contains definition of the gdb command used_size. After loading of this script it can be called from gdb command line or other gdb scripts. | ||
Command params: | ||
`used_size arg0 arg1` | ||
`arg0` - variable to store memory used by the object | ||
`arg1` - name of object whose memory will be calculated and stored in the first argument | ||
Example: | ||
``` | ||
>(gdb) set $size = 0 | ||
>(gdb) used_size $size mnodeman | ||
>(gdb) p $size | ||
``` | ||
|
||
## stl_containers.py | ||
Contains helper classes to calculate memory used by the STL containers (list, vector, map, set, pair). | ||
|
||
## simple_class_obj.py | ||
Contains a helper class to calculate the memory used by an object as a sum of the memory used by its fields. | ||
All processed objects of such type are listed in the this file, you can add new types you are interested in to this list. | ||
If a type is not listed here, its size is the return of sizeof (except STL containers which are processed in stl_containers.py). | ||
|
||
## common_helpers.py | ||
Several helper functions that are used in other python code. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/python | ||
# | ||
|
||
try: | ||
import gdb | ||
except ImportError as e: | ||
raise ImportError("This script must be run in GDB: ", str(e)) | ||
import sys | ||
import os | ||
sys.path.append(os.getcwd()) | ||
import stl_containers | ||
import simple_class_obj | ||
|
||
SIZE_OF_INT = 4 | ||
SIZE_OF_BOOL = 1 | ||
SIZE_OF_INT64 = 8 | ||
SIZE_OF_UINT256 = 32 | ||
|
||
|
||
def get_special_type_obj(gobj): | ||
obj_type = gobj.type.strip_typedefs() | ||
if stl_containers.VectorObj.is_this_type(obj_type): | ||
return stl_containers.VectorObj(gobj) | ||
if stl_containers.ListObj.is_this_type(obj_type): | ||
return stl_containers.ListObj(gobj) | ||
if stl_containers.PairObj.is_this_type(obj_type): | ||
return stl_containers.PairObj(gobj) | ||
if stl_containers.MapObj.is_this_type(obj_type): | ||
return stl_containers.MapObj(gobj) | ||
if stl_containers.SetObj.is_this_type(obj_type): | ||
return stl_containers.SetObj(gobj) | ||
if simple_class_obj.SimpleClassObj.is_this_type(obj_type): | ||
return simple_class_obj.SimpleClassObj(gobj) | ||
return False | ||
|
||
|
||
def is_special_type(obj_type): | ||
if stl_containers.VectorObj.is_this_type(obj_type): | ||
return True | ||
if stl_containers.ListObj.is_this_type(obj_type): | ||
return True | ||
if stl_containers.PairObj.is_this_type(obj_type): | ||
return True | ||
if stl_containers.MapObj.is_this_type(obj_type): | ||
return True | ||
if stl_containers.SetObj.is_this_type(obj_type): | ||
return True | ||
if simple_class_obj.SimpleClassObj.is_this_type(obj_type): | ||
return True | ||
return False | ||
|
||
|
||
def get_instance_size(gobj): | ||
obj = get_special_type_obj(gobj) | ||
if not obj: | ||
return gobj.type.sizeof | ||
return obj.get_used_size() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
set pagination off | ||
source used_size.py | ||
source log_size.py | ||
source test_used_size.gdb | ||
#logsize privateSendClient "memlog.txt" | ||
#logsize privateSendServer "memlog.txt" | ||
#logsize mnodeman "memlog.txt" | ||
logsize mnpayments "memlog.txt" | ||
#logsize instantsend "memlog.txt" | ||
#logsize sporkManager "memlog.txt" | ||
#logsize masternodeSync "memlog.txt" | ||
#logsize governance "memlog.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
# use testnet settings, if you need mainnet, use ~/.fartcoincore/fartcoind.pid file instead | ||
fartcoin_pid=$(<~/.fartcoincore/testnet3/fartcoind.pid) | ||
sudo gdb -batch -ex "source debug.gdb" fartcoind ${fartcoin_pid} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/python | ||
# | ||
|
||
try: | ||
import gdb | ||
except ImportError as e: | ||
raise ImportError("This script must be run in GDB: ", str(e)) | ||
import sys | ||
import os | ||
sys.path.append(os.getcwd()) | ||
import common_helpers | ||
|
||
|
||
simple_types = ["CMasternode", "CMasternodeVerification", | ||
"CMasternodeBroadcast", "CMasternodePing", | ||
"CMasternodeMan", "CDarksendQueue", "CDarkSendEntry", | ||
"CTransaction", "CMutableTransaction", "CPrivateSendBaseSession", | ||
"CPrivateSendBaseManager", "CPrivateSendClientSession", | ||
"CPrivateSendClientManager", "CPrivateSendServer", "CMasternodePayments", | ||
"CMasternodePaymentVote", "CMasternodeBlockPayees", | ||
"CMasternodePayee", "CInstantSend", "CTxLockRequest", | ||
"CTxLockVote", "CTxLockCandidate", "COutPoint", | ||
"COutPointLock", "CSporkManager", "CMasternodeSync", | ||
"CGovernanceManager", "CRateCheckBuffer", "CGovernanceObject", | ||
"CGovernanceVote", "CGovernanceObjectVoteFile"] | ||
|
||
simple_templates = ["CacheMultiMap", "CacheMap"] | ||
|
||
|
||
class SimpleClassObj: | ||
|
||
def __init__ (self, gobj): | ||
self.obj = gobj | ||
|
||
@classmethod | ||
def is_this_type(cls, obj_type): | ||
str_type = str(obj_type) | ||
if str_type in simple_types: | ||
return True | ||
for templ in simple_templates: | ||
if str_type.find(templ + "<") == 0: | ||
return True | ||
return False | ||
|
||
def get_used_size(self): | ||
size = 0 | ||
fields = self.obj.type.fields() | ||
for f in fields: | ||
# check if it is static field | ||
if not hasattr(f, "bitpos"): | ||
continue | ||
# process base class size | ||
if f.is_base_class: | ||
size += common_helpers.get_instance_size(self.obj.cast(f.type.strip_typedefs())) | ||
continue | ||
# process simple field | ||
size += common_helpers.get_instance_size(self.obj[f.name]) | ||
return size |
Oops, something went wrong.