From 9da43ca0e3c87ef2ef83d546722200a1df485627 Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 30 Nov 2025 21:53:37 -0500 Subject: Add path include/exclude args --- .gitignore | 1 + nemesis/nemesis.py | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c9d0a01..5f4a1c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__/ t/manual/ results.html +*.log diff --git a/nemesis/nemesis.py b/nemesis/nemesis.py index 03901e3..f4fa2d8 100755 --- a/nemesis/nemesis.py +++ b/nemesis/nemesis.py @@ -39,6 +39,7 @@ import threading import time import traceback import types +from pathlib import Path CO_COROUTINE = inspect.CO_COROUTINE @@ -84,10 +85,21 @@ class Nemesis(object): # A mapping of event loops to the previous running coroutine. prev_coro = defaultdict(lambda: None) + # Path of files to profile. + path_include : [] + # Path of files to exclude + path_exclude = [] + @staticmethod - def __init__(e_duration, filename, prog, signal_interval=0.01): + def __init__(e_duration, + path_include, + path_exclude, + filename, + prog, + signal_interval=0.01): Nemesis.signal_interval = signal_interval Nemesis.e_duration = e_duration + Nemesis.path_include = path_include Nemesis.filename = filename Nemesis.prog = prog @@ -320,6 +332,13 @@ the_globals = { '__cached__': None, } +def validate_dir(path_str: str) -> Path: + p = Path(path_str).expanduser().resolve() + if not p.exists(): + raise ValueError(f"Profile path does not exist: {p}") + if not p.is_dir(): + raise ValueError(f"Can't profile a non-dir: {p}") + return p if __name__ == "__main__": # parses CLI arguments and facilitates profiler runtime. @@ -343,6 +362,16 @@ if __name__ == "__main__": metavar='', type=str, default="results.html") + # parser.add_argument('--include-paths', + # help='Specify the path(s) containing files to profile. If a file is in this path, it is a candidate for optimization.', + # nargs="+", + # type=validate_dir, + # required=True) + # parser.add_argument('--exclude-paths', + # help='Specify the path(s) containing files to exclude profile. Takes priority over --include-paths.', + # nargs="*", + # type=validate_dir, + # required=False) parser.add_argument('prog', type=str, nargs='*', @@ -354,6 +383,9 @@ 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.filename, args.prog[0], args.interval).start() -- cgit v1.2.3