-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added functions to print imported Python modules and/or loaded shared…
… C/C++ libraries
- Loading branch information
1 parent
1666eb1
commit 7ec7372
Showing
1 changed file
with
33 additions
and
0 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 |
---|---|---|
@@ -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("") |