From 9be8d4af1bcd7bc3a047ffd6505c9a0fe2e7107b Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Thu, 30 Apr 2020 16:28:46 +0300 Subject: [PATCH] Fixed log paths for profiling decorator --- monkey/monkey_island/cc/testing/profiler_decorator.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/testing/profiler_decorator.py b/monkey/monkey_island/cc/testing/profiler_decorator.py index 403548add..dd08eec2e 100644 --- a/monkey/monkey_island/cc/testing/profiler_decorator.py +++ b/monkey/monkey_island/cc/testing/profiler_decorator.py @@ -1,6 +1,9 @@ from cProfile import Profile +import os import pstats +PROFILER_LOG_DIR = "./profiler_logs/" + def profile(sort_args=['cumulative'], print_args=[100]): profiler = Profile() @@ -11,7 +14,11 @@ def profile(sort_args=['cumulative'], print_args=[100]): try: result = profiler.runcall(fn, *args, **kwargs) finally: - filename = _get_filename_for_function(fn) + try: + os.mkdir(PROFILER_LOG_DIR) + except os.error: + pass + filename = PROFILER_LOG_DIR + _get_filename_for_function(fn) with open(filename, 'w') as stream: stats = pstats.Stats(profiler, stream=stream) stats.strip_dirs().sort_stats(*sort_args).print_stats(*print_args)