summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..e468379
--- /dev/null
+++ b/main.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python3
+'''
+ _/ _/ _/
+ _/_/ _/ _/_/ _/_/_/ _/_/ _/_/ _/_/_/ _/_/_/
+ _/ _/ _/ _/_/_/_/ _/ _/ _/ _/_/_/_/ _/_/ _/ _/_/
+ _/ _/_/ _/ _/ _/ _/ _/ _/_/ _/ _/_/
+ _/ _/ _/_/_/ _/ _/ _/ _/_/_/ _/_/_/ _/ _/_/_/
+
+Copyright:
+
+ Copyright © 2025 bdunahu <bdunahu@operationnull.com>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+Commentary:
+Code:
+'''
+import argparse
+import sys
+import traceback
+from nemesis.nemesis import Nemesis
+from nemesis.utils import validate_html, validate_dir
+
+def parse_args():
+ parser = argparse.ArgumentParser(
+ usage='%(prog)s [args] -- prog'
+ )
+
+ parser.add_argument('-i', '--interval',
+ help='The minimum amount of time inbetween \
+ samples in seconds.',
+ metavar='',
+ type=float,
+ default=0.01)
+ parser.add_argument('-e', '--experiment-duration',
+ help='The performance experiment duration. Defaults to 3 seconds.',
+ metavar='',
+ type=float,
+ default=3)
+ parser.add_argument('-f', '--filename',
+ help='The filename to write results to. Must name an HTML file.',
+ metavar='',
+ type=validate_html,
+ 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,
+ default=[])
+ parser.add_argument('prog',
+ type=str,
+ nargs='*',
+ help='Path to the python script and its arguments.')
+ return parser.parse_args()
+
+the_globals = {
+ '__name__': '__main__',
+ '__doc__': None,
+ '__package__': None,
+ '__loader__': globals()['__loader__'],
+ '__spec__': None,
+ '__annotations__': {},
+ '__builtins__': globals()['__builtins__'],
+ '__file__': None,
+ '__cached__': None,
+}
+
+if __name__ == "__main__":
+ args = parse_args()
+ sys.argv = args.prog
+ try:
+ 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,
+ args.filename,
+ args.prog[0],
+ args.interval).start()
+ exec(code, the_globals)
+ Nemesis.stop()
+ except Exception:
+ traceback.print_exc()