From 3a35bcda91d43e1e93095a090180bb6893940825 Mon Sep 17 00:00:00 2001 From: evonneng Date: Thu, 5 May 2022 13:48:34 -0700 Subject: [PATCH] adding scripts for easy local run (#59) --- README.md | 18 ++++++++++++- scripts/debugging/profile.sh | 43 ++++++++++++++++++++++++++++++++ scripts/debugging/run_actions.py | 26 +++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100755 scripts/debugging/profile.sh create mode 100644 scripts/debugging/run_actions.py diff --git a/README.md b/README.md index 11eea60de..134911c4d 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ bash environments/run_jupyter.sh # Tooling -One can use [autoenv](https://github.com/hyperupcall/autoenv) to make setting up the environment and environment variables easier. This will run the `.envrc` file upon entering the `/path/to/mattport` folder. It will also remove the environment parameters upon leaving. +1. One can use [autoenv](https://github.com/hyperupcall/autoenv) to make setting up the environment and environment variables easier. This will run the `.envrc` file upon entering the `/path/to/mattport` folder. It will also remove the environment parameters upon leaving. ``` # Install direnv. @@ -79,4 +79,20 @@ eval "$(direnv hook bash)" # Populate your .envrc with commands you want to run. Then, run the following to allow updates. cd /path/to/mattport direnv allow . +``` + +2. To run local **github actions**, you can run: +``` +python scripts/debugging/run_actions.py +``` + +3. To run local **profiling** to get a flame graph, make sure [pyspy](https://github.com/benfred/py-spy) is installed and you can run: +``` +pip install py-spy + +## for flame graph +./scripts/debugging/profile.sh -t flame -o flame.svg -p scripts/run_train.py data/dataset=blender_lego + +## for live view of functions +./scripts/debugging/profile.sh -t top -p scripts/run_train.py data/dataset=blender_lego ``` \ No newline at end of file diff --git a/scripts/debugging/profile.sh b/scripts/debugging/profile.sh new file mode 100755 index 000000000..990b3b0b8 --- /dev/null +++ b/scripts/debugging/profile.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +helpFunction_flame() +{ + echo "Usage: $0 -o output_file -p program" + echo -e "\t-o output .svg filename, where to save flame graph" + echo -e "\t-p .py program we want to profile with associated arguments" + exit 1 # Exit program after printing help +} + +helpFunction_top() +{ + echo "Usage: $0 -p program" + echo -e "\t-p .py program we want to profile with associated arguments" + exit 1 # Exit program after printing help +} + + +while getopts "t:o:p:a:" opt; do + case "$opt" in + t ) type="$OPTARG" ;; + o ) output_file="$OPTARG" ;; + p ) program="$OPTARG" ;; + ? ) helpFunction ;; + esac + done + if [ -z "$type" ]; then + echo "Missing profiling type (flame / top)" + fi + # Print helpFunction in case parameters are empty + if [[ "$type" = "flame" ]]; then + if [ -z "$output_file" ] || [ -z "$program" ]; then + echo "Some or all of the parameters are empty"; + helpFunction_flame + fi + py-spy record -o "$output_file" python "$program" + elif [[ "$type" = "top" ]]; then + if [ -z "$program" ]; then + echo "Some or all of the parameters are empty"; + helpFunction_top + fi + py-spy top python "$program" + fi \ No newline at end of file diff --git a/scripts/debugging/run_actions.py b/scripts/debugging/run_actions.py new file mode 100644 index 000000000..d55506ca9 --- /dev/null +++ b/scripts/debugging/run_actions.py @@ -0,0 +1,26 @@ +"""Simple yaml debugger""" +import subprocess + +import yaml + +LOCAL_TESTS = ["Run Black", "Python Pylint", "Test with pytest"] + +if __name__ == "__main__": + with open(".github/workflows/code_checks.yml", "rb") as f: + my_dict = yaml.safe_load(f) + steps = my_dict["jobs"]["build"]["steps"] + + for step in steps: + if "name" in step and step["name"] in LOCAL_TESTS: + if step["name"] == "Run Black": + curr_command = f"black mattport/ {step['with']['options']};" + else: + compressed = step["run"].replace("\n", "").replace("\\", "") + curr_command = f"{compressed};" + + print("*" * 100) + print(f"Running {curr_command}") + subprocess.call(curr_command, shell=True) + else: + print("*" * 100) + print(f"Skipping {step}")