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 35 36 37
|
#
# report-libcall.py
#
# uftrace-option: --nest-libcall -F .*@plt
#
import os
libcall_map = {}
def uftrace_begin(ctx):
pass
def uftrace_entry(ctx):
_name = ctx["name"]
if _name in libcall_map:
libcall_map[_name] += 1
else:
libcall_map[_name] = 1
def uftrace_exit(ctx):
pass
def uftrace_end():
global libcall_map
sorted_dict = sorted(libcall_map.items(), key=lambda k: k[1], reverse=True)
pid = os.getpid()
with open("/proc/%s/comm" % pid) as proc_comm:
comm = proc_comm.read()[:-1]
print(" # Library Function Call Report for '%s' (pid: %d)\n" % (comm, pid))
print(" %15s %-#50s" % ("Call Count", "Library Functions"))
print(" ================ ================================================")
for item in sorted_dict:
print(" %15d %-#50s" % (item[1], item[0]))
print("\n")
|