summaryrefslogtreecommitdiff
path: root/nemesis/nemesis.py
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-11-30 22:40:14 -0500
committerbd <bdunahu@operationnull.com>2025-11-30 22:40:14 -0500
commit444554a579fe57e3bd470821d77c3cf4af60c56f (patch)
tree0569e2b02143631dcb42ae7660f85ef93d029503 /nemesis/nemesis.py
parentd85ccbe6cf340f758a971af855c809457607cd7a (diff)
nemesis: update should_trace.
nemesis/nemesis.py: update should_trace This change allows the user to selectively choose directories to profile. I need this to allow selecting pip-installed libraries.
Diffstat (limited to 'nemesis/nemesis.py')
-rwxr-xr-xnemesis/nemesis.py46
1 files changed, 20 insertions, 26 deletions
diff --git a/nemesis/nemesis.py b/nemesis/nemesis.py
index c1a6fb2..9d4014c 100755
--- a/nemesis/nemesis.py
+++ b/nemesis/nemesis.py
@@ -86,20 +86,21 @@ class Nemesis(object):
prev_coro = defaultdict(lambda: None)
# Path of files to profile.
- path_include: list(Path)
+ path_include: list[Path]
# Path of files to exclude
- path_exclude: list(Path)
+ path_exclude: list[Path]
@staticmethod
def __init__(e_duration: int,
- path_include: None,
- path_exclude: None,
+ path_include: list[Path],
+ path_exclude: list[Path],
filename: str,
prog: str,
signal_interval: float=0.01) -> None:
Nemesis.signal_interval = signal_interval
Nemesis.e_duration = e_duration
Nemesis.path_include = path_include
+ Nemesis.path_exclude = path_exclude
Nemesis.filename = filename
Nemesis.prog = prog
@@ -272,26 +273,19 @@ class Nemesis(object):
return None
@staticmethod
- def _should_trace(filename: str) -> bool:
- '''Returns FALSE if filename is uninteresting to the user.
- Don't depend on this. It kind of sucks.'''
- if not filename:
+ def _should_trace(fname: str) -> bool:
+ '''Returns FALSE if filename is uninteresting to the user.'''
+ # never profile the profiler.
+ if 'nemesis' in fname:
return False
- if '/gnu/store' in filename:
- return False
- if '/usr/local/lib/python' in filename:
- return False
- if 'site-packages' in filename:
- return False
- if 'propcache' in filename:
- return False
- if '.pyx' in filename:
- return False
- if filename[0] == '<':
- return False
- if 'nemesis' in filename:
+
+ f = Path(fname).resolve()
+ i = any(f.is_relative_to(p) for p in Nemesis.path_include)
+ if not i:
return False
- return True
+
+ e = any(f.is_relative_to(p) for p in Nemesis.path_exclude)
+ return not e
def _select_speedup() -> float:
'''
@@ -376,7 +370,8 @@ if __name__ == "__main__":
help='Specify the path(s) containing files to exclude profile. Takes priority over --include-paths.',
nargs="*",
type=validate_dir,
- required=False)
+ required=False,
+ default=[])
parser.add_argument('prog',
type=str,
nargs='*',
@@ -388,9 +383,8 @@ if __name__ == "__main__":
with open(args.prog[0], 'r', encoding='utf-8') as fp:
code = compile(fp.read(), args.prog[0], "exec")
Nemesis(args.experiment_duration,
- # args.include_paths,
- # args.exclude_paths,
- None, None,
+ args.include_paths,
+ args.exclude_paths,
args.filename,
args.prog[0],
args.interval).start()