44 lines
1014 B
Python

import cProfile
import pstats
import time
from KSG_anomaly_detection import _prepare_env, delegator
from KSG_anomaly_detection.monitor import monitor_folder_simple
profiler = cProfile.Profile()
PROFILE = True
USE_NEW_IMPL = False
USE_MP = False
ONLY_PREPARE = False
def main() -> None:
_prepare_env.main()
if ONLY_PREPARE:
return
mp_pool = delegator.MPPool()
try:
t1 = time.perf_counter()
if PROFILE:
profiler.enable()
monitor_folder_simple(mp_pool=mp_pool, use_new=USE_NEW_IMPL, use_mp=USE_MP)
profiler.disable()
stats = pstats.Stats(profiler).sort_stats("cumtime")
ENTRIES_TO_SHOW = 40 if USE_MP else 20
stats.print_stats(ENTRIES_TO_SHOW)
else:
monitor_folder_simple(mp_pool=mp_pool, use_new=USE_NEW_IMPL, use_mp=USE_MP)
t2 = time.perf_counter()
finally:
mp_pool.close()
print(f"Elapsed time: {t2 - t1} s")
if __name__ == "__main__":
main()