Skip to content

Commit

Permalink
Added functions to print imported Python modules and/or loaded shared…
Browse files Browse the repository at this point in the history
… C/C++ libraries
  • Loading branch information
dsuponitskiy-duality committed Jul 10, 2024
1 parent 1666eb1 commit 7ec7372
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions utils/print-used-modules-and-libraries-linux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys

def print_python_imported_modules():
# print imported Python modules with their paths
print(" ===== imported Python modules =====")
for module_name, module in sorted(sys.modules.items()):
try:
module_file = module.__file__
if module_file:
print(f"{module_name}: {module_file}")
except AttributeError:
pass

def print_loaded_shared_libraries():
# print loaded shared libraries from /proc/self/maps
print(" ===== loaded shared C/C++ libraries =====")
with open("/proc/self/maps", "r") as maps_file:
lines = maps_file.readlines()
for line in lines:
if ".so" in line:
parts = line.split()
if len(parts) > 5:
print(parts[5])

if __name__ == "__main__":
# import numpy
# import pandas

print("")
print_python_imported_modules()
print("")
print_loaded_shared_libraries()
print("")

0 comments on commit 7ec7372

Please sign in to comment.