From 1d2c92bf6b3b4baf092e2454effc2483fb49b06c Mon Sep 17 00:00:00 2001 From: Pablo Goitia Date: Tue, 22 Aug 2023 11:49:03 +0200 Subject: [PATCH] Added some improvements and bug fixes --- autosubmit/autosubmit.py | 2 +- autosubmit/profiler/profiler.py | 6 ++++-- test/unit/test_profiler.py | 10 ++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/autosubmit/autosubmit.py b/autosubmit/autosubmit.py index 10f7a7be3..d1a7b00c9 100644 --- a/autosubmit/autosubmit.py +++ b/autosubmit/autosubmit.py @@ -2017,7 +2017,7 @@ class Autosubmit: :param start_time: the time at which the experiment should start :param start_after: the expid after which the experiment should start :param run_only_members: the members to run - :param profile: if True, the whole experiment will be profiled + :param profile: if True, the function will be profiled :return: None """ diff --git a/autosubmit/profiler/profiler.py b/autosubmit/profiler/profiler.py index 789402b4d..b73ccea09 100644 --- a/autosubmit/profiler/profiler.py +++ b/autosubmit/profiler/profiler.py @@ -46,24 +46,26 @@ class Profiler: # Error handling flags self._started = False + self._finished = False def start(self) -> None: """Function to start the profiling process.""" if self._started: raise AutosubmitCritical('The profiling process was already started.', 7074) + self._started = True self._profiler.enable() self._mem_init += _get_current_memory() - self._started = True def stop(self) -> None: """Function to finish the profiling process.""" - if not self._started: + if not self._started or self._finished: raise AutosubmitCritical('Cannot stop the profiler because was not running.', 7074) self._profiler.disable() self._mem_final += _get_current_memory() self._report() + self._finished = True def _report(self) -> None: """Function to print the final report into the stdout, log and filesystem.""" diff --git a/test/unit/test_profiler.py b/test/unit/test_profiler.py index 4d474d572..cf99067ea 100644 --- a/test/unit/test_profiler.py +++ b/test/unit/test_profiler.py @@ -1,7 +1,6 @@ from unittest import TestCase, mock from autosubmit.profiler.profiler import Profiler from log.log import AutosubmitCritical -from pathlib import Path class TestProfiler(TestCase): @@ -15,11 +14,6 @@ class TestProfiler(TestCase): # | # stop ----> report --->0 - # Status coverage - def test_status_machine(self): - self.profiler.start() - self.profiler.stop() - # Transition coverage def test_transitions(self): # __init__ -> start @@ -36,6 +30,10 @@ class TestProfiler(TestCase): self.profiler.start() self.assertRaises(AutosubmitCritical, self.profiler.start) + # stop -> stop + self.profiler.stop() + self.assertRaises(AutosubmitCritical, self.profiler.stop) + # White box tests @mock.patch("os.access") def test_writing_permission_check_fails(self, mock_response): -- GitLab