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
# Usage: | |
# LD_DEBUG=bindings <program> >bindings_dump 2>&1 | |
# python print_bindings.py bindings_dump | |
import sys | |
import os | |
from collections import defaultdict | |
class colors: | |
red = '\033[91m' | |
clear = '\033[0m' | |
# Detect PyTorch libs | |
torch_libs = set() | |
torch_libs_paths = set() | |
def register_lib(libpath): | |
if '/torch/' in libpath: | |
torch_libs.add(os.path.basename(libpath)) | |
torch_libs_paths.add(libpath) | |
def color_lib(libname): | |
color = colors.red if libname in torch_libs else '' | |
return color + libname + colors.clear | |
# Parse the file | |
with open(sys.argv[1], 'r') as f: | |
lines = f.read().split('\n') | |
lib_bindings = defaultdict(set) | |
for l in lines: | |
if 'binding file' not in l: continue | |
fields = l.split() | |
bound_lib_path = fields[3] | |
symbol_lib_path = fields[6] | |
symbol_name = fields[10] | |
register_lib(bound_lib_path) | |
register_lib(symbol_lib_path) | |
bound_lib = os.path.basename(bound_lib_path) | |
symbol_lib = os.path.basename(symbol_lib_path) | |
if bound_lib != symbol_lib: | |
lib_bindings[bound_lib].add(symbol_lib) | |
# Print lib imports | |
for lib, symbol_libs in lib_bindings.items(): | |
print('{} imported symbols from:'.format(color_lib(lib))) | |
for slib in symbol_libs: | |
print('\t' + color_lib(slib)) | |
# Warnings for PyTorch exports | |
for lib, symbol_libs in lib_bindings.items(): | |
if lib in torch_libs: continue | |
for slib in symbol_libs: | |
if slib in torch_libs: | |
print('WARNING: non-torch lib {} imported symbols from torch lib {}'.format(lib, slib)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment