*notes, referrers
This commit is contained in:
parent
99ddc843b7
commit
7f4322f4d7
69
srcxray.py
69
srcxray.py
|
@ -4,10 +4,10 @@
|
||||||
#
|
#
|
||||||
# Analyzes interconnections between functions and structures in source code.
|
# Analyzes interconnections between functions and structures in source code.
|
||||||
#
|
#
|
||||||
# Uses cscope and git grep --show-function to
|
# Uses doxygen, git grep --show-functionm and cscope to
|
||||||
# reveal references between identifiers.
|
# reveal references between identifiers.
|
||||||
#
|
#
|
||||||
# 2018 Constantine Shulyupin, const@MakeLinux.com
|
# Since 2018, Costa Shulyupin, costa@MakeLinux.net
|
||||||
#
|
#
|
||||||
|
|
||||||
from inspect import currentframe, getframeinfo, getouterframes, stack
|
from inspect import currentframe, getframeinfo, getouterframes, stack
|
||||||
|
@ -101,7 +101,7 @@ def popen(p):
|
||||||
return check_output(p, shell=True).decode('utf-8').splitlines()
|
return check_output(p, shell=True).decode('utf-8').splitlines()
|
||||||
|
|
||||||
|
|
||||||
def extract_referer(line):
|
def extract_referrer(line):
|
||||||
line = re.sub(r'__ro_after_init', '', line)
|
line = re.sub(r'__ro_after_init', '', line)
|
||||||
line = re.sub(r'FNAME\((\w+)\)', r'\1', line)
|
line = re.sub(r'FNAME\((\w+)\)', r'\1', line)
|
||||||
line = re.sub(r'.*TRACE_EVENT.*', '', line)
|
line = re.sub(r'.*TRACE_EVENT.*', '', line)
|
||||||
|
@ -116,7 +116,7 @@ def extract_referer(line):
|
||||||
return m.groups()
|
return m.groups()
|
||||||
|
|
||||||
|
|
||||||
def extract_referer_test():
|
def extract_referrer_test():
|
||||||
passed = 0
|
passed = 0
|
||||||
for a in {
|
for a in {
|
||||||
"f=1=good2()",
|
"f=1=good2()",
|
||||||
|
@ -130,7 +130,7 @@ def extract_referer_test():
|
||||||
"f:8: a=in bad()",
|
"f:8: a=in bad()",
|
||||||
"f=9=struct good",
|
"f=9=struct good",
|
||||||
}:
|
}:
|
||||||
r = extract_referer(a)
|
r = extract_referrer(a)
|
||||||
#print(a, '->', r)
|
#print(a, '->', r)
|
||||||
if 'bad' in a and r and 'bad' in r[2]:
|
if 'bad' in a and r and 'bad' in r[2]:
|
||||||
print("ERROR: ", a, '->', r)
|
print("ERROR: ", a, '->', r)
|
||||||
|
@ -141,7 +141,7 @@ def extract_referer_test():
|
||||||
log(passed)
|
log(passed)
|
||||||
|
|
||||||
|
|
||||||
def func_referers_git_grep(name):
|
def func_referrers_git_grep(name):
|
||||||
res = list()
|
res = list()
|
||||||
r = None
|
r = None
|
||||||
for line in popen(r'git grep --threads 1 --no-index --word-regexp '
|
for line in popen(r'git grep --threads 1 --no-index --word-regexp '
|
||||||
|
@ -163,7 +163,7 @@ def func_referers_git_grep(name):
|
||||||
if r and r[2] != name and r[2] not in black_list:
|
if r and r[2] != name and r[2] not in black_list:
|
||||||
res.append(r)
|
res.append(r)
|
||||||
r = None
|
r = None
|
||||||
r = extract_referer(line)
|
r = extract_referrer(line)
|
||||||
# r is list of file line func
|
# r is list of file line func
|
||||||
if verbose and r:
|
if verbose and r:
|
||||||
print("%-40s\t%s"%(("%s:%s"%(r[0],r[1])),r[2]))
|
print("%-40s\t%s"%(("%s:%s"%(r[0],r[1])),r[2]))
|
||||||
|
@ -173,7 +173,7 @@ def func_referers_git_grep(name):
|
||||||
cscope_warned = False
|
cscope_warned = False
|
||||||
|
|
||||||
|
|
||||||
def func_referers_cscope(name):
|
def func_referrers_cscope(name):
|
||||||
global cscope_warned
|
global cscope_warned
|
||||||
if not os.path.isfile('cscope.out'):
|
if not os.path.isfile('cscope.out'):
|
||||||
if not cscope_warned:
|
if not cscope_warned:
|
||||||
|
@ -190,25 +190,24 @@ def func_referers_cscope(name):
|
||||||
res.append([file, line_num, func])
|
res.append([file, line_num, func])
|
||||||
if not res and len(name) > 3:
|
if not res and len(name) > 3:
|
||||||
log(name)
|
log(name)
|
||||||
res = func_referers_git_grep(name)
|
res = func_referrers_git_grep(name)
|
||||||
log(res)
|
log(res)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def func_referers_all(name):
|
def func_referrers_all(name):
|
||||||
return list(dict.fromkeys(func_referers_git_grep(name) + func_referers_cscope(name)))
|
return list(dict.fromkeys(func_referrers_git_grep(name) + func_referrers_cscope(name)))
|
||||||
|
|
||||||
|
|
||||||
def referers_tree(name, referer=None, printed=None, level=0):
|
def referrers_tree(name, referrer=None, printed=None, level=0):
|
||||||
if not referer:
|
|
||||||
if os.path.isfile('cscope.out'):
|
if os.path.isfile('cscope.out'):
|
||||||
referer = func_referers_cscope
|
referrer = func_referrers_cscope
|
||||||
else:
|
else:
|
||||||
print("Using git grep only, recommended to run: cscope -Rcbk",
|
print("Using git grep only, recommended to run: cscope -Rcbk",
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
referer = func_referers_git_grep
|
referrer = func_referrers_git_grep
|
||||||
if isinstance(referer, str):
|
if isinstance(referrer, str):
|
||||||
referer = eval(referer)
|
referrer = eval(referrer)
|
||||||
if not printed:
|
if not printed:
|
||||||
printed = set()
|
printed = set()
|
||||||
# definition
|
# definition
|
||||||
|
@ -222,39 +221,39 @@ def referers_tree(name, referer=None, printed=None, level=0):
|
||||||
if level > level_limit - 2:
|
if level > level_limit - 2:
|
||||||
print_limited((level + 1)*'\t' + '...')
|
print_limited((level + 1)*'\t' + '...')
|
||||||
return ''
|
return ''
|
||||||
for a in referer(name):
|
for a in referrer(name):
|
||||||
name = a[2]
|
name = a[2]
|
||||||
referers_tree(name, referer, printed, level + 1)
|
referrers_tree(name, referrer, printed, level + 1)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def referers(name):
|
def referrers(name):
|
||||||
#for a in func_referers_git_grep(name):
|
#for a in func_referrers_git_grep(name):
|
||||||
# print("%s:%s: %s"%(a[0],a[1],a[2]))
|
# print("%s:%s: %s"%(a[0],a[1],a[2]))
|
||||||
print(' '.join([a[2] for a in func_referers_git_grep(name)]))
|
print(' '.join([a[2] for a in func_referrers_git_grep(name)]))
|
||||||
|
|
||||||
|
|
||||||
def referers_dep(name, referer=None, printed=None, level=0):
|
def referrers_dep(name, referrer=None, printed=None, level=0):
|
||||||
if not referer:
|
if not referrer:
|
||||||
if os.path.isfile('cscope.out'):
|
if os.path.isfile('cscope.out'):
|
||||||
referer = func_referers_cscope
|
referrer = func_referrers_cscope
|
||||||
else:
|
else:
|
||||||
print("Using git grep only, recommended to run: cscope -Rcbk",
|
print("Using git grep only, recommended to run: cscope -Rcbk",
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
referer = func_referers_git_grep
|
referrer = func_referrers_git_grep
|
||||||
if isinstance(referer, str):
|
if isinstance(referrer, str):
|
||||||
referer = eval(referer)
|
referrer = eval(referrer)
|
||||||
if not printed:
|
if not printed:
|
||||||
printed = set()
|
printed = set()
|
||||||
if name in printed:
|
if name in printed:
|
||||||
return
|
return
|
||||||
if level > level_limit - 2:
|
if level > level_limit - 2:
|
||||||
return ''
|
return ''
|
||||||
referers = referer(name)
|
referrers = referrer(name)
|
||||||
if referers:
|
if referrers:
|
||||||
printed.add(name)
|
printed.add(name)
|
||||||
print("%s:" % (name), ' '.join(referers))
|
print("%s:" % (name), ' '.join(referrers))
|
||||||
for a in referers:
|
for a in referrers:
|
||||||
referers_dep(a, referer, printed, level + 1)
|
referrers_dep(a, referrer, printed, level + 1)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
# TODO: print terminal
|
# TODO: print terminal
|
||||||
|
@ -1202,9 +1201,9 @@ class _unittest_autotest(unittest.TestCase):
|
||||||
self.assertTrue(os.path.isdir('include/linux/'))
|
self.assertTrue(os.path.isdir('include/linux/'))
|
||||||
os.chdir('init')
|
os.chdir('init')
|
||||||
self.assertEqual('\t\t\t\t\tprepare_namespace ^', popen(
|
self.assertEqual('\t\t\t\t\tprepare_namespace ^', popen(
|
||||||
'srcxray.py referers_tree nfs_root_data')[-1])
|
'srcxray.py referrers_tree nfs_root_data')[-1])
|
||||||
self.assertEqual('initrd_load: prepare_namespace', popen(
|
self.assertEqual('initrd_load: prepare_namespace', popen(
|
||||||
'srcxray.py referers_dep nfs_root_data')[-1])
|
'srcxray.py referrers_dep nfs_root_data')[-1])
|
||||||
self.assertEqual('calibrate_delay_converge: __delay',
|
self.assertEqual('calibrate_delay_converge: __delay',
|
||||||
popen('srcxray.py call_dep start_kernel')[-2])
|
popen('srcxray.py call_dep start_kernel')[-2])
|
||||||
self.assertEqual('\t\tcpu_startup_entry', popen(
|
self.assertEqual('\t\tcpu_startup_entry', popen(
|
||||||
|
|
Loading…
Reference in New Issue