diff --git a/batbot/spectrogram/__init__.py b/batbot/spectrogram/__init__.py index f1fa0f4..f7974b1 100644 --- a/batbot/spectrogram/__init__.py +++ b/batbot/spectrogram/__init__.py @@ -16,7 +16,6 @@ import pyastar2d import scipy.signal # Ensure this is at the top with other imports import tqdm -from line_profiler import LineProfiler from scipy import ndimage # from PIL import Image @@ -29,7 +28,12 @@ from batbot import log -lp = LineProfiler() +PROFILE = os.environ.get('BATBOT_PROFILE', '').lower() in ('1', 'true', 'yes') + +if PROFILE: + from line_profiler import LineProfiler + + lp = LineProfiler() FREQ_MIN = 5e3 @@ -38,7 +42,8 @@ def compute(*args, **kwargs): retval = compute_wrapper(*args, **kwargs) - lp.print_stats() + if PROFILE: + lp.print_stats() return retval @@ -1298,7 +1303,7 @@ def calculate_harmonic_and_echo_flags( return harmonic_flag, harmonic_peak, echo_flag, echo_peak -@lp +@lp if PROFILE else lambda f: f def compute_wrapper( wav_filepath, annotations=None, output_folder='.', bitdepth=16, debug=False, **kwargs ): diff --git a/requirements/optional.txt b/requirements/optional.txt index 8dcdc59..f66d4cd 100644 --- a/requirements/optional.txt +++ b/requirements/optional.txt @@ -5,6 +5,7 @@ flake8 # gradio ipython isort +line_profiler # onnx # onnxruntime pre-commit diff --git a/requirements/runtime.txt b/requirements/runtime.txt index 9f94278..237f13d 100644 --- a/requirements/runtime.txt +++ b/requirements/runtime.txt @@ -2,7 +2,6 @@ click cryptography cython librosa -line_profiler matplotlib numpy opencv-python-headless diff --git a/setup.cfg b/setup.cfg index d73eb80..b0e095d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,7 +22,6 @@ install_requires = cryptography cython librosa - line_profiler matplotlib numpy opencv-python-headless